Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'iio-fixes-for-6.15a' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/jic23/iio into char-misc-linus

Jonathan writes:

IIO: 1st set of fixes for the 6.15 cycle.

A mixed bunch of fixes for new and ancient issues found.

multiple driver sets:
- Stop leaking wakeup sources on device unbind.
- Various timestamp alignment fixes that came up as part of work to add
runtime checks on buffer sizing. Similarly a DMA buffer safety fix.
hid-sensor-prox
- Fix a bad merge conflict resolution that lost some variable assignments.
- Fix handling of scale when multiple channels present.
- Fix wrong application of exponent in offset calculation.
adi,ad7380
- Disable offload before using the SPI bus.
- Fix a wrong shift on the event threshold.
adi,ad7606
- Check there is a sw_mode_config callback before using it as not
all busses define one.
- Fix missing hold of chip select on in multi word accesses.
adi,ad7861
- Fix wrong logic on storing of mode.
adi,adis16201
- Wrong resolution for inclinometer channel.
adi,adxl367
- Use fresh ODR when setting activity time, not previous value.
bosch,bmi270
- Fix initial sampling frequency configuration which was using the
wrong register mask.
rockchip,saradc
- Fix clock initialization sequence to get frequency after get + enable,
not before.
st,lsm6dsx
- Avoid 2 potential infinite loops if we see empty FIFOs
ti,opt3001
- Fix a deadlock that can occur due to concurrent access to a flag.

* tag 'iio-fixes-for-6.15a' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/jic23/iio: (28 commits)
iio: adis16201: Correct inclinometer channel resolution
iio: adc: ad7606: fix serial register access
iio: pressure: mprls0025pa: use aligned_s64 for timestamp
iio: imu: adis16550: align buffers for timestamp
staging: iio: adc: ad7816: Correct conditional logic for store mode
iio: adc: ad7266: Fix potential timestamp alignment issue.
iio: adc: ad7768-1: Fix insufficient alignment of timestamp.
iio: adc: dln2: Use aligned_s64 for timestamp
iio: accel: adxl355: Make timestamp 64-bit aligned using aligned_s64
iio: temp: maxim-thermocouple: Fix potential lack of DMA safe buffer.
iio: chemical: pms7003: use aligned_s64 for timestamp
iio: chemical: sps30: use aligned_s64 for timestamp
iio: imu: inv_mpu6050: align buffer for timestamp
iio: imu: st_lsm6dsx: Fix wakeup source leaks on device unbind
iio: adc: qcom-spmi-iadc: Fix wakeup source leaks on device unbind
iio: accel: fxls8962af: Fix wakeup source leaks on device unbind
iio: adc: ad7380: fix event threshold shift
iio: hid-sensor-prox: Fix incorrect OFFSET calculation
iio: hid-sensor-prox: support multi-channel SCALE calculation
iio: hid-sensor-prox: Restore lost scale assignments
...

+104 -73
+2 -2
drivers/iio/accel/adis16201.c
··· 211 211 BIT(IIO_CHAN_INFO_CALIBBIAS), 0, 14), 212 212 ADIS_AUX_ADC_CHAN(ADIS16201_AUX_ADC_REG, ADIS16201_SCAN_AUX_ADC, 0, 12), 213 213 ADIS_INCLI_CHAN(X, ADIS16201_XINCL_OUT_REG, ADIS16201_SCAN_INCLI_X, 214 - BIT(IIO_CHAN_INFO_CALIBBIAS), 0, 14), 214 + BIT(IIO_CHAN_INFO_CALIBBIAS), 0, 12), 215 215 ADIS_INCLI_CHAN(Y, ADIS16201_YINCL_OUT_REG, ADIS16201_SCAN_INCLI_Y, 216 - BIT(IIO_CHAN_INFO_CALIBBIAS), 0, 14), 216 + BIT(IIO_CHAN_INFO_CALIBBIAS), 0, 12), 217 217 IIO_CHAN_SOFT_TIMESTAMP(7) 218 218 }; 219 219
+1 -1
drivers/iio/accel/adxl355_core.c
··· 231 231 u8 transf_buf[3]; 232 232 struct { 233 233 u8 buf[14]; 234 - s64 ts; 234 + aligned_s64 ts; 235 235 } buffer; 236 236 } __aligned(IIO_DMA_MINALIGN); 237 237 };
+3 -7
drivers/iio/accel/adxl367.c
··· 601 601 if (ret) 602 602 return ret; 603 603 604 + st->odr = odr; 605 + 604 606 /* Activity timers depend on ODR */ 605 607 ret = _adxl367_set_act_time_ms(st, st->act_time_ms); 606 608 if (ret) 607 609 return ret; 608 610 609 - ret = _adxl367_set_inact_time_ms(st, st->inact_time_ms); 610 - if (ret) 611 - return ret; 612 - 613 - st->odr = odr; 614 - 615 - return 0; 611 + return _adxl367_set_inact_time_ms(st, st->inact_time_ms); 616 612 } 617 613 618 614 static int adxl367_set_odr(struct iio_dev *indio_dev, enum adxl367_odr odr)
+5 -2
drivers/iio/accel/fxls8962af-core.c
··· 1226 1226 if (ret) 1227 1227 return ret; 1228 1228 1229 - if (device_property_read_bool(dev, "wakeup-source")) 1230 - device_init_wakeup(dev, true); 1229 + if (device_property_read_bool(dev, "wakeup-source")) { 1230 + ret = devm_device_init_wakeup(dev); 1231 + if (ret) 1232 + return dev_err_probe(dev, ret, "Failed to init wakeup\n"); 1233 + } 1231 1234 1232 1235 return devm_iio_device_register(dev, indio_dev); 1233 1236 }
+1 -1
drivers/iio/adc/ad7266.c
··· 45 45 */ 46 46 struct { 47 47 __be16 sample[2]; 48 - s64 timestamp; 48 + aligned_s64 timestamp; 49 49 } data __aligned(IIO_DMA_MINALIGN); 50 50 }; 51 51
+22 -10
drivers/iio/adc/ad7380.c
··· 1211 1211 struct ad7380_state *st = iio_priv(indio_dev); 1212 1212 int ret; 1213 1213 1214 + spi_offload_trigger_disable(st->offload, st->offload_trigger); 1215 + spi_unoptimize_message(&st->offload_msg); 1216 + 1214 1217 if (st->seq) { 1215 1218 ret = regmap_update_bits(st->regmap, 1216 1219 AD7380_REG_ADDR_CONFIG1, ··· 1224 1221 1225 1222 st->seq = false; 1226 1223 } 1227 - 1228 - spi_offload_trigger_disable(st->offload, st->offload_trigger); 1229 - 1230 - spi_unoptimize_message(&st->offload_msg); 1231 1224 1232 1225 return 0; 1233 1226 } ··· 1610 1611 return ret; 1611 1612 } 1612 1613 1613 - static int ad7380_get_alert_th(struct ad7380_state *st, 1614 + static int ad7380_get_alert_th(struct iio_dev *indio_dev, 1615 + const struct iio_chan_spec *chan, 1614 1616 enum iio_event_direction dir, 1615 1617 int *val) 1616 1618 { 1617 - int ret, tmp; 1619 + struct ad7380_state *st = iio_priv(indio_dev); 1620 + const struct iio_scan_type *scan_type; 1621 + int ret, tmp, shift; 1622 + 1623 + scan_type = iio_get_current_scan_type(indio_dev, chan); 1624 + if (IS_ERR(scan_type)) 1625 + return PTR_ERR(scan_type); 1626 + 1627 + /* 1628 + * The register value is 12-bits and is compared to the most significant 1629 + * bits of raw value, therefore a shift is required to convert this to 1630 + * the same scale as the raw value. 1631 + */ 1632 + shift = scan_type->realbits - 12; 1618 1633 1619 1634 switch (dir) { 1620 1635 case IIO_EV_DIR_RISING: ··· 1638 1625 if (ret) 1639 1626 return ret; 1640 1627 1641 - *val = FIELD_GET(AD7380_ALERT_HIGH_TH, tmp); 1628 + *val = FIELD_GET(AD7380_ALERT_HIGH_TH, tmp) << shift; 1642 1629 return IIO_VAL_INT; 1643 1630 case IIO_EV_DIR_FALLING: 1644 1631 ret = regmap_read(st->regmap, ··· 1647 1634 if (ret) 1648 1635 return ret; 1649 1636 1650 - *val = FIELD_GET(AD7380_ALERT_LOW_TH, tmp); 1637 + *val = FIELD_GET(AD7380_ALERT_LOW_TH, tmp) << shift; 1651 1638 return IIO_VAL_INT; 1652 1639 default: 1653 1640 return -EINVAL; ··· 1661 1648 enum iio_event_info info, 1662 1649 int *val, int *val2) 1663 1650 { 1664 - struct ad7380_state *st = iio_priv(indio_dev); 1665 1651 int ret; 1666 1652 1667 1653 switch (info) { ··· 1668 1656 if (!iio_device_claim_direct(indio_dev)) 1669 1657 return -EBUSY; 1670 1658 1671 - ret = ad7380_get_alert_th(st, dir, val); 1659 + ret = ad7380_get_alert_th(indio_dev, chan, dir, val); 1672 1660 1673 1661 iio_device_release_direct(indio_dev); 1674 1662 return ret;
+8 -3
drivers/iio/adc/ad7606.c
··· 1236 1236 st->write_scale = ad7616_write_scale_sw; 1237 1237 st->write_os = &ad7616_write_os_sw; 1238 1238 1239 - ret = st->bops->sw_mode_config(indio_dev); 1240 - if (ret) 1241 - return ret; 1239 + if (st->bops->sw_mode_config) { 1240 + ret = st->bops->sw_mode_config(indio_dev); 1241 + if (ret) 1242 + return ret; 1243 + } 1242 1244 1243 1245 /* Activate Burst mode and SEQEN MODE */ 1244 1246 return ad7606_write_mask(st, AD7616_CONFIGURATION_REGISTER, ··· 1269 1267 1270 1268 st->write_scale = ad7606_write_scale_sw; 1271 1269 st->write_os = &ad7606_write_os_sw; 1270 + 1271 + if (!st->bops->sw_mode_config) 1272 + return 0; 1272 1273 1273 1274 return st->bops->sw_mode_config(indio_dev); 1274 1275 }
+1 -1
drivers/iio/adc/ad7606_spi.c
··· 131 131 { 132 132 .tx_buf = &st->d16[0], 133 133 .len = 2, 134 - .cs_change = 0, 134 + .cs_change = 1, 135 135 }, { 136 136 .rx_buf = &st->d16[1], 137 137 .len = 2,
+1 -1
drivers/iio/adc/ad7768-1.c
··· 168 168 union { 169 169 struct { 170 170 __be32 chan; 171 - s64 timestamp; 171 + aligned_s64 timestamp; 172 172 } scan; 173 173 __be32 d32; 174 174 u8 d8[2];
+1 -1
drivers/iio/adc/dln2-adc.c
··· 466 466 struct iio_dev *indio_dev = pf->indio_dev; 467 467 struct { 468 468 __le16 values[DLN2_ADC_MAX_CHANNELS]; 469 - int64_t timestamp_space; 469 + aligned_s64 timestamp_space; 470 470 } data; 471 471 struct dln2_adc_get_all_vals dev_data; 472 472 struct dln2_adc *dln2 = iio_priv(indio_dev);
+3 -1
drivers/iio/adc/qcom-spmi-iadc.c
··· 543 543 else 544 544 return ret; 545 545 } else { 546 - device_init_wakeup(iadc->dev, 1); 546 + ret = devm_device_init_wakeup(iadc->dev); 547 + if (ret) 548 + return dev_err_probe(iadc->dev, ret, "Failed to init wakeup\n"); 547 549 } 548 550 549 551 ret = iadc_update_offset(iadc);
+8 -9
drivers/iio/adc/rockchip_saradc.c
··· 520 520 if (info->reset) 521 521 rockchip_saradc_reset_controller(info->reset); 522 522 523 - /* 524 - * Use a default value for the converter clock. 525 - * This may become user-configurable in the future. 526 - */ 527 - ret = clk_set_rate(info->clk, info->data->clk_rate); 528 - if (ret < 0) 529 - return dev_err_probe(&pdev->dev, ret, 530 - "failed to set adc clk rate\n"); 531 - 532 523 ret = regulator_enable(info->vref); 533 524 if (ret < 0) 534 525 return dev_err_probe(&pdev->dev, ret, ··· 546 555 if (IS_ERR(info->clk)) 547 556 return dev_err_probe(&pdev->dev, PTR_ERR(info->clk), 548 557 "failed to get adc clock\n"); 558 + /* 559 + * Use a default value for the converter clock. 560 + * This may become user-configurable in the future. 561 + */ 562 + ret = clk_set_rate(info->clk, info->data->clk_rate); 563 + if (ret < 0) 564 + return dev_err_probe(&pdev->dev, ret, 565 + "failed to set adc clk rate\n"); 549 566 550 567 platform_set_drvdata(pdev, indio_dev); 551 568
+3 -2
drivers/iio/chemical/pms7003.c
··· 5 5 * Copyright (c) Tomasz Duszynski <tduszyns@gmail.com> 6 6 */ 7 7 8 - #include <linux/unaligned.h> 9 8 #include <linux/completion.h> 10 9 #include <linux/device.h> 11 10 #include <linux/errno.h> ··· 18 19 #include <linux/module.h> 19 20 #include <linux/mutex.h> 20 21 #include <linux/serdev.h> 22 + #include <linux/types.h> 23 + #include <linux/unaligned.h> 21 24 22 25 #define PMS7003_DRIVER_NAME "pms7003" 23 26 ··· 77 76 /* Used to construct scan to push to the IIO buffer */ 78 77 struct { 79 78 u16 data[3]; /* PM1, PM2P5, PM10 */ 80 - s64 ts; 79 + aligned_s64 ts; 81 80 } scan; 82 81 }; 83 82
+1 -1
drivers/iio/chemical/sps30.c
··· 108 108 int ret; 109 109 struct { 110 110 s32 data[4]; /* PM1, PM2P5, PM4, PM10 */ 111 - s64 ts; 111 + aligned_s64 ts; 112 112 } scan; 113 113 114 114 mutex_lock(&state->lock);
+4
drivers/iio/common/hid-sensors/hid-sensor-attributes.c
··· 66 66 {HID_USAGE_SENSOR_HUMIDITY, 0, 1000, 0}, 67 67 {HID_USAGE_SENSOR_HINGE, 0, 0, 17453293}, 68 68 {HID_USAGE_SENSOR_HINGE, HID_USAGE_SENSOR_UNITS_DEGREES, 0, 17453293}, 69 + 70 + {HID_USAGE_SENSOR_HUMAN_PRESENCE, 0, 1, 0}, 71 + {HID_USAGE_SENSOR_HUMAN_PROXIMITY, 0, 1, 0}, 72 + {HID_USAGE_SENSOR_HUMAN_ATTENTION, 0, 1, 0}, 69 73 }; 70 74 71 75 static void simple_div(int dividend, int divisor, int *whole,
+1 -1
drivers/iio/imu/adis16550.c
··· 836 836 u16 dummy; 837 837 bool valid; 838 838 struct iio_poll_func *pf = p; 839 - __be32 data[ADIS16550_MAX_SCAN_DATA]; 839 + __be32 data[ADIS16550_MAX_SCAN_DATA] __aligned(8); 840 840 struct iio_dev *indio_dev = pf->indio_dev; 841 841 struct adis16550 *st = iio_priv(indio_dev); 842 842 struct adis *adis = iio_device_get_drvdata(indio_dev);
+2 -4
drivers/iio/imu/bmi270/bmi270_core.c
··· 918 918 FIELD_PREP(BMI270_ACC_CONF_ODR_MSK, 919 919 BMI270_ACC_CONF_ODR_100HZ) | 920 920 FIELD_PREP(BMI270_ACC_CONF_BWP_MSK, 921 - BMI270_ACC_CONF_BWP_NORMAL_MODE) | 922 - BMI270_PWR_CONF_ADV_PWR_SAVE_MSK); 921 + BMI270_ACC_CONF_BWP_NORMAL_MODE)); 923 922 if (ret) 924 923 return dev_err_probe(dev, ret, "Failed to configure accelerometer"); 925 924 ··· 926 927 FIELD_PREP(BMI270_GYR_CONF_ODR_MSK, 927 928 BMI270_GYR_CONF_ODR_200HZ) | 928 929 FIELD_PREP(BMI270_GYR_CONF_BWP_MSK, 929 - BMI270_GYR_CONF_BWP_NORMAL_MODE) | 930 - BMI270_PWR_CONF_ADV_PWR_SAVE_MSK); 930 + BMI270_GYR_CONF_BWP_NORMAL_MODE)); 931 931 if (ret) 932 932 return dev_err_probe(dev, ret, "Failed to configure gyroscope"); 933 933
+1 -1
drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c
··· 50 50 u16 fifo_count; 51 51 u32 fifo_period; 52 52 s64 timestamp; 53 - u8 data[INV_MPU6050_OUTPUT_DATA_SIZE]; 53 + u8 data[INV_MPU6050_OUTPUT_DATA_SIZE] __aligned(8); 54 54 size_t i, nb; 55 55 56 56 mutex_lock(&st->lock);
+6
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
··· 392 392 if (fifo_status & cpu_to_le16(ST_LSM6DSX_FIFO_EMPTY_MASK)) 393 393 return 0; 394 394 395 + if (!pattern_len) 396 + pattern_len = ST_LSM6DSX_SAMPLE_SIZE; 397 + 395 398 fifo_len = (le16_to_cpu(fifo_status) & fifo_diff_mask) * 396 399 ST_LSM6DSX_CHAN_SIZE; 397 400 fifo_len = (fifo_len / pattern_len) * pattern_len; ··· 625 622 ST_LSM6DSX_TAGGED_SAMPLE_SIZE; 626 623 if (!fifo_len) 627 624 return 0; 625 + 626 + if (!pattern_len) 627 + pattern_len = ST_LSM6DSX_TAGGED_SAMPLE_SIZE; 628 628 629 629 for (read_len = 0; read_len < fifo_len; read_len += pattern_len) { 630 630 err = st_lsm6dsx_read_block(hw,
+5 -2
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
··· 2719 2719 } 2720 2720 2721 2721 if (device_property_read_bool(dev, "wakeup-source") || 2722 - (pdata && pdata->wakeup_source)) 2723 - device_init_wakeup(dev, true); 2722 + (pdata && pdata->wakeup_source)) { 2723 + err = devm_device_init_wakeup(dev); 2724 + if (err) 2725 + return dev_err_probe(dev, err, "Failed to init wakeup\n"); 2726 + } 2724 2727 2725 2728 return 0; 2726 2729 }
+14 -8
drivers/iio/light/hid-sensor-prox.c
··· 34 34 struct iio_chan_spec channels[MAX_CHANNELS]; 35 35 u32 channel2usage[MAX_CHANNELS]; 36 36 u32 human_presence[MAX_CHANNELS]; 37 - int scale_pre_decml; 38 - int scale_post_decml; 39 - int scale_precision; 37 + int scale_pre_decml[MAX_CHANNELS]; 38 + int scale_post_decml[MAX_CHANNELS]; 39 + int scale_precision[MAX_CHANNELS]; 40 40 unsigned long scan_mask[2]; /* One entry plus one terminator. */ 41 41 int num_channels; 42 42 }; ··· 116 116 ret_type = IIO_VAL_INT; 117 117 break; 118 118 case IIO_CHAN_INFO_SCALE: 119 - *val = prox_state->scale_pre_decml; 120 - *val2 = prox_state->scale_post_decml; 121 - ret_type = prox_state->scale_precision; 119 + if (chan->scan_index >= prox_state->num_channels) 120 + return -EINVAL; 121 + 122 + *val = prox_state->scale_pre_decml[chan->scan_index]; 123 + *val2 = prox_state->scale_post_decml[chan->scan_index]; 124 + ret_type = prox_state->scale_precision[chan->scan_index]; 122 125 break; 123 126 case IIO_CHAN_INFO_OFFSET: 124 - *val = hid_sensor_convert_exponent( 125 - prox_state->prox_attr[chan->scan_index].unit_expo); 127 + *val = 0; 126 128 ret_type = IIO_VAL_INT; 127 129 break; 128 130 case IIO_CHAN_INFO_SAMP_FREQ: ··· 251 249 st->prox_attr[index].size); 252 250 dev_dbg(&pdev->dev, "prox %x:%x\n", st->prox_attr[index].index, 253 251 st->prox_attr[index].report_id); 252 + st->scale_precision[index] = 253 + hid_sensor_format_scale(usage_id, &st->prox_attr[index], 254 + &st->scale_pre_decml[index], 255 + &st->scale_post_decml[index]); 254 256 index++; 255 257 } 256 258
+3 -2
drivers/iio/light/opt3001.c
··· 788 788 int ret; 789 789 bool wake_result_ready_queue = false; 790 790 enum iio_chan_type chan_type = opt->chip_info->chan_type; 791 + bool ok_to_ignore_lock = opt->ok_to_ignore_lock; 791 792 792 - if (!opt->ok_to_ignore_lock) 793 + if (!ok_to_ignore_lock) 793 794 mutex_lock(&opt->lock); 794 795 795 796 ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_CONFIGURATION); ··· 827 826 } 828 827 829 828 out: 830 - if (!opt->ok_to_ignore_lock) 829 + if (!ok_to_ignore_lock) 831 830 mutex_unlock(&opt->lock); 832 831 833 832 if (wake_result_ready_queue)
+6 -11
drivers/iio/pressure/mprls0025pa.h
··· 34 34 struct mpr_data; 35 35 struct mpr_ops; 36 36 37 - /** 38 - * struct mpr_chan 39 - * @pres: pressure value 40 - * @ts: timestamp 41 - */ 42 - struct mpr_chan { 43 - s32 pres; 44 - s64 ts; 45 - }; 46 - 47 37 enum mpr_func_id { 48 38 MPR_FUNCTION_A, 49 39 MPR_FUNCTION_B, ··· 59 69 * reading in a loop until data is ready 60 70 * @completion: handshake from irq to read 61 71 * @chan: channel values for buffered mode 72 + * @chan.pres: pressure value 73 + * @chan.ts: timestamp 62 74 * @buffer: raw conversion data 63 75 */ 64 76 struct mpr_data { ··· 79 87 struct gpio_desc *gpiod_reset; 80 88 int irq; 81 89 struct completion completion; 82 - struct mpr_chan chan; 90 + struct { 91 + s32 pres; 92 + aligned_s64 ts; 93 + } chan; 83 94 u8 buffer[MPR_MEASUREMENT_RD_SIZE] __aligned(IIO_DMA_MINALIGN); 84 95 }; 85 96
+1 -1
drivers/iio/temperature/maxim_thermocouple.c
··· 121 121 struct maxim_thermocouple_data { 122 122 struct spi_device *spi; 123 123 const struct maxim_thermocouple_chip *chip; 124 + char tc_type; 124 125 125 126 u8 buffer[16] __aligned(IIO_DMA_MINALIGN); 126 - char tc_type; 127 127 }; 128 128 129 129 static int maxim_thermocouple_read(struct maxim_thermocouple_data *data,
+1 -1
drivers/staging/iio/adc/ad7816.c
··· 136 136 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 137 137 struct ad7816_chip_info *chip = iio_priv(indio_dev); 138 138 139 - if (strcmp(buf, "full")) { 139 + if (strcmp(buf, "full") == 0) { 140 140 gpiod_set_value(chip->rdwr_pin, 1); 141 141 chip->mode = AD7816_FULL; 142 142 } else {