Skip to content

Commit 3585cfd

Browse files
committed
Merge tag 'iio-fixes-for-7.2a' 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 7.2 cycle Usual mixed bag of recently introduced issues and much older ones. core - Ensure kfifo is reset before fd is allocated avoiding concurrent use of fifo with reset. multiple drivers - Fix up missing Kconfig dependencies. hid-sensors - Add support for multibyte read as necessary precursor to... - Fix stale or zero output when reading raw values for quaternions. adi,adis - Add IRQF_NO_THREAD to ensure interrupt is not pushed to the software interrupt chip used for trigger demux in the IIO core from a thread. bosch,bmc150 - Hardening against device returning a reserved out of range value for how many entries are in the FIFO. bosch,bmi160 - Add IRQF_NO_THREAD to ensure interrupt is not pushed to the software interrupt chip used for trigger demux in the IIO core from a thread. dynaimage,al3010 - Fix wrong scale for highest gain_range due to too many digits in the micro part (val2). freescale,mpl3115 - Fix unbalanced runtime pm on error in read_raw(). invensens,icm42600 - Avoid wrong divisor for fifo timestamps when using the watermark interrupt. - Fix timestamp accuracy loss due to excessive divisor for calculations. kionix,kxsd9 - Fix unbalanced runtime pm on an error in write_raw(). microchip,mcp37feb02 - Fix an uninitialized reference voltage value for particular DT config. melix,mlx90635 - Build on basis of right Kconfig symbol. nxp,lpc32xx - Ensure completion initialized before requesting irq. Hardening against spurious IRQ. nxp,saradc - Fix a delay calculation. sharp,gp2ap0002 - Fix unbalanced runtime pm on error in read_raw(). st,lsm6dsx - Fix an issue seen in wild where an unplanned CPU reset can leave the device on the wrong register page, thus leaving the driver wedged. st,st_sensors library - Make sure to handle a device that provides data as big endian correctly. st,spear - Ensure completion initialized before requesting irq. Hardening against spurious IRQ. taos,tsl2591 - Don't eat return from devm_request_threaded_irq() as that breaks deferred probing. ti,ads1119 - Fix a pm reference count leak in an error path. ti,ads124s08 - Handle gpio look up errors correctly. * tag 'iio-fixes-for-7.2a' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/jic23/iio: (28 commits) iio: event: Fix event FIFO reset race iio: imu: inv_icm42600: fix timestamp clock period by using lower value iio: light: al3010: fix incorrect scale for the highest gain range iio: adc: nxp-sar-adc: Fix the delay calculation in nxp_sar_adc_wait_for() iio: light: tsl2591: return actual error from probe IRQ failure iio: imu: inv_icm42600: fix timestamping by limiting FIFO reading iio: imu: st_lsm6dsx: deselect shub page before reading whoami iio: adc: ad7779: add missing 'select IIO_TRIGGERED_BUFFER' to Kconfig iio: adc: ad4130: add missing `select IIO_TRIGGERED_BUFFER` to Kconfig iio: adc: ti-ads124s08: Return reset GPIO lookup errors iio: temperature: Build mlx90635 with CONFIG_MLX90635 iio: light: al3320a: add missing REGMAP_I2C to Kconfig iio: light: al3010: add missing REGMAP_I2C to Kconfig iio: light: al3000a: add missing REGMAP_I2C to Kconfig iio: common: st_sensors: honour channel endianness in read_axis_data iio: imu: bmi160: add IRQF_NO_THREAD to data-ready trigger IRQ iio: imu: adis: add IRQF_NO_THREAD to non-FIFO trigger IRQ iio: hid-sensor-rotation: Fix stale or zero output when reading raw values HID: sensor-hub: Add sensor_hub_input_attr_read_values() for multi-byte reads iio: adc: spear: Initialize completion before requesting IRQ ...
2 parents bc4a982 + af791d2 commit 3585cfd

27 files changed

Lines changed: 238 additions & 62 deletions

drivers/hid/hid-sensor-hub.c

Lines changed: 71 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,54 @@ int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
286286
}
287287
EXPORT_SYMBOL_GPL(sensor_hub_get_feature);
288288

289+
int sensor_hub_input_attr_read_values(struct hid_sensor_hub_device *hsdev,
290+
u32 usage_id, u32 attr_usage_id,
291+
u32 report_id,
292+
enum sensor_hub_read_flags flag,
293+
u32 buffer_size, u8 *buffer)
294+
{
295+
struct sensor_hub_data *data = hid_get_drvdata(hsdev->hdev);
296+
struct hid_report *report;
297+
unsigned long flags;
298+
long cycles;
299+
int ret;
300+
301+
report = sensor_hub_report(report_id, hsdev->hdev, HID_INPUT_REPORT);
302+
if (!report)
303+
return -EINVAL;
304+
305+
mutex_lock(hsdev->mutex_ptr);
306+
if (flag == SENSOR_HUB_SYNC) {
307+
memset(&hsdev->pending, 0, sizeof(hsdev->pending));
308+
init_completion(&hsdev->pending.ready);
309+
hsdev->pending.usage_id = usage_id;
310+
hsdev->pending.attr_usage_id = attr_usage_id;
311+
hsdev->pending.max_raw_size = buffer_size;
312+
hsdev->pending.raw_data = buffer;
313+
314+
spin_lock_irqsave(&data->lock, flags);
315+
hsdev->pending.status = true;
316+
spin_unlock_irqrestore(&data->lock, flags);
317+
}
318+
mutex_lock(&data->mutex);
319+
hid_hw_request(hsdev->hdev, report, HID_REQ_GET_REPORT);
320+
mutex_unlock(&data->mutex);
321+
ret = 0;
322+
if (flag == SENSOR_HUB_SYNC) {
323+
cycles = wait_for_completion_interruptible_timeout(&hsdev->pending.ready,
324+
HZ * 5);
325+
if (cycles == 0)
326+
ret = -ETIMEDOUT;
327+
else if (cycles < 0)
328+
ret = cycles;
329+
330+
hsdev->pending.status = false;
331+
}
332+
mutex_unlock(hsdev->mutex_ptr);
333+
334+
return ret;
335+
}
336+
EXPORT_SYMBOL_GPL(sensor_hub_input_attr_read_values);
289337

290338
int sensor_hub_input_attr_get_raw_value(struct hid_sensor_hub_device *hsdev,
291339
u32 usage_id,
@@ -478,6 +526,8 @@ static int sensor_hub_raw_event(struct hid_device *hdev,
478526
struct hid_collection *collection = NULL;
479527
void *priv = NULL;
480528
struct hid_sensor_hub_device *hsdev = NULL;
529+
u32 copy_size;
530+
u32 avail;
481531

482532
hid_dbg(hdev, "sensor_hub_raw_event report id:0x%x size:%d type:%d\n",
483533
report->id, size, report->type);
@@ -518,12 +568,27 @@ static int sensor_hub_raw_event(struct hid_device *hdev,
518568
hsdev->pending.attr_usage_id ==
519569
report->field[i]->logical)) {
520570
hid_dbg(hdev, "data was pending ...\n");
521-
hsdev->pending.raw_data = kmemdup(ptr, sz, GFP_ATOMIC);
522-
if (hsdev->pending.raw_data)
523-
hsdev->pending.raw_size = sz;
524-
else
525-
hsdev->pending.raw_size = 0;
526-
complete(&hsdev->pending.ready);
571+
if (hsdev->pending.max_raw_size) {
572+
if (hsdev->pending.index < hsdev->pending.max_raw_size) {
573+
avail = hsdev->pending.max_raw_size - hsdev->pending.index;
574+
copy_size = clamp(sz, 0U, avail);
575+
576+
memcpy(hsdev->pending.raw_data + hsdev->pending.index,
577+
ptr, copy_size);
578+
hsdev->pending.index += copy_size;
579+
if (hsdev->pending.index >= hsdev->pending.max_raw_size) {
580+
hsdev->pending.raw_size = hsdev->pending.index;
581+
complete(&hsdev->pending.ready);
582+
}
583+
}
584+
} else {
585+
hsdev->pending.raw_data = kmemdup(ptr, sz, GFP_ATOMIC);
586+
if (hsdev->pending.raw_data)
587+
hsdev->pending.raw_size = sz;
588+
else
589+
hsdev->pending.raw_size = 0;
590+
complete(&hsdev->pending.ready);
591+
}
527592
}
528593
if (callback->capture_sample) {
529594
if (report->field[i]->logical)

drivers/iio/accel/bmc150-accel-core.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,8 @@ static int __bmc150_accel_fifo_flush(struct iio_dev *indio_dev,
991991
if (samples && count > samples)
992992
count = samples;
993993

994+
count = min_t(u8, count, BMC150_ACCEL_FIFO_LENGTH);
995+
994996
ret = bmc150_accel_fifo_transfer(data, (u8 *)buffer, count);
995997
if (ret)
996998
return ret;

drivers/iio/accel/kxsd9.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,9 @@ static int kxsd9_write_raw(struct iio_dev *indio_dev,
147147
if (mask == IIO_CHAN_INFO_SCALE) {
148148
/* Check no integer component */
149149
if (val)
150-
return -EINVAL;
151-
ret = kxsd9_write_scale(indio_dev, val2);
150+
ret = -EINVAL;
151+
else
152+
ret = kxsd9_write_scale(indio_dev, val2);
152153
}
153154

154155
pm_runtime_put_autosuspend(st->dev);

drivers/iio/adc/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ config AD4130
108108
depends on SPI
109109
depends on GPIOLIB
110110
select IIO_BUFFER
111+
select IIO_TRIGGERED_BUFFER
111112
select IIO_KFIFO_BUF
112113
select REGMAP_SPI
113114
depends on COMMON_CLK
@@ -328,6 +329,7 @@ config AD7298
328329
config AD7380
329330
tristate "Analog Devices AD7380 ADC driver"
330331
depends on SPI_MASTER
332+
select REGMAP
331333
select SPI_OFFLOAD
332334
select IIO_BUFFER
333335
select IIO_BUFFER_DMAENGINE
@@ -452,6 +454,7 @@ config AD7779
452454
depends on SPI
453455
select CRC8
454456
select IIO_BUFFER
457+
select IIO_TRIGGERED_BUFFER
455458
select IIO_BACKEND
456459
help
457460
Say yes here to build support for Analog Devices AD777X family

drivers/iio/adc/lpc32xx_adc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ static int lpc32xx_adc_probe(struct platform_device *pdev)
179179
if (irq < 0)
180180
return irq;
181181

182+
init_completion(&st->completion);
183+
182184
retval = devm_request_irq(&pdev->dev, irq, lpc32xx_adc_isr, 0,
183185
LPC32XXAD_NAME, st);
184186
if (retval < 0) {
@@ -197,8 +199,6 @@ static int lpc32xx_adc_probe(struct platform_device *pdev)
197199

198200
platform_set_drvdata(pdev, iodev);
199201

200-
init_completion(&st->completion);
201-
202202
iodev->name = LPC32XXAD_NAME;
203203
iodev->info = &lpc32xx_adc_iio_info;
204204
iodev->modes = INDIO_DIRECT_MODE;

drivers/iio/adc/nxp-sar-adc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,13 @@ static void nxp_sar_adc_irq_cfg(struct nxp_sar_adc *info, bool enable)
198198
writel(0, NXP_SAR_ADC_IMR(info->regs));
199199
}
200200

201-
static void nxp_sar_adc_wait_for(struct nxp_sar_adc *info, unsigned int cycles)
201+
static void nxp_sar_adc_wait_for(struct nxp_sar_adc *info, u64 cycles)
202202
{
203203
u64 rate;
204204

205205
rate = clk_get_rate(info->clk);
206206
if (rate)
207-
ndelay(div64_u64(NSEC_PER_SEC, rate * cycles));
207+
ndelay(div64_u64(NSEC_PER_SEC * cycles, rate));
208208
}
209209

210210
static bool nxp_sar_adc_set_enabled(struct nxp_sar_adc *info, bool enable)

drivers/iio/adc/spear_adc.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ static int spear_adc_probe(struct platform_device *pdev)
283283
st = iio_priv(indio_dev);
284284
st->dev = dev;
285285

286+
init_completion(&st->completion);
286287
mutex_init(&st->lock);
287288

288289
/*
@@ -329,8 +330,6 @@ static int spear_adc_probe(struct platform_device *pdev)
329330

330331
spear_adc_configure(st);
331332

332-
init_completion(&st->completion);
333-
334333
indio_dev->name = SPEAR_ADC_MOD_NAME;
335334
indio_dev->info = &spear_adc_info;
336335
indio_dev->modes = INDIO_DIRECT_MODE;

drivers/iio/adc/ti-ads1119.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,11 @@ static int ads1119_triggered_buffer_preenable(struct iio_dev *indio_dev)
459459
if (ret)
460460
return ret;
461461

462-
return i2c_smbus_write_byte(st->client, ADS1119_CMD_START_SYNC);
462+
ret = i2c_smbus_write_byte(st->client, ADS1119_CMD_START_SYNC);
463+
if (ret)
464+
pm_runtime_put_autosuspend(dev);
465+
466+
return ret;
463467
}
464468

465469
static int ads1119_triggered_buffer_postdisable(struct iio_dev *indio_dev)

drivers/iio/adc/ti-ads124s08.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,8 @@ static int ads124s_probe(struct spi_device *spi)
321321
ads124s_priv->reset_gpio = devm_gpiod_get_optional(&spi->dev,
322322
"reset", GPIOD_OUT_LOW);
323323
if (IS_ERR(ads124s_priv->reset_gpio))
324-
dev_info(&spi->dev, "Reset GPIO not defined\n");
324+
return dev_err_probe(&spi->dev, PTR_ERR(ads124s_priv->reset_gpio),
325+
"Failed to get reset GPIO\n");
325326

326327
ads124s_priv->chip_info = &ads124s_chip_info_tbl[spi_id->driver_data];
327328

drivers/iio/common/st_sensors/st_sensors_core.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ static int st_sensors_read_axis_data(struct iio_dev *indio_dev,
498498
u8 *outdata;
499499
struct st_sensor_data *sdata = iio_priv(indio_dev);
500500
unsigned int byte_for_channel;
501+
u32 tmp;
501502

502503
byte_for_channel = DIV_ROUND_UP(ch->scan_type.realbits +
503504
ch->scan_type.shift, 8);
@@ -508,12 +509,22 @@ static int st_sensors_read_axis_data(struct iio_dev *indio_dev,
508509
if (err < 0)
509510
return err;
510511

511-
if (byte_for_channel == 1)
512-
*data = (s8)*outdata;
513-
else if (byte_for_channel == 2)
514-
*data = (s16)get_unaligned_le16(outdata);
515-
else if (byte_for_channel == 3)
516-
*data = (s32)sign_extend32(get_unaligned_le24(outdata), 23);
512+
if (byte_for_channel == 1) {
513+
tmp = *outdata;
514+
} else if (byte_for_channel == 2) {
515+
if (ch->scan_type.endianness == IIO_BE)
516+
tmp = get_unaligned_be16(outdata);
517+
else
518+
tmp = get_unaligned_le16(outdata);
519+
} else if (byte_for_channel == 3) {
520+
if (ch->scan_type.endianness == IIO_BE)
521+
tmp = get_unaligned_be24(outdata);
522+
else
523+
tmp = get_unaligned_le24(outdata);
524+
} else {
525+
return -EINVAL;
526+
}
527+
*data = sign_extend32(tmp, BYTES_TO_BITS(byte_for_channel) - 1);
517528

518529
return 0;
519530
}

0 commit comments

Comments
 (0)