Skip to content

Commit

Permalink
Merge tag 'iio-fixes-for-5.16a' of https://git.kernel.org/pub/scm/lin…
Browse files Browse the repository at this point in the history
…ux/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
  • Loading branch information
Greg Kroah-Hartman committed Oct 24, 2021
2 parents 714f1af + 486a250 commit 8210a20
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Documentation/devicetree/bindings/iio/dac/adi,ad5766.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ examples:
ad5766@0 {
compatible = "adi,ad5766";
output-range-microvolts = <(-5000) 5000>;
output-range-microvolts = <(-5000000) 5000000>;
reg = <0>;
spi-cpol;
spi-max-frequency = <1000000>;
Expand Down
2 changes: 1 addition & 1 deletion drivers/iio/adc/ti-tsc2046.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ static int tsc2046_adc_update_scan_mode(struct iio_dev *indio_dev,
priv->xfer.len = size;
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",
priv->scan_interval_us, priv->time_per_scan_us);

Expand Down
9 changes: 8 additions & 1 deletion drivers/iio/dac/ad5446.c
Original file line number Diff line number Diff line change
Expand Up @@ -531,8 +531,15 @@ static int ad5622_write(struct ad5446_state *st, unsigned val)
{
struct i2c_client *client = to_i2c_client(st->dev);
__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;
}

/*
Expand Down
6 changes: 3 additions & 3 deletions drivers/iio/dac/ad5766.c
Original file line number Diff line number Diff line change
Expand Up @@ -507,13 +507,13 @@ static int ad5766_get_output_range(struct ad5766_state *st)
int i, ret, min, max, tmp[2];

ret = device_property_read_u32_array(&st->spi->dev,
"output-range-voltage",
"output-range-microvolts",
tmp, 2);
if (ret)
return ret;

min = tmp[0] / 1000;
max = tmp[1] / 1000;
min = tmp[0] / 1000000;
max = tmp[1] / 1000000;
for (i = 0; i < ARRAY_SIZE(ad5766_span_tbl); i++) {
if (ad5766_span_tbl[i].min != min ||
ad5766_span_tbl[i].max != max)
Expand Down
28 changes: 17 additions & 11 deletions drivers/iio/industrialio-buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1434,6 +1434,11 @@ static struct attribute *iio_buffer_wrap_attr(struct iio_buffer *buffer,
iio_attr->buffer = buffer;
memcpy(&iio_attr->dev_attr, dattr, sizeof(iio_attr->dev_attr));
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);

list_add(&iio_attr->l, &buffer->buffer_attr_list);
Expand Down Expand Up @@ -1484,10 +1489,10 @@ static int iio_buffer_register_legacy_sysfs_groups(struct iio_dev *indio_dev,

return 0;

error_free_buffer_attrs:
kfree(iio_dev_opaque->legacy_buffer_group.attrs);
error_free_scan_el_attrs:
kfree(iio_dev_opaque->legacy_scan_el_group.attrs);
error_free_buffer_attrs:
kfree(iio_dev_opaque->legacy_buffer_group.attrs);

return ret;
}
Expand Down Expand Up @@ -1654,14 +1659,15 @@ static int __iio_buffer_alloc_sysfs_and_mask(struct iio_buffer *buffer,
sizeof(struct attribute *) * buffer_attrcount);

buffer_attrcount += ARRAY_SIZE(iio_buffer_attrs);
buffer->buffer_group.attrs = attr;

for (i = 0; i < buffer_attrcount; i++) {
struct attribute *wrapped;

wrapped = iio_buffer_wrap_attr(buffer, attr[i]);
if (!wrapped) {
ret = -ENOMEM;
goto error_free_scan_mask;
goto error_free_buffer_attrs;
}
attr[i] = wrapped;
}
Expand All @@ -1676,8 +1682,6 @@ static int __iio_buffer_alloc_sysfs_and_mask(struct iio_buffer *buffer,
goto error_free_buffer_attrs;
}

buffer->buffer_group.attrs = attr;

ret = iio_device_register_sysfs_group(indio_dev, &buffer->buffer_group);
if (ret)
goto error_free_buffer_attr_group_name;
Expand Down Expand Up @@ -1706,8 +1710,12 @@ static int __iio_buffer_alloc_sysfs_and_mask(struct iio_buffer *buffer,
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);
kfree(buffer->buffer_group.name);
kfree(buffer->buffer_group.attrs);
Expand Down Expand Up @@ -1739,7 +1747,7 @@ int iio_buffers_alloc_sysfs_and_mask(struct iio_dev *indio_dev)
buffer = iio_dev_opaque->attached_buffers[i];
ret = __iio_buffer_alloc_sysfs_and_mask(buffer, indio_dev, i);
if (ret) {
unwind_idx = i;
unwind_idx = i - 1;
goto error_unwind_sysfs_and_mask;
}
}
Expand All @@ -1761,7 +1769,7 @@ int iio_buffers_alloc_sysfs_and_mask(struct iio_dev *indio_dev)
error_unwind_sysfs_and_mask:
for (; unwind_idx >= 0; 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;
}
Expand All @@ -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);
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--) {
buffer = iio_dev_opaque->attached_buffers[i];
__iio_buffer_free_sysfs_and_mask(buffer);
__iio_buffer_free_sysfs_and_mask(buffer, indio_dev, i);
}
}

Expand Down
9 changes: 8 additions & 1 deletion drivers/iio/industrialio-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1600,6 +1600,7 @@ static void iio_device_unregister_sysfs(struct iio_dev *indio_dev)
kfree(iio_dev_opaque->chan_attr_group.attrs);
iio_dev_opaque->chan_attr_group.attrs = NULL;
kfree(iio_dev_opaque->groups);
iio_dev_opaque->groups = NULL;
}

static void iio_dev_release(struct device *device)
Expand Down Expand Up @@ -1664,7 +1665,13 @@ struct iio_dev *iio_device_alloc(struct device *parent, int sizeof_priv)
kfree(iio_dev_opaque);
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->ioctl_handlers);

Expand Down
4 changes: 4 additions & 0 deletions drivers/iio/pressure/st_pressure_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ static const struct spi_device_id st_press_id_table[] = {
{ LPS33HW_PRESS_DEV_NAME },
{ LPS35HW_PRESS_DEV_NAME },
{ LPS22HH_PRESS_DEV_NAME },
{ "lps001wp-press" },
{ "lps25h-press", },
{ "lps331ap-press" },
{ "lps22hb-press" },
{},
};
MODULE_DEVICE_TABLE(spi, st_press_id_table);
Expand Down

0 comments on commit 8210a20

Please sign in to comment.