Commit 8210a200 authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

Merge tag 'iio-fixes-for-5.16a' of...

Merge tag 'iio-fixes-for-5.16a' of https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into char-misc-next

Jonathan writes:

First set of IIO fixes for the 5.16 cycle

As these are very late in the 5.15 cycle and non are particularly urgent,
they can wait for the merge window.

Key element in this set is Yang Yingliang has identified a number of
issues in error paths introduced recently when we added multiple
buffer support.

Other fixes:
* adi,ad5662
  - Fix handling of i2c_master_send() return value.
* adi,ad5766
  - Fix a wrong dt-property name that indicated wrong units and
    did not mach the bindings.
  - Associated 'fix' of the bindings example to have a possible scale.
* st,pressure-spi
  - Add some missing entries to the spi_device_id table to ensure
    auto-loading works.
* ti,tsc2046
  - Fix a backwards comparison leading to a false dev_warn

* tag 'iio-fixes-for-5.16a' of https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio:
  iio: buffer: Fix memory leak in iio_buffers_alloc_sysfs_and_mask()
  iio: adc: tsc2046: fix scan interval warning
  iio: core: fix double free in iio_device_unregister_sysfs()
  iio: core: check return value when calling dev_set_name()
  iio: buffer: Fix memory leak in iio_buffer_register_legacy_sysfs_groups()
  iio: buffer: Fix double-free in iio_buffers_alloc_sysfs_and_mask()
  iio: buffer: Fix memory leak in __iio_buffer_alloc_sysfs_and_mask()
  iio: buffer: check return value of kstrdup_const()
  iio: dac: ad5446: Fix ad5622_write() return value
  Documentation:devicetree:bindings:iio:dac: Fix val
  drivers: iio: dac: ad5766: Fix dt property name
  iio: st_pressure_spi: Add missing entries SPI to device ID table
parents 714f1af1 486a2508
...@@ -54,7 +54,7 @@ examples: ...@@ -54,7 +54,7 @@ examples:
ad5766@0 { ad5766@0 {
compatible = "adi,ad5766"; compatible = "adi,ad5766";
output-range-microvolts = <(-5000) 5000>; output-range-microvolts = <(-5000000) 5000000>;
reg = <0>; reg = <0>;
spi-cpol; spi-cpol;
spi-max-frequency = <1000000>; spi-max-frequency = <1000000>;
......
...@@ -398,7 +398,7 @@ static int tsc2046_adc_update_scan_mode(struct iio_dev *indio_dev, ...@@ -398,7 +398,7 @@ static int tsc2046_adc_update_scan_mode(struct iio_dev *indio_dev,
priv->xfer.len = size; priv->xfer.len = size;
priv->time_per_scan_us = size * 8 * priv->time_per_bit_ns / NSEC_PER_USEC; priv->time_per_scan_us = size * 8 * priv->time_per_bit_ns / NSEC_PER_USEC;
if (priv->scan_interval_us > priv->time_per_scan_us) if (priv->scan_interval_us < priv->time_per_scan_us)
dev_warn(&priv->spi->dev, "The scan interval (%d) is less then calculated scan time (%d)\n", dev_warn(&priv->spi->dev, "The scan interval (%d) is less then calculated scan time (%d)\n",
priv->scan_interval_us, priv->time_per_scan_us); priv->scan_interval_us, priv->time_per_scan_us);
......
...@@ -531,8 +531,15 @@ static int ad5622_write(struct ad5446_state *st, unsigned val) ...@@ -531,8 +531,15 @@ static int ad5622_write(struct ad5446_state *st, unsigned val)
{ {
struct i2c_client *client = to_i2c_client(st->dev); struct i2c_client *client = to_i2c_client(st->dev);
__be16 data = cpu_to_be16(val); __be16 data = cpu_to_be16(val);
int ret;
ret = i2c_master_send(client, (char *)&data, sizeof(data));
if (ret < 0)
return ret;
if (ret != sizeof(data))
return -EIO;
return i2c_master_send(client, (char *)&data, sizeof(data)); return 0;
} }
/* /*
......
...@@ -507,13 +507,13 @@ static int ad5766_get_output_range(struct ad5766_state *st) ...@@ -507,13 +507,13 @@ static int ad5766_get_output_range(struct ad5766_state *st)
int i, ret, min, max, tmp[2]; int i, ret, min, max, tmp[2];
ret = device_property_read_u32_array(&st->spi->dev, ret = device_property_read_u32_array(&st->spi->dev,
"output-range-voltage", "output-range-microvolts",
tmp, 2); tmp, 2);
if (ret) if (ret)
return ret; return ret;
min = tmp[0] / 1000; min = tmp[0] / 1000000;
max = tmp[1] / 1000; max = tmp[1] / 1000000;
for (i = 0; i < ARRAY_SIZE(ad5766_span_tbl); i++) { for (i = 0; i < ARRAY_SIZE(ad5766_span_tbl); i++) {
if (ad5766_span_tbl[i].min != min || if (ad5766_span_tbl[i].min != min ||
ad5766_span_tbl[i].max != max) ad5766_span_tbl[i].max != max)
......
...@@ -1434,6 +1434,11 @@ static struct attribute *iio_buffer_wrap_attr(struct iio_buffer *buffer, ...@@ -1434,6 +1434,11 @@ static struct attribute *iio_buffer_wrap_attr(struct iio_buffer *buffer,
iio_attr->buffer = buffer; iio_attr->buffer = buffer;
memcpy(&iio_attr->dev_attr, dattr, sizeof(iio_attr->dev_attr)); memcpy(&iio_attr->dev_attr, dattr, sizeof(iio_attr->dev_attr));
iio_attr->dev_attr.attr.name = kstrdup_const(attr->name, GFP_KERNEL); iio_attr->dev_attr.attr.name = kstrdup_const(attr->name, GFP_KERNEL);
if (!iio_attr->dev_attr.attr.name) {
kfree(iio_attr);
return NULL;
}
sysfs_attr_init(&iio_attr->dev_attr.attr); sysfs_attr_init(&iio_attr->dev_attr.attr);
list_add(&iio_attr->l, &buffer->buffer_attr_list); list_add(&iio_attr->l, &buffer->buffer_attr_list);
...@@ -1484,10 +1489,10 @@ static int iio_buffer_register_legacy_sysfs_groups(struct iio_dev *indio_dev, ...@@ -1484,10 +1489,10 @@ static int iio_buffer_register_legacy_sysfs_groups(struct iio_dev *indio_dev,
return 0; return 0;
error_free_buffer_attrs:
kfree(iio_dev_opaque->legacy_buffer_group.attrs);
error_free_scan_el_attrs: error_free_scan_el_attrs:
kfree(iio_dev_opaque->legacy_scan_el_group.attrs); kfree(iio_dev_opaque->legacy_scan_el_group.attrs);
error_free_buffer_attrs:
kfree(iio_dev_opaque->legacy_buffer_group.attrs);
return ret; return ret;
} }
...@@ -1654,6 +1659,7 @@ static int __iio_buffer_alloc_sysfs_and_mask(struct iio_buffer *buffer, ...@@ -1654,6 +1659,7 @@ static int __iio_buffer_alloc_sysfs_and_mask(struct iio_buffer *buffer,
sizeof(struct attribute *) * buffer_attrcount); sizeof(struct attribute *) * buffer_attrcount);
buffer_attrcount += ARRAY_SIZE(iio_buffer_attrs); buffer_attrcount += ARRAY_SIZE(iio_buffer_attrs);
buffer->buffer_group.attrs = attr;
for (i = 0; i < buffer_attrcount; i++) { for (i = 0; i < buffer_attrcount; i++) {
struct attribute *wrapped; struct attribute *wrapped;
...@@ -1661,7 +1667,7 @@ static int __iio_buffer_alloc_sysfs_and_mask(struct iio_buffer *buffer, ...@@ -1661,7 +1667,7 @@ static int __iio_buffer_alloc_sysfs_and_mask(struct iio_buffer *buffer,
wrapped = iio_buffer_wrap_attr(buffer, attr[i]); wrapped = iio_buffer_wrap_attr(buffer, attr[i]);
if (!wrapped) { if (!wrapped) {
ret = -ENOMEM; ret = -ENOMEM;
goto error_free_scan_mask; goto error_free_buffer_attrs;
} }
attr[i] = wrapped; attr[i] = wrapped;
} }
...@@ -1676,8 +1682,6 @@ static int __iio_buffer_alloc_sysfs_and_mask(struct iio_buffer *buffer, ...@@ -1676,8 +1682,6 @@ static int __iio_buffer_alloc_sysfs_and_mask(struct iio_buffer *buffer,
goto error_free_buffer_attrs; goto error_free_buffer_attrs;
} }
buffer->buffer_group.attrs = attr;
ret = iio_device_register_sysfs_group(indio_dev, &buffer->buffer_group); ret = iio_device_register_sysfs_group(indio_dev, &buffer->buffer_group);
if (ret) if (ret)
goto error_free_buffer_attr_group_name; goto error_free_buffer_attr_group_name;
...@@ -1706,8 +1710,12 @@ static int __iio_buffer_alloc_sysfs_and_mask(struct iio_buffer *buffer, ...@@ -1706,8 +1710,12 @@ static int __iio_buffer_alloc_sysfs_and_mask(struct iio_buffer *buffer,
return ret; return ret;
} }
static void __iio_buffer_free_sysfs_and_mask(struct iio_buffer *buffer) static void __iio_buffer_free_sysfs_and_mask(struct iio_buffer *buffer,
struct iio_dev *indio_dev,
int index)
{ {
if (index == 0)
iio_buffer_unregister_legacy_sysfs_groups(indio_dev);
bitmap_free(buffer->scan_mask); bitmap_free(buffer->scan_mask);
kfree(buffer->buffer_group.name); kfree(buffer->buffer_group.name);
kfree(buffer->buffer_group.attrs); kfree(buffer->buffer_group.attrs);
...@@ -1739,7 +1747,7 @@ int iio_buffers_alloc_sysfs_and_mask(struct iio_dev *indio_dev) ...@@ -1739,7 +1747,7 @@ int iio_buffers_alloc_sysfs_and_mask(struct iio_dev *indio_dev)
buffer = iio_dev_opaque->attached_buffers[i]; buffer = iio_dev_opaque->attached_buffers[i];
ret = __iio_buffer_alloc_sysfs_and_mask(buffer, indio_dev, i); ret = __iio_buffer_alloc_sysfs_and_mask(buffer, indio_dev, i);
if (ret) { if (ret) {
unwind_idx = i; unwind_idx = i - 1;
goto error_unwind_sysfs_and_mask; goto error_unwind_sysfs_and_mask;
} }
} }
...@@ -1761,7 +1769,7 @@ int iio_buffers_alloc_sysfs_and_mask(struct iio_dev *indio_dev) ...@@ -1761,7 +1769,7 @@ int iio_buffers_alloc_sysfs_and_mask(struct iio_dev *indio_dev)
error_unwind_sysfs_and_mask: error_unwind_sysfs_and_mask:
for (; unwind_idx >= 0; unwind_idx--) { for (; unwind_idx >= 0; unwind_idx--) {
buffer = iio_dev_opaque->attached_buffers[unwind_idx]; buffer = iio_dev_opaque->attached_buffers[unwind_idx];
__iio_buffer_free_sysfs_and_mask(buffer); __iio_buffer_free_sysfs_and_mask(buffer, indio_dev, unwind_idx);
} }
return ret; return ret;
} }
...@@ -1778,11 +1786,9 @@ void iio_buffers_free_sysfs_and_mask(struct iio_dev *indio_dev) ...@@ -1778,11 +1786,9 @@ void iio_buffers_free_sysfs_and_mask(struct iio_dev *indio_dev)
iio_device_ioctl_handler_unregister(iio_dev_opaque->buffer_ioctl_handler); iio_device_ioctl_handler_unregister(iio_dev_opaque->buffer_ioctl_handler);
kfree(iio_dev_opaque->buffer_ioctl_handler); kfree(iio_dev_opaque->buffer_ioctl_handler);
iio_buffer_unregister_legacy_sysfs_groups(indio_dev);
for (i = iio_dev_opaque->attached_buffers_cnt - 1; i >= 0; i--) { for (i = iio_dev_opaque->attached_buffers_cnt - 1; i >= 0; i--) {
buffer = iio_dev_opaque->attached_buffers[i]; buffer = iio_dev_opaque->attached_buffers[i];
__iio_buffer_free_sysfs_and_mask(buffer); __iio_buffer_free_sysfs_and_mask(buffer, indio_dev, i);
} }
} }
......
...@@ -1600,6 +1600,7 @@ static void iio_device_unregister_sysfs(struct iio_dev *indio_dev) ...@@ -1600,6 +1600,7 @@ static void iio_device_unregister_sysfs(struct iio_dev *indio_dev)
kfree(iio_dev_opaque->chan_attr_group.attrs); kfree(iio_dev_opaque->chan_attr_group.attrs);
iio_dev_opaque->chan_attr_group.attrs = NULL; iio_dev_opaque->chan_attr_group.attrs = NULL;
kfree(iio_dev_opaque->groups); kfree(iio_dev_opaque->groups);
iio_dev_opaque->groups = NULL;
} }
static void iio_dev_release(struct device *device) static void iio_dev_release(struct device *device)
...@@ -1664,7 +1665,13 @@ struct iio_dev *iio_device_alloc(struct device *parent, int sizeof_priv) ...@@ -1664,7 +1665,13 @@ struct iio_dev *iio_device_alloc(struct device *parent, int sizeof_priv)
kfree(iio_dev_opaque); kfree(iio_dev_opaque);
return NULL; return NULL;
} }
dev_set_name(&indio_dev->dev, "iio:device%d", iio_dev_opaque->id);
if (dev_set_name(&indio_dev->dev, "iio:device%d", iio_dev_opaque->id)) {
ida_simple_remove(&iio_ida, iio_dev_opaque->id);
kfree(iio_dev_opaque);
return NULL;
}
INIT_LIST_HEAD(&iio_dev_opaque->buffer_list); INIT_LIST_HEAD(&iio_dev_opaque->buffer_list);
INIT_LIST_HEAD(&iio_dev_opaque->ioctl_handlers); INIT_LIST_HEAD(&iio_dev_opaque->ioctl_handlers);
......
...@@ -97,6 +97,10 @@ static const struct spi_device_id st_press_id_table[] = { ...@@ -97,6 +97,10 @@ static const struct spi_device_id st_press_id_table[] = {
{ LPS33HW_PRESS_DEV_NAME }, { LPS33HW_PRESS_DEV_NAME },
{ LPS35HW_PRESS_DEV_NAME }, { LPS35HW_PRESS_DEV_NAME },
{ LPS22HH_PRESS_DEV_NAME }, { LPS22HH_PRESS_DEV_NAME },
{ "lps001wp-press" },
{ "lps25h-press", },
{ "lps331ap-press" },
{ "lps22hb-press" },
{}, {},
}; };
MODULE_DEVICE_TABLE(spi, st_press_id_table); MODULE_DEVICE_TABLE(spi, st_press_id_table);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment