1st set of IIO fixes for the 6.1 cycle.

Usual bunch of driver fixes + one set of fixes for driver bugs
 introduced by a core change to how buffer attributes are handled.
 
 - buffer attributes
   * Remove usage of IIO_CONST_ATTR() for buffer attributes in all drivers
     where this occurred as that broke wrapping code need to duplicate these
     for multiple buffer support. The minimal fix is moving to
     IIO_DEVICE_ATTR_RO() with separate _show() routines.  A cleanup of
     this code, preventing similar issues in future will follow next merge
     window.
 - tools/iio
   * Wrong handling of number of digits in the number 0.
 - adi,ltc2983
   * Avoid reallocating channels on each wake up from sleep by moving
     that step out of the ltc2983_setup() function.
 - microchip,mcp3911
   * Wrong ID bits + masking in debug prints.
   * Fix ARRAY_SIZE() vs sizeof() mix up.
   * Handle NULL return on trigger allocation failure correctly.
 - st,stm32-adc:
   * Ensure we initialize sampling time even when optional property not
     provided in DT. Internal channels require a minimum value that will
     not otherwise be set.
 - taos,tsl2583
   * Fix a double call of iio_device_unregister() via device managed and
     un-managed paths.
 -----BEGIN PGP SIGNATURE-----
 
 iQJFBAABCAAvFiEEbilms4eEBlKRJoGxVIU0mcT0FogFAmNVHMQRHGppYzIzQGtl
 cm5lbC5vcmcACgkQVIU0mcT0FojVEhAAkk/IPJTZItrKZFMUpp5XGO6jnIXcvZSp
 WTYIQHVaM4QFRy+YYte6lXMNkYoXMxwj+Zo3gQztlGlS4NmYm0L/RGjARTFlCJtK
 XuAPOh+XIKnPS7c428ehgAHxHKmXnYFFsS52YgQl3DzdvbPMBtoRoOURle+0uemK
 OJapDNHpW13KwJ+0ytGj2n+OapFMnErrTVKB6ZKi33cNwz6r/f4fm+KDZTDRTgtN
 Kv0+fXVtAVMtjMubM4ursXzhNbxr+/gyYDJa5/w66gh8KeEAPXrKP7M3eKhBJsNv
 LCdqN79C+YlrSsna5cug2uHuPuAxK5lVT2gGeYY1u1ejxSrsZmjRsUOnpS5ZW69P
 frt+wUMWpbBPcudN9A0HCplPOIV0VUl+mjsEt8N5WQ98ySCwcZZQwR+wLhx/0IKn
 EMJimdr52oKqF2Wde25fUD4svYgHqVHYsdOpra6Mn810G16U+jjiCYh1UzyKi9WS
 Wna7HoH+cYUzSYTJi05hMrPfJTQxleIrvS80ZqZ+FYn3rUDbN12HcIKefXmwyshm
 xlTO1oUCIlDk2EL5CAESsNmfu1rjXcXr6prcpnLKpx0w705TbeB8N7/sx4OXaaUP
 36l5P212+DkEriGpZKE+vkq5oAweNyA0FdzqNgbq+OaM6LfkGnBqloVS5GrVGfWU
 rcRx7CsfTJY=
 =XIpr
 -----END PGP SIGNATURE-----

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

Jonathan writes:
  "1st set of IIO fixes for the 6.1 cycle.

   Usual bunch of driver fixes + one set of fixes for driver bugs
   introduced by a core change to how buffer attributes are handled.

   - buffer attributes
     * Remove usage of IIO_CONST_ATTR() for buffer attributes in all drivers
       where this occurred as that broke wrapping code need to duplicate these
       for multiple buffer support. The minimal fix is moving to
       IIO_DEVICE_ATTR_RO() with separate _show() routines.  A cleanup of
       this code, preventing similar issues in future will follow next merge
       window.
   - tools/iio
     * Wrong handling of number of digits in the number 0.
   - adi,ltc2983
     * Avoid reallocating channels on each wake up from sleep by moving
       that step out of the ltc2983_setup() function.
   - microchip,mcp3911
     * Wrong ID bits + masking in debug prints.
     * Fix ARRAY_SIZE() vs sizeof() mix up.
     * Handle NULL return on trigger allocation failure correctly.
   - st,stm32-adc:
     * Ensure we initialize sampling time even when optional property not
       provided in DT. Internal channels require a minimum value that will
       not otherwise be set.
   - taos,tsl2583
     * Fix a double call of iio_device_unregister() via device managed and
       un-managed paths."

* tag 'iio-fixes-for-6.1a' of https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio:
  iio: bmc150-accel-core: Fix unsafe buffer attributes
  iio: adxl367: Fix unsafe buffer attributes
  iio: adxl372: Fix unsafe buffer attributes
  iio: at91-sama5d2_adc: Fix unsafe buffer attributes
  iio: temperature: ltc2983: allocate iio channels once
  tools: iio: iio_utils: fix digit calculation
  iio: adc: stm32-adc: fix channel sampling time init
  iio: adc: mcp3911: mask out device ID in debug prints
  iio: adc: mcp3911: use correct id bits
  iio: adc: mcp3911: return proper error code on failure to allocate trigger
  iio: adc: mcp3911: fix sizeof() vs ARRAY_SIZE() bug
  iio: light: tsl2583: Fix module unloading
This commit is contained in:
Greg Kroah-Hartman 2022-10-23 18:05:37 +02:00
commit 39114b881c
9 changed files with 96 additions and 39 deletions

View File

@ -1185,17 +1185,30 @@ static ssize_t adxl367_get_fifo_watermark(struct device *dev,
return sysfs_emit(buf, "%d\n", fifo_watermark);
}
static IIO_CONST_ATTR(hwfifo_watermark_min, "1");
static IIO_CONST_ATTR(hwfifo_watermark_max,
__stringify(ADXL367_FIFO_MAX_WATERMARK));
static ssize_t hwfifo_watermark_min_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
return sysfs_emit(buf, "%s\n", "1");
}
static ssize_t hwfifo_watermark_max_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
return sysfs_emit(buf, "%s\n", __stringify(ADXL367_FIFO_MAX_WATERMARK));
}
static IIO_DEVICE_ATTR_RO(hwfifo_watermark_min, 0);
static IIO_DEVICE_ATTR_RO(hwfifo_watermark_max, 0);
static IIO_DEVICE_ATTR(hwfifo_watermark, 0444,
adxl367_get_fifo_watermark, NULL, 0);
static IIO_DEVICE_ATTR(hwfifo_enabled, 0444,
adxl367_get_fifo_enabled, NULL, 0);
static const struct attribute *adxl367_fifo_attributes[] = {
&iio_const_attr_hwfifo_watermark_min.dev_attr.attr,
&iio_const_attr_hwfifo_watermark_max.dev_attr.attr,
&iio_dev_attr_hwfifo_watermark_min.dev_attr.attr,
&iio_dev_attr_hwfifo_watermark_max.dev_attr.attr,
&iio_dev_attr_hwfifo_watermark.dev_attr.attr,
&iio_dev_attr_hwfifo_enabled.dev_attr.attr,
NULL,

View File

@ -998,17 +998,30 @@ static ssize_t adxl372_get_fifo_watermark(struct device *dev,
return sprintf(buf, "%d\n", st->watermark);
}
static IIO_CONST_ATTR(hwfifo_watermark_min, "1");
static IIO_CONST_ATTR(hwfifo_watermark_max,
__stringify(ADXL372_FIFO_SIZE));
static ssize_t hwfifo_watermark_min_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
return sysfs_emit(buf, "%s\n", "1");
}
static ssize_t hwfifo_watermark_max_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
return sysfs_emit(buf, "%s\n", __stringify(ADXL372_FIFO_SIZE));
}
static IIO_DEVICE_ATTR_RO(hwfifo_watermark_min, 0);
static IIO_DEVICE_ATTR_RO(hwfifo_watermark_max, 0);
static IIO_DEVICE_ATTR(hwfifo_watermark, 0444,
adxl372_get_fifo_watermark, NULL, 0);
static IIO_DEVICE_ATTR(hwfifo_enabled, 0444,
adxl372_get_fifo_enabled, NULL, 0);
static const struct attribute *adxl372_fifo_attributes[] = {
&iio_const_attr_hwfifo_watermark_min.dev_attr.attr,
&iio_const_attr_hwfifo_watermark_max.dev_attr.attr,
&iio_dev_attr_hwfifo_watermark_min.dev_attr.attr,
&iio_dev_attr_hwfifo_watermark_max.dev_attr.attr,
&iio_dev_attr_hwfifo_watermark.dev_attr.attr,
&iio_dev_attr_hwfifo_enabled.dev_attr.attr,
NULL,

View File

@ -925,17 +925,30 @@ static const struct iio_chan_spec_ext_info bmc150_accel_ext_info[] = {
{ }
};
static IIO_CONST_ATTR(hwfifo_watermark_min, "1");
static IIO_CONST_ATTR(hwfifo_watermark_max,
__stringify(BMC150_ACCEL_FIFO_LENGTH));
static ssize_t hwfifo_watermark_min_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
return sysfs_emit(buf, "%s\n", "1");
}
static ssize_t hwfifo_watermark_max_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
return sysfs_emit(buf, "%s\n", __stringify(BMC150_ACCEL_FIFO_LENGTH));
}
static IIO_DEVICE_ATTR_RO(hwfifo_watermark_min, 0);
static IIO_DEVICE_ATTR_RO(hwfifo_watermark_max, 0);
static IIO_DEVICE_ATTR(hwfifo_enabled, S_IRUGO,
bmc150_accel_get_fifo_state, NULL, 0);
static IIO_DEVICE_ATTR(hwfifo_watermark, S_IRUGO,
bmc150_accel_get_fifo_watermark, NULL, 0);
static const struct attribute *bmc150_accel_fifo_attributes[] = {
&iio_const_attr_hwfifo_watermark_min.dev_attr.attr,
&iio_const_attr_hwfifo_watermark_max.dev_attr.attr,
&iio_dev_attr_hwfifo_watermark_min.dev_attr.attr,
&iio_dev_attr_hwfifo_watermark_max.dev_attr.attr,
&iio_dev_attr_hwfifo_watermark.dev_attr.attr,
&iio_dev_attr_hwfifo_enabled.dev_attr.attr,
NULL,

View File

@ -2193,17 +2193,30 @@ static ssize_t at91_adc_get_watermark(struct device *dev,
return scnprintf(buf, PAGE_SIZE, "%d\n", st->dma_st.watermark);
}
static ssize_t hwfifo_watermark_min_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
return sysfs_emit(buf, "%s\n", "2");
}
static ssize_t hwfifo_watermark_max_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
return sysfs_emit(buf, "%s\n", AT91_HWFIFO_MAX_SIZE_STR);
}
static IIO_DEVICE_ATTR(hwfifo_enabled, 0444,
at91_adc_get_fifo_state, NULL, 0);
static IIO_DEVICE_ATTR(hwfifo_watermark, 0444,
at91_adc_get_watermark, NULL, 0);
static IIO_CONST_ATTR(hwfifo_watermark_min, "2");
static IIO_CONST_ATTR(hwfifo_watermark_max, AT91_HWFIFO_MAX_SIZE_STR);
static IIO_DEVICE_ATTR_RO(hwfifo_watermark_min, 0);
static IIO_DEVICE_ATTR_RO(hwfifo_watermark_max, 0);
static const struct attribute *at91_adc_fifo_attributes[] = {
&iio_const_attr_hwfifo_watermark_min.dev_attr.attr,
&iio_const_attr_hwfifo_watermark_max.dev_attr.attr,
&iio_dev_attr_hwfifo_watermark_min.dev_attr.attr,
&iio_dev_attr_hwfifo_watermark_max.dev_attr.attr,
&iio_dev_attr_hwfifo_watermark.dev_attr.attr,
&iio_dev_attr_hwfifo_enabled.dev_attr.attr,
NULL,

View File

@ -55,8 +55,9 @@
/* Internal voltage reference in mV */
#define MCP3911_INT_VREF_MV 1200
#define MCP3911_REG_READ(reg, id) ((((reg) << 1) | ((id) << 5) | (1 << 0)) & 0xff)
#define MCP3911_REG_WRITE(reg, id) ((((reg) << 1) | ((id) << 5) | (0 << 0)) & 0xff)
#define MCP3911_REG_READ(reg, id) ((((reg) << 1) | ((id) << 6) | (1 << 0)) & 0xff)
#define MCP3911_REG_WRITE(reg, id) ((((reg) << 1) | ((id) << 6) | (0 << 0)) & 0xff)
#define MCP3911_REG_MASK GENMASK(4, 1)
#define MCP3911_NUM_CHANNELS 2
@ -89,8 +90,8 @@ static int mcp3911_read(struct mcp3911 *adc, u8 reg, u32 *val, u8 len)
be32_to_cpus(val);
*val >>= ((4 - len) * 8);
dev_dbg(&adc->spi->dev, "reading 0x%x from register 0x%x\n", *val,
reg >> 1);
dev_dbg(&adc->spi->dev, "reading 0x%x from register 0x%lx\n", *val,
FIELD_GET(MCP3911_REG_MASK, reg));
return ret;
}
@ -248,7 +249,7 @@ static int mcp3911_write_raw(struct iio_dev *indio_dev,
break;
case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
for (int i = 0; i < sizeof(mcp3911_osr_table); i++) {
for (int i = 0; i < ARRAY_SIZE(mcp3911_osr_table); i++) {
if (val == mcp3911_osr_table[i]) {
val = FIELD_PREP(MCP3911_CONFIG_OSR, i);
ret = mcp3911_update(adc, MCP3911_REG_CONFIG, MCP3911_CONFIG_OSR,
@ -496,7 +497,7 @@ static int mcp3911_probe(struct spi_device *spi)
indio_dev->name,
iio_device_id(indio_dev));
if (!adc->trig)
return PTR_ERR(adc->trig);
return -ENOMEM;
adc->trig->ops = &mcp3911_trigger_ops;
iio_trigger_set_drvdata(adc->trig, adc);

View File

@ -2086,18 +2086,19 @@ static int stm32_adc_generic_chan_init(struct iio_dev *indio_dev,
stm32_adc_chan_init_one(indio_dev, &channels[scan_index], val,
vin[1], scan_index, differential);
val = 0;
ret = fwnode_property_read_u32(child, "st,min-sample-time-ns", &val);
/* st,min-sample-time-ns is optional */
if (!ret) {
stm32_adc_smpr_init(adc, channels[scan_index].channel, val);
if (differential)
stm32_adc_smpr_init(adc, vin[1], val);
} else if (ret != -EINVAL) {
if (ret && ret != -EINVAL) {
dev_err(&indio_dev->dev, "Invalid st,min-sample-time-ns property %d\n",
ret);
goto err;
}
stm32_adc_smpr_init(adc, channels[scan_index].channel, val);
if (differential)
stm32_adc_smpr_init(adc, vin[1], val);
scan_index++;
}

View File

@ -858,7 +858,7 @@ static int tsl2583_probe(struct i2c_client *clientp,
TSL2583_POWER_OFF_DELAY_MS);
pm_runtime_use_autosuspend(&clientp->dev);
ret = devm_iio_device_register(indio_dev->dev.parent, indio_dev);
ret = iio_device_register(indio_dev);
if (ret) {
dev_err(&clientp->dev, "%s: iio registration failed\n",
__func__);

View File

@ -1385,13 +1385,6 @@ static int ltc2983_setup(struct ltc2983_data *st, bool assign_iio)
return ret;
}
st->iio_chan = devm_kzalloc(&st->spi->dev,
st->iio_channels * sizeof(*st->iio_chan),
GFP_KERNEL);
if (!st->iio_chan)
return -ENOMEM;
ret = regmap_update_bits(st->regmap, LTC2983_GLOBAL_CONFIG_REG,
LTC2983_NOTCH_FREQ_MASK,
LTC2983_NOTCH_FREQ(st->filter_notch_freq));
@ -1514,6 +1507,12 @@ static int ltc2983_probe(struct spi_device *spi)
gpiod_set_value_cansleep(gpio, 0);
}
st->iio_chan = devm_kzalloc(&spi->dev,
st->iio_channels * sizeof(*st->iio_chan),
GFP_KERNEL);
if (!st->iio_chan)
return -ENOMEM;
ret = ltc2983_setup(st, true);
if (ret)
return ret;

View File

@ -547,6 +547,10 @@ static int calc_digits(int num)
{
int count = 0;
/* It takes a digit to represent zero */
if (!num)
return 1;
while (num != 0) {
num /= 10;
count++;