Skip to content

Commit 6ffc565

Browse files
committed
Merge tag 'iio-fixes-for-6.13a' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/jic23/iio into char-misc-linus
Jonathan writes: IIO: 1st set of fixes for 6.13 cycle. The usual mixed back of fixes for ancient and recent bugs A number of these were from an audit by Javier Carrasco of places we may leak stack data via holes in structures passed to userspace that were not explicitly zeroed. Very helpful effort after we found a similar bug in review of new code. This affected: - dummy driver - kionix,kmx61 - murrata,zpa2326 - rockchip,saradc - rohm,bh1745 - veml,vcnl4035 - ti,ads1119 - ti,ads8688 - ti,tmp0006 Other fixes: core,inkern - Underflow fo reference count issue in error path of iio_channel_get_all() for devices we haven't yet gotten. tests - Kconfig typo fix so it's possible to tell what test is being enabled. - Check for allocation failures. adi,ad4695 - Ensure timing requirement wrt to final clock edge vs next conversion signal are met by adding an additional SPI transfer. adi,ad7124 - Ensure channels are disabled at probe to avoid wrong data if channel 0 is not the first one read. adi,ad7173 - Fix handing of multiple devices by not editing a single static structure and instead making a per instance copy. adi,ad9467 - Fix handing of multiple devices by not editing a single static structure and instead making a per instance copy. adi,ad9832 - Off by one error on input verification for phase control adi,ad9834 - Off by one error on input verification for phase control. atmel,at91 - In an error path don't use a variable that hasn't been initialized yet. invensense,icm42600 - SPI burst write does not work for some icm426000 chips, disable it. - Ensure correct handling of timestamps after resume. st,sensors - Add back accidentally dropped IIS2MDC compatible in binding doc. st,stm32-dfsdm: - label property was accidentally made a required property. Make it optional again to fix use of older DT. ti,ads1119 - Use a fixed size for the channel data rather than an integer, bringing the code inline with the advertised 16 bit channel size and avoiding userspace misinterpreting the data. ti,ads124s08 - Use _cansleep gpio calls as no reason to prevent sleeping and it was stopping a new board design working (trivial fix). ti,ads1298 - Add a check on failure of devm_kasprintf() * tag 'iio-fixes-for-6.13a' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/jic23/iio: (27 commits) iio: adc: ti-ads1119: fix sample size in scan struct for triggered buffer iio: temperature: tmp006: fix information leak in triggered buffer iio: inkern: call iio_device_put() only on mapped devices iio: adc: ad9467: Fix the "don't allow reading vref if not available" case iio: adc: at91: call input_free_device() on allocated iio_dev iio: adc: ad7173: fix using shared static info struct iio: adc: ti-ads124s08: Use gpiod_set_value_cansleep() iio: adc: ti-ads1119: fix information leak in triggered buffer iio: pressure: zpa2326: fix information leak in triggered buffer iio: adc: rockchip_saradc: fix information leak in triggered buffer iio: imu: kmx61: fix information leak in triggered buffer iio: light: vcnl4035: fix information leak in triggered buffer iio: light: bh1745: fix information leak in triggered buffer iio: adc: ti-ads8688: fix information leak in triggered buffer iio: dummy: iio_simply_dummy_buffer: fix information leak in triggered buffer iio: test: Fix GTS test config dt-bindings: iio: st-sensors: Re-add IIS2MDC magnetometer iio: adc: ti-ads1298: Add NULL check in ads1298_init iio: adc: stm32-dfsdm: handle label as an optional property iio: adc: ad4695: fix buffered read, single sample timings ...
2 parents 78d4f34 + 54d3949 commit 6ffc565

27 files changed

+159
-58
lines changed

Documentation/devicetree/bindings/iio/st,st-sensors.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ properties:
6565
- st,lsm9ds0-gyro
6666
- description: STMicroelectronics Magnetometers
6767
enum:
68+
- st,iis2mdc
6869
- st,lis2mdl
6970
- st,lis3mdl-magn
7071
- st,lsm303agr-magn

drivers/iio/adc/ad4695.c

Lines changed: 69 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
#define AD4695_T_WAKEUP_SW_MS 3
9292
#define AD4695_T_REFBUF_MS 100
9393
#define AD4695_T_REGCONFIG_NS 20
94+
#define AD4695_T_SCK_CNV_DELAY_NS 80
9495
#define AD4695_REG_ACCESS_SCLK_HZ (10 * MEGA)
9596

9697
/* Max number of voltage input channels. */
@@ -132,8 +133,13 @@ struct ad4695_state {
132133
unsigned int vref_mv;
133134
/* Common mode input pin voltage. */
134135
unsigned int com_mv;
135-
/* 1 per voltage and temperature chan plus 1 xfer to trigger 1st CNV */
136-
struct spi_transfer buf_read_xfer[AD4695_MAX_CHANNELS + 2];
136+
/*
137+
* 2 per voltage and temperature chan plus 1 xfer to trigger 1st
138+
* CNV. Excluding the trigger xfer, every 2nd xfer only serves
139+
* to control CS and add a delay between the last SCLK and next
140+
* CNV rising edges.
141+
*/
142+
struct spi_transfer buf_read_xfer[AD4695_MAX_CHANNELS * 2 + 3];
137143
struct spi_message buf_read_msg;
138144
/* Raw conversion data received. */
139145
u8 buf[ALIGN((AD4695_MAX_CHANNELS + 2) * AD4695_MAX_CHANNEL_SIZE,
@@ -423,7 +429,7 @@ static int ad4695_buffer_preenable(struct iio_dev *indio_dev)
423429
u8 temp_chan_bit = st->chip_info->num_voltage_inputs;
424430
u32 bit, num_xfer, num_slots;
425431
u32 temp_en = 0;
426-
int ret;
432+
int ret, rx_buf_offset = 0;
427433

428434
/*
429435
* We are using the advanced sequencer since it is the only way to read
@@ -449,11 +455,9 @@ static int ad4695_buffer_preenable(struct iio_dev *indio_dev)
449455
iio_for_each_active_channel(indio_dev, bit) {
450456
xfer = &st->buf_read_xfer[num_xfer];
451457
xfer->bits_per_word = 16;
452-
xfer->rx_buf = &st->buf[(num_xfer - 1) * 2];
458+
xfer->rx_buf = &st->buf[rx_buf_offset];
453459
xfer->len = 2;
454-
xfer->cs_change = 1;
455-
xfer->cs_change_delay.value = AD4695_T_CONVERT_NS;
456-
xfer->cs_change_delay.unit = SPI_DELAY_UNIT_NSECS;
460+
rx_buf_offset += xfer->len;
457461

458462
if (bit == temp_chan_bit) {
459463
temp_en = 1;
@@ -468,21 +472,44 @@ static int ad4695_buffer_preenable(struct iio_dev *indio_dev)
468472
}
469473

470474
num_xfer++;
475+
476+
/*
477+
* We need to add a blank xfer in data reads, to meet the timing
478+
* requirement of a minimum delay between the last SCLK rising
479+
* edge and the CS deassert.
480+
*/
481+
xfer = &st->buf_read_xfer[num_xfer];
482+
xfer->delay.value = AD4695_T_SCK_CNV_DELAY_NS;
483+
xfer->delay.unit = SPI_DELAY_UNIT_NSECS;
484+
xfer->cs_change = 1;
485+
xfer->cs_change_delay.value = AD4695_T_CONVERT_NS;
486+
xfer->cs_change_delay.unit = SPI_DELAY_UNIT_NSECS;
487+
488+
num_xfer++;
471489
}
472490

473491
/*
474492
* The advanced sequencer requires that at least 2 slots are enabled.
475493
* Since slot 0 is always used for other purposes, we need only 1
476-
* enabled voltage channel to meet this requirement. If the temperature
477-
* channel is the only enabled channel, we need to add one more slot
478-
* in the sequence but not read from it.
494+
* enabled voltage channel to meet this requirement. If the temperature
495+
* channel is the only enabled channel, we need to add one more slot in
496+
* the sequence but not read from it. This is because the temperature
497+
* sensor is sampled at the end of the channel sequence in advanced
498+
* sequencer mode (see datasheet page 38).
499+
*
500+
* From the iio_for_each_active_channel() block above, we now have an
501+
* xfer with data followed by a blank xfer to allow us to meet the
502+
* timing spec, so move both of those up before adding an extra to
503+
* handle the temperature-only case.
479504
*/
480505
if (num_slots < 2) {
481-
/* move last xfer so we can insert one more xfer before it */
482-
st->buf_read_xfer[num_xfer] = *xfer;
506+
/* Move last two xfers */
507+
st->buf_read_xfer[num_xfer] = st->buf_read_xfer[num_xfer - 1];
508+
st->buf_read_xfer[num_xfer - 1] = st->buf_read_xfer[num_xfer - 2];
483509
num_xfer++;
484510

485-
/* modify 2nd to last xfer for extra slot */
511+
/* Modify inserted xfer for extra slot. */
512+
xfer = &st->buf_read_xfer[num_xfer - 3];
486513
memset(xfer, 0, sizeof(*xfer));
487514
xfer->cs_change = 1;
488515
xfer->delay.value = st->chip_info->t_acq_ns;
@@ -499,6 +526,12 @@ static int ad4695_buffer_preenable(struct iio_dev *indio_dev)
499526
return ret;
500527

501528
num_slots++;
529+
530+
/*
531+
* We still want to point at the last xfer when finished, so
532+
* update the pointer.
533+
*/
534+
xfer = &st->buf_read_xfer[num_xfer - 1];
502535
}
503536

504537
/*
@@ -583,38 +616,43 @@ static irqreturn_t ad4695_trigger_handler(int irq, void *p)
583616
*/
584617
static int ad4695_read_one_sample(struct ad4695_state *st, unsigned int address)
585618
{
586-
struct spi_transfer xfer[2] = { };
587-
int ret, i = 0;
619+
struct spi_transfer xfers[2] = {
620+
{
621+
.speed_hz = AD4695_REG_ACCESS_SCLK_HZ,
622+
.bits_per_word = 16,
623+
.tx_buf = &st->cnv_cmd,
624+
.len = 2,
625+
},
626+
{
627+
/* Required delay between last SCLK and CNV/CS */
628+
.delay.value = AD4695_T_SCK_CNV_DELAY_NS,
629+
.delay.unit = SPI_DELAY_UNIT_NSECS,
630+
}
631+
};
632+
int ret;
588633

589634
ret = ad4695_set_single_cycle_mode(st, address);
590635
if (ret)
591636
return ret;
592637

593638
/*
594639
* Setting the first channel to the temperature channel isn't supported
595-
* in single-cycle mode, so we have to do an extra xfer to read the
596-
* temperature.
640+
* in single-cycle mode, so we have to do an extra conversion to read
641+
* the temperature.
597642
*/
598643
if (address == AD4695_CMD_TEMP_CHAN) {
599-
/* We aren't reading, so we can make this a short xfer. */
600-
st->cnv_cmd2 = AD4695_CMD_TEMP_CHAN << 3;
601-
xfer[0].tx_buf = &st->cnv_cmd2;
602-
xfer[0].len = 1;
603-
xfer[0].cs_change = 1;
604-
xfer[0].cs_change_delay.value = AD4695_T_CONVERT_NS;
605-
xfer[0].cs_change_delay.unit = SPI_DELAY_UNIT_NSECS;
606-
607-
i = 1;
644+
st->cnv_cmd = AD4695_CMD_TEMP_CHAN << 11;
645+
646+
ret = spi_sync_transfer(st->spi, xfers, ARRAY_SIZE(xfers));
647+
if (ret)
648+
return ret;
608649
}
609650

610651
/* Then read the result and exit conversion mode. */
611652
st->cnv_cmd = AD4695_CMD_EXIT_CNV_MODE << 11;
612-
xfer[i].bits_per_word = 16;
613-
xfer[i].tx_buf = &st->cnv_cmd;
614-
xfer[i].rx_buf = &st->raw_data;
615-
xfer[i].len = 2;
653+
xfers[0].rx_buf = &st->raw_data;
616654

617-
return spi_sync_transfer(st->spi, xfer, i + 1);
655+
return spi_sync_transfer(st->spi, xfers, ARRAY_SIZE(xfers));
618656
}
619657

620658
static int ad4695_read_raw(struct iio_dev *indio_dev,

drivers/iio/adc/ad7124.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,9 @@ static int ad7124_setup(struct ad7124_state *st)
917917
* set all channels to this default value.
918918
*/
919919
ad7124_set_channel_odr(st, i, 10);
920+
921+
/* Disable all channels to prevent unintended conversions. */
922+
ad_sd_write_reg(&st->sd, AD7124_CHANNEL(i), 2, 0);
920923
}
921924

922925
ret = ad_sd_write_reg(&st->sd, AD7124_ADC_CONTROL, 2, st->adc_control);

drivers/iio/adc/ad7173.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ struct ad7173_channel {
200200

201201
struct ad7173_state {
202202
struct ad_sigma_delta sd;
203+
struct ad_sigma_delta_info sigma_delta_info;
203204
const struct ad7173_device_info *info;
204205
struct ad7173_channel *channels;
205206
struct regulator_bulk_data regulators[3];
@@ -753,7 +754,7 @@ static int ad7173_disable_one(struct ad_sigma_delta *sd, unsigned int chan)
753754
return ad_sd_write_reg(sd, AD7173_REG_CH(chan), 2, 0);
754755
}
755756

756-
static struct ad_sigma_delta_info ad7173_sigma_delta_info = {
757+
static const struct ad_sigma_delta_info ad7173_sigma_delta_info = {
757758
.set_channel = ad7173_set_channel,
758759
.append_status = ad7173_append_status,
759760
.disable_all = ad7173_disable_all,
@@ -1403,7 +1404,7 @@ static int ad7173_fw_parse_device_config(struct iio_dev *indio_dev)
14031404
if (ret < 0)
14041405
return dev_err_probe(dev, ret, "Interrupt 'rdy' is required\n");
14051406

1406-
ad7173_sigma_delta_info.irq_line = ret;
1407+
st->sigma_delta_info.irq_line = ret;
14071408

14081409
return ad7173_fw_parse_channel_config(indio_dev);
14091410
}
@@ -1436,8 +1437,9 @@ static int ad7173_probe(struct spi_device *spi)
14361437
spi->mode = SPI_MODE_3;
14371438
spi_setup(spi);
14381439

1439-
ad7173_sigma_delta_info.num_slots = st->info->num_configs;
1440-
ret = ad_sd_init(&st->sd, indio_dev, spi, &ad7173_sigma_delta_info);
1440+
st->sigma_delta_info = ad7173_sigma_delta_info;
1441+
st->sigma_delta_info.num_slots = st->info->num_configs;
1442+
ret = ad_sd_init(&st->sd, indio_dev, spi, &st->sigma_delta_info);
14411443
if (ret)
14421444
return ret;
14431445

drivers/iio/adc/ad9467.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -895,14 +895,22 @@ static int ad9467_update_scan_mode(struct iio_dev *indio_dev,
895895
return 0;
896896
}
897897

898-
static struct iio_info ad9467_info = {
898+
static const struct iio_info ad9467_info = {
899899
.read_raw = ad9467_read_raw,
900900
.write_raw = ad9467_write_raw,
901901
.update_scan_mode = ad9467_update_scan_mode,
902902
.debugfs_reg_access = ad9467_reg_access,
903903
.read_avail = ad9467_read_avail,
904904
};
905905

906+
/* Same as above, but without .read_avail */
907+
static const struct iio_info ad9467_info_no_read_avail = {
908+
.read_raw = ad9467_read_raw,
909+
.write_raw = ad9467_write_raw,
910+
.update_scan_mode = ad9467_update_scan_mode,
911+
.debugfs_reg_access = ad9467_reg_access,
912+
};
913+
906914
static int ad9467_scale_fill(struct ad9467_state *st)
907915
{
908916
const struct ad9467_chip_info *info = st->info;
@@ -1214,11 +1222,12 @@ static int ad9467_probe(struct spi_device *spi)
12141222
}
12151223

12161224
if (st->info->num_scales > 1)
1217-
ad9467_info.read_avail = ad9467_read_avail;
1225+
indio_dev->info = &ad9467_info;
1226+
else
1227+
indio_dev->info = &ad9467_info_no_read_avail;
12181228
indio_dev->name = st->info->name;
12191229
indio_dev->channels = st->info->channels;
12201230
indio_dev->num_channels = st->info->num_channels;
1221-
indio_dev->info = &ad9467_info;
12221231

12231232
ret = ad9467_iio_backend_get(st);
12241233
if (ret)

drivers/iio/adc/at91_adc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ static int at91_ts_register(struct iio_dev *idev,
979979
return ret;
980980

981981
err:
982-
input_free_device(st->ts_input);
982+
input_free_device(input);
983983
return ret;
984984
}
985985

drivers/iio/adc/rockchip_saradc.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,8 @@ static irqreturn_t rockchip_saradc_trigger_handler(int irq, void *p)
368368
int ret;
369369
int i, j = 0;
370370

371+
memset(&data, 0, sizeof(data));
372+
371373
mutex_lock(&info->lock);
372374

373375
iio_for_each_active_channel(i_dev, i) {

drivers/iio/adc/stm32-dfsdm-adc.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -691,11 +691,14 @@ static int stm32_dfsdm_generic_channel_parse_of(struct stm32_dfsdm *dfsdm,
691691
return -EINVAL;
692692
}
693693

694-
ret = fwnode_property_read_string(node, "label", &ch->datasheet_name);
695-
if (ret < 0) {
696-
dev_err(&indio_dev->dev,
697-
" Error parsing 'label' for idx %d\n", ch->channel);
698-
return ret;
694+
if (fwnode_property_present(node, "label")) {
695+
/* label is optional */
696+
ret = fwnode_property_read_string(node, "label", &ch->datasheet_name);
697+
if (ret < 0) {
698+
dev_err(&indio_dev->dev,
699+
" Error parsing 'label' for idx %d\n", ch->channel);
700+
return ret;
701+
}
699702
}
700703

701704
df_ch = &dfsdm->ch_list[ch->channel];

drivers/iio/adc/ti-ads1119.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,12 +500,14 @@ static irqreturn_t ads1119_trigger_handler(int irq, void *private)
500500
struct iio_dev *indio_dev = pf->indio_dev;
501501
struct ads1119_state *st = iio_priv(indio_dev);
502502
struct {
503-
unsigned int sample;
503+
s16 sample;
504504
s64 timestamp __aligned(8);
505505
} scan;
506506
unsigned int index;
507507
int ret;
508508

509+
memset(&scan, 0, sizeof(scan));
510+
509511
if (!iio_trigger_using_own(indio_dev)) {
510512
index = find_first_bit(indio_dev->active_scan_mask,
511513
iio_get_masklength(indio_dev));

drivers/iio/adc/ti-ads124s08.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,9 @@ static int ads124s_reset(struct iio_dev *indio_dev)
183183
struct ads124s_private *priv = iio_priv(indio_dev);
184184

185185
if (priv->reset_gpio) {
186-
gpiod_set_value(priv->reset_gpio, 0);
186+
gpiod_set_value_cansleep(priv->reset_gpio, 0);
187187
udelay(200);
188-
gpiod_set_value(priv->reset_gpio, 1);
188+
gpiod_set_value_cansleep(priv->reset_gpio, 1);
189189
} else {
190190
return ads124s_write_cmd(indio_dev, ADS124S08_CMD_RESET);
191191
}

0 commit comments

Comments
 (0)