Skip to content

Commit 39114b8

Browse files
committed
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
2 parents da95cf6 + a10a0f3 commit 39114b8

File tree

9 files changed

+96
-39
lines changed

9 files changed

+96
-39
lines changed

drivers/iio/accel/adxl367.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,17 +1185,30 @@ static ssize_t adxl367_get_fifo_watermark(struct device *dev,
11851185
return sysfs_emit(buf, "%d\n", fifo_watermark);
11861186
}
11871187

1188-
static IIO_CONST_ATTR(hwfifo_watermark_min, "1");
1189-
static IIO_CONST_ATTR(hwfifo_watermark_max,
1190-
__stringify(ADXL367_FIFO_MAX_WATERMARK));
1188+
static ssize_t hwfifo_watermark_min_show(struct device *dev,
1189+
struct device_attribute *attr,
1190+
char *buf)
1191+
{
1192+
return sysfs_emit(buf, "%s\n", "1");
1193+
}
1194+
1195+
static ssize_t hwfifo_watermark_max_show(struct device *dev,
1196+
struct device_attribute *attr,
1197+
char *buf)
1198+
{
1199+
return sysfs_emit(buf, "%s\n", __stringify(ADXL367_FIFO_MAX_WATERMARK));
1200+
}
1201+
1202+
static IIO_DEVICE_ATTR_RO(hwfifo_watermark_min, 0);
1203+
static IIO_DEVICE_ATTR_RO(hwfifo_watermark_max, 0);
11911204
static IIO_DEVICE_ATTR(hwfifo_watermark, 0444,
11921205
adxl367_get_fifo_watermark, NULL, 0);
11931206
static IIO_DEVICE_ATTR(hwfifo_enabled, 0444,
11941207
adxl367_get_fifo_enabled, NULL, 0);
11951208

11961209
static const struct attribute *adxl367_fifo_attributes[] = {
1197-
&iio_const_attr_hwfifo_watermark_min.dev_attr.attr,
1198-
&iio_const_attr_hwfifo_watermark_max.dev_attr.attr,
1210+
&iio_dev_attr_hwfifo_watermark_min.dev_attr.attr,
1211+
&iio_dev_attr_hwfifo_watermark_max.dev_attr.attr,
11991212
&iio_dev_attr_hwfifo_watermark.dev_attr.attr,
12001213
&iio_dev_attr_hwfifo_enabled.dev_attr.attr,
12011214
NULL,

drivers/iio/accel/adxl372.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -998,17 +998,30 @@ static ssize_t adxl372_get_fifo_watermark(struct device *dev,
998998
return sprintf(buf, "%d\n", st->watermark);
999999
}
10001000

1001-
static IIO_CONST_ATTR(hwfifo_watermark_min, "1");
1002-
static IIO_CONST_ATTR(hwfifo_watermark_max,
1003-
__stringify(ADXL372_FIFO_SIZE));
1001+
static ssize_t hwfifo_watermark_min_show(struct device *dev,
1002+
struct device_attribute *attr,
1003+
char *buf)
1004+
{
1005+
return sysfs_emit(buf, "%s\n", "1");
1006+
}
1007+
1008+
static ssize_t hwfifo_watermark_max_show(struct device *dev,
1009+
struct device_attribute *attr,
1010+
char *buf)
1011+
{
1012+
return sysfs_emit(buf, "%s\n", __stringify(ADXL372_FIFO_SIZE));
1013+
}
1014+
1015+
static IIO_DEVICE_ATTR_RO(hwfifo_watermark_min, 0);
1016+
static IIO_DEVICE_ATTR_RO(hwfifo_watermark_max, 0);
10041017
static IIO_DEVICE_ATTR(hwfifo_watermark, 0444,
10051018
adxl372_get_fifo_watermark, NULL, 0);
10061019
static IIO_DEVICE_ATTR(hwfifo_enabled, 0444,
10071020
adxl372_get_fifo_enabled, NULL, 0);
10081021

10091022
static const struct attribute *adxl372_fifo_attributes[] = {
1010-
&iio_const_attr_hwfifo_watermark_min.dev_attr.attr,
1011-
&iio_const_attr_hwfifo_watermark_max.dev_attr.attr,
1023+
&iio_dev_attr_hwfifo_watermark_min.dev_attr.attr,
1024+
&iio_dev_attr_hwfifo_watermark_max.dev_attr.attr,
10121025
&iio_dev_attr_hwfifo_watermark.dev_attr.attr,
10131026
&iio_dev_attr_hwfifo_enabled.dev_attr.attr,
10141027
NULL,

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -925,17 +925,30 @@ static const struct iio_chan_spec_ext_info bmc150_accel_ext_info[] = {
925925
{ }
926926
};
927927

928-
static IIO_CONST_ATTR(hwfifo_watermark_min, "1");
929-
static IIO_CONST_ATTR(hwfifo_watermark_max,
930-
__stringify(BMC150_ACCEL_FIFO_LENGTH));
928+
static ssize_t hwfifo_watermark_min_show(struct device *dev,
929+
struct device_attribute *attr,
930+
char *buf)
931+
{
932+
return sysfs_emit(buf, "%s\n", "1");
933+
}
934+
935+
static ssize_t hwfifo_watermark_max_show(struct device *dev,
936+
struct device_attribute *attr,
937+
char *buf)
938+
{
939+
return sysfs_emit(buf, "%s\n", __stringify(BMC150_ACCEL_FIFO_LENGTH));
940+
}
941+
942+
static IIO_DEVICE_ATTR_RO(hwfifo_watermark_min, 0);
943+
static IIO_DEVICE_ATTR_RO(hwfifo_watermark_max, 0);
931944
static IIO_DEVICE_ATTR(hwfifo_enabled, S_IRUGO,
932945
bmc150_accel_get_fifo_state, NULL, 0);
933946
static IIO_DEVICE_ATTR(hwfifo_watermark, S_IRUGO,
934947
bmc150_accel_get_fifo_watermark, NULL, 0);
935948

936949
static const struct attribute *bmc150_accel_fifo_attributes[] = {
937-
&iio_const_attr_hwfifo_watermark_min.dev_attr.attr,
938-
&iio_const_attr_hwfifo_watermark_max.dev_attr.attr,
950+
&iio_dev_attr_hwfifo_watermark_min.dev_attr.attr,
951+
&iio_dev_attr_hwfifo_watermark_max.dev_attr.attr,
939952
&iio_dev_attr_hwfifo_watermark.dev_attr.attr,
940953
&iio_dev_attr_hwfifo_enabled.dev_attr.attr,
941954
NULL,

drivers/iio/adc/at91-sama5d2_adc.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2193,17 +2193,30 @@ static ssize_t at91_adc_get_watermark(struct device *dev,
21932193
return scnprintf(buf, PAGE_SIZE, "%d\n", st->dma_st.watermark);
21942194
}
21952195

2196+
static ssize_t hwfifo_watermark_min_show(struct device *dev,
2197+
struct device_attribute *attr,
2198+
char *buf)
2199+
{
2200+
return sysfs_emit(buf, "%s\n", "2");
2201+
}
2202+
2203+
static ssize_t hwfifo_watermark_max_show(struct device *dev,
2204+
struct device_attribute *attr,
2205+
char *buf)
2206+
{
2207+
return sysfs_emit(buf, "%s\n", AT91_HWFIFO_MAX_SIZE_STR);
2208+
}
2209+
21962210
static IIO_DEVICE_ATTR(hwfifo_enabled, 0444,
21972211
at91_adc_get_fifo_state, NULL, 0);
21982212
static IIO_DEVICE_ATTR(hwfifo_watermark, 0444,
21992213
at91_adc_get_watermark, NULL, 0);
2200-
2201-
static IIO_CONST_ATTR(hwfifo_watermark_min, "2");
2202-
static IIO_CONST_ATTR(hwfifo_watermark_max, AT91_HWFIFO_MAX_SIZE_STR);
2214+
static IIO_DEVICE_ATTR_RO(hwfifo_watermark_min, 0);
2215+
static IIO_DEVICE_ATTR_RO(hwfifo_watermark_max, 0);
22032216

22042217
static const struct attribute *at91_adc_fifo_attributes[] = {
2205-
&iio_const_attr_hwfifo_watermark_min.dev_attr.attr,
2206-
&iio_const_attr_hwfifo_watermark_max.dev_attr.attr,
2218+
&iio_dev_attr_hwfifo_watermark_min.dev_attr.attr,
2219+
&iio_dev_attr_hwfifo_watermark_max.dev_attr.attr,
22072220
&iio_dev_attr_hwfifo_watermark.dev_attr.attr,
22082221
&iio_dev_attr_hwfifo_enabled.dev_attr.attr,
22092222
NULL,

drivers/iio/adc/mcp3911.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@
5555
/* Internal voltage reference in mV */
5656
#define MCP3911_INT_VREF_MV 1200
5757

58-
#define MCP3911_REG_READ(reg, id) ((((reg) << 1) | ((id) << 5) | (1 << 0)) & 0xff)
59-
#define MCP3911_REG_WRITE(reg, id) ((((reg) << 1) | ((id) << 5) | (0 << 0)) & 0xff)
58+
#define MCP3911_REG_READ(reg, id) ((((reg) << 1) | ((id) << 6) | (1 << 0)) & 0xff)
59+
#define MCP3911_REG_WRITE(reg, id) ((((reg) << 1) | ((id) << 6) | (0 << 0)) & 0xff)
60+
#define MCP3911_REG_MASK GENMASK(4, 1)
6061

6162
#define MCP3911_NUM_CHANNELS 2
6263

@@ -89,8 +90,8 @@ static int mcp3911_read(struct mcp3911 *adc, u8 reg, u32 *val, u8 len)
8990

9091
be32_to_cpus(val);
9192
*val >>= ((4 - len) * 8);
92-
dev_dbg(&adc->spi->dev, "reading 0x%x from register 0x%x\n", *val,
93-
reg >> 1);
93+
dev_dbg(&adc->spi->dev, "reading 0x%x from register 0x%lx\n", *val,
94+
FIELD_GET(MCP3911_REG_MASK, reg));
9495
return ret;
9596
}
9697

@@ -248,7 +249,7 @@ static int mcp3911_write_raw(struct iio_dev *indio_dev,
248249
break;
249250

250251
case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
251-
for (int i = 0; i < sizeof(mcp3911_osr_table); i++) {
252+
for (int i = 0; i < ARRAY_SIZE(mcp3911_osr_table); i++) {
252253
if (val == mcp3911_osr_table[i]) {
253254
val = FIELD_PREP(MCP3911_CONFIG_OSR, i);
254255
ret = mcp3911_update(adc, MCP3911_REG_CONFIG, MCP3911_CONFIG_OSR,
@@ -496,7 +497,7 @@ static int mcp3911_probe(struct spi_device *spi)
496497
indio_dev->name,
497498
iio_device_id(indio_dev));
498499
if (!adc->trig)
499-
return PTR_ERR(adc->trig);
500+
return -ENOMEM;
500501

501502
adc->trig->ops = &mcp3911_trigger_ops;
502503
iio_trigger_set_drvdata(adc->trig, adc);

drivers/iio/adc/stm32-adc.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2086,18 +2086,19 @@ static int stm32_adc_generic_chan_init(struct iio_dev *indio_dev,
20862086
stm32_adc_chan_init_one(indio_dev, &channels[scan_index], val,
20872087
vin[1], scan_index, differential);
20882088

2089+
val = 0;
20892090
ret = fwnode_property_read_u32(child, "st,min-sample-time-ns", &val);
20902091
/* st,min-sample-time-ns is optional */
2091-
if (!ret) {
2092-
stm32_adc_smpr_init(adc, channels[scan_index].channel, val);
2093-
if (differential)
2094-
stm32_adc_smpr_init(adc, vin[1], val);
2095-
} else if (ret != -EINVAL) {
2092+
if (ret && ret != -EINVAL) {
20962093
dev_err(&indio_dev->dev, "Invalid st,min-sample-time-ns property %d\n",
20972094
ret);
20982095
goto err;
20992096
}
21002097

2098+
stm32_adc_smpr_init(adc, channels[scan_index].channel, val);
2099+
if (differential)
2100+
stm32_adc_smpr_init(adc, vin[1], val);
2101+
21012102
scan_index++;
21022103
}
21032104

drivers/iio/light/tsl2583.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ static int tsl2583_probe(struct i2c_client *clientp,
858858
TSL2583_POWER_OFF_DELAY_MS);
859859
pm_runtime_use_autosuspend(&clientp->dev);
860860

861-
ret = devm_iio_device_register(indio_dev->dev.parent, indio_dev);
861+
ret = iio_device_register(indio_dev);
862862
if (ret) {
863863
dev_err(&clientp->dev, "%s: iio registration failed\n",
864864
__func__);

drivers/iio/temperature/ltc2983.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,13 +1385,6 @@ static int ltc2983_setup(struct ltc2983_data *st, bool assign_iio)
13851385
return ret;
13861386
}
13871387

1388-
st->iio_chan = devm_kzalloc(&st->spi->dev,
1389-
st->iio_channels * sizeof(*st->iio_chan),
1390-
GFP_KERNEL);
1391-
1392-
if (!st->iio_chan)
1393-
return -ENOMEM;
1394-
13951388
ret = regmap_update_bits(st->regmap, LTC2983_GLOBAL_CONFIG_REG,
13961389
LTC2983_NOTCH_FREQ_MASK,
13971390
LTC2983_NOTCH_FREQ(st->filter_notch_freq));
@@ -1514,6 +1507,12 @@ static int ltc2983_probe(struct spi_device *spi)
15141507
gpiod_set_value_cansleep(gpio, 0);
15151508
}
15161509

1510+
st->iio_chan = devm_kzalloc(&spi->dev,
1511+
st->iio_channels * sizeof(*st->iio_chan),
1512+
GFP_KERNEL);
1513+
if (!st->iio_chan)
1514+
return -ENOMEM;
1515+
15171516
ret = ltc2983_setup(st, true);
15181517
if (ret)
15191518
return ret;

tools/iio/iio_utils.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,10 @@ static int calc_digits(int num)
547547
{
548548
int count = 0;
549549

550+
/* It takes a digit to represent zero */
551+
if (!num)
552+
return 1;
553+
550554
while (num != 0) {
551555
num /= 10;
552556
count++;

0 commit comments

Comments
 (0)