diff options
author | Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> | 2017-03-29 19:23:35 -0400 |
---|---|---|
committer | Jonathan Cameron <jic23@kernel.org> | 2017-04-02 06:26:14 -0400 |
commit | 862d1d89ad9e5b117f1fb2a472cef6fc92c0007a (patch) | |
tree | 7bd3c10277ecd05b90b96cd6a237a4220c453e68 | |
parent | 7fd6592d1287046f61bfd3cda3c03cd35be490f7 (diff) |
iio: accel: hid-sensor-accel-3d: Fix duplicate scan index error
When both accel_3d and gravity sensor are present, iio_device_register()
fails with "Duplicate scan index" error.
The reason for this is setting of indio_dev->num_channels based on
accel_3d channel for both gravity and accel-3d sensor. But number of
channels are not same, so for gravity it is pointing to some invalid
memory and getting scan_index to compare which may match.
To fix this issue, set the indio_dev->num_channels correctly based on
the sensor type.
Fixes: 0e377f3b9ae9 ('iio: Add gravity sensor support')
Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
-rw-r--r-- | drivers/iio/accel/hid-sensor-accel-3d.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/drivers/iio/accel/hid-sensor-accel-3d.c b/drivers/iio/accel/hid-sensor-accel-3d.c index ca5759c0c318..43a6cb078193 100644 --- a/drivers/iio/accel/hid-sensor-accel-3d.c +++ b/drivers/iio/accel/hid-sensor-accel-3d.c | |||
@@ -370,10 +370,12 @@ static int hid_accel_3d_probe(struct platform_device *pdev) | |||
370 | name = "accel_3d"; | 370 | name = "accel_3d"; |
371 | channel_spec = accel_3d_channels; | 371 | channel_spec = accel_3d_channels; |
372 | channel_size = sizeof(accel_3d_channels); | 372 | channel_size = sizeof(accel_3d_channels); |
373 | indio_dev->num_channels = ARRAY_SIZE(accel_3d_channels); | ||
373 | } else { | 374 | } else { |
374 | name = "gravity"; | 375 | name = "gravity"; |
375 | channel_spec = gravity_channels; | 376 | channel_spec = gravity_channels; |
376 | channel_size = sizeof(gravity_channels); | 377 | channel_size = sizeof(gravity_channels); |
378 | indio_dev->num_channels = ARRAY_SIZE(gravity_channels); | ||
377 | } | 379 | } |
378 | ret = hid_sensor_parse_common_attributes(hsdev, hsdev->usage, | 380 | ret = hid_sensor_parse_common_attributes(hsdev, hsdev->usage, |
379 | &accel_state->common_attributes); | 381 | &accel_state->common_attributes); |
@@ -395,7 +397,6 @@ static int hid_accel_3d_probe(struct platform_device *pdev) | |||
395 | goto error_free_dev_mem; | 397 | goto error_free_dev_mem; |
396 | } | 398 | } |
397 | 399 | ||
398 | indio_dev->num_channels = ARRAY_SIZE(accel_3d_channels); | ||
399 | indio_dev->dev.parent = &pdev->dev; | 400 | indio_dev->dev.parent = &pdev->dev; |
400 | indio_dev->info = &accel_3d_info; | 401 | indio_dev->info = &accel_3d_info; |
401 | indio_dev->name = name; | 402 | indio_dev->name = name; |