Skip to content

Commit 38e9f21

Browse files
committed
Merge tag 'iio-fixes-for-6.1b' of https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into char-misc-linus
Jonathan writes: "2nd set of IIO fixes for 6.1 Another mixed bag of driver fixes. * atmel,at91-sama5d2 - Drop a 5 degree offset as not needed for production devices. - Missing iio_trigger_free() in error path. * bosch,bma400 - Turn power on before trying to read chip ID. * bosch,bno055 - Avoid uninitialized variable warning (no actual impact) * meas,ms5611 - Fix multiple instances of driver sharing single prom array. - Stop forcing SPI speed to max devices supports * mps,mp2629 - Wrong structure field used to match channel. - Missing NULL terminator. * sysfs-trigger - Fix memory leak in error path. * tools - Fix wrong read size when calling with noevents." * tag 'iio-fixes-for-6.1b' of https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio: tools: iio: iio_generic_buffer: Fix read size iio: imu: bno055: uninitialized variable bug in bno055_trigger_handler() iio: adc: at91_adc: fix possible memory leak in at91_adc_allocate_trigger() iio: adc: mp2629: fix potential array out of bound access iio: adc: mp2629: fix wrong comparison of channel iio: pressure: ms5611: changed hardcoded SPI speed to value limited iio: pressure: ms5611: fixed value compensation bug iio: accel: bma400: Ensure VDDIO is enable defore reading the chip ID. iio: adc: at91-sama5d2_adc: get rid of 5 degrees Celsius adjustment iio: trigger: sysfs: fix possible memory leak in iio_sysfs_trig_init()
2 parents 30a0b95 + 7c919b6 commit 38e9f21

File tree

10 files changed

+60
-56
lines changed

10 files changed

+60
-56
lines changed

drivers/iio/accel/bma400_core.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -869,18 +869,6 @@ static int bma400_init(struct bma400_data *data)
869869
unsigned int val;
870870
int ret;
871871

872-
/* Try to read chip_id register. It must return 0x90. */
873-
ret = regmap_read(data->regmap, BMA400_CHIP_ID_REG, &val);
874-
if (ret) {
875-
dev_err(data->dev, "Failed to read chip id register\n");
876-
return ret;
877-
}
878-
879-
if (val != BMA400_ID_REG_VAL) {
880-
dev_err(data->dev, "Chip ID mismatch\n");
881-
return -ENODEV;
882-
}
883-
884872
data->regulators[BMA400_VDD_REGULATOR].supply = "vdd";
885873
data->regulators[BMA400_VDDIO_REGULATOR].supply = "vddio";
886874
ret = devm_regulator_bulk_get(data->dev,
@@ -906,6 +894,18 @@ static int bma400_init(struct bma400_data *data)
906894
if (ret)
907895
return ret;
908896

897+
/* Try to read chip_id register. It must return 0x90. */
898+
ret = regmap_read(data->regmap, BMA400_CHIP_ID_REG, &val);
899+
if (ret) {
900+
dev_err(data->dev, "Failed to read chip id register\n");
901+
return ret;
902+
}
903+
904+
if (val != BMA400_ID_REG_VAL) {
905+
dev_err(data->dev, "Chip ID mismatch\n");
906+
return -ENODEV;
907+
}
908+
909909
ret = bma400_get_power_mode(data);
910910
if (ret) {
911911
dev_err(data->dev, "Failed to get the initial power-mode\n");

drivers/iio/adc/at91-sama5d2_adc.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2307,11 +2307,9 @@ static int at91_adc_temp_sensor_init(struct at91_adc_state *st,
23072307
clb->p6 = buf[AT91_ADC_TS_CLB_IDX_P6];
23082308

23092309
/*
2310-
* We prepare here the conversion to milli and also add constant
2311-
* factor (5 degrees Celsius) to p1 here to avoid doing it on
2312-
* hotpath.
2310+
* We prepare here the conversion to milli to avoid doing it on hotpath.
23132311
*/
2314-
clb->p1 = clb->p1 * 1000 + 5000;
2312+
clb->p1 = clb->p1 * 1000;
23152313

23162314
free_buf:
23172315
kfree(buf);

drivers/iio/adc/at91_adc.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,8 +634,10 @@ static struct iio_trigger *at91_adc_allocate_trigger(struct iio_dev *idev,
634634
trig->ops = &at91_adc_trigger_ops;
635635

636636
ret = iio_trigger_register(trig);
637-
if (ret)
637+
if (ret) {
638+
iio_trigger_free(trig);
638639
return NULL;
640+
}
639641

640642
return trig;
641643
}

drivers/iio/adc/mp2629_adc.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ static struct iio_map mp2629_adc_maps[] = {
5757
MP2629_MAP(SYSTEM_VOLT, "system-volt"),
5858
MP2629_MAP(INPUT_VOLT, "input-volt"),
5959
MP2629_MAP(BATT_CURRENT, "batt-current"),
60-
MP2629_MAP(INPUT_CURRENT, "input-current")
60+
MP2629_MAP(INPUT_CURRENT, "input-current"),
61+
{ }
6162
};
6263

6364
static int mp2629_read_raw(struct iio_dev *indio_dev,
@@ -74,7 +75,7 @@ static int mp2629_read_raw(struct iio_dev *indio_dev,
7475
if (ret)
7576
return ret;
7677

77-
if (chan->address == MP2629_INPUT_VOLT)
78+
if (chan->channel == MP2629_INPUT_VOLT)
7879
rval &= GENMASK(6, 0);
7980
*val = rval;
8081
return IIO_VAL_INT;

drivers/iio/imu/bno055/bno055.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ static int bno055_set_regmask(struct bno055_priv *priv, int val, int val2,
632632
return -EINVAL;
633633
}
634634
delta = abs(tbl_val - req_val);
635-
if (delta < best_delta || first) {
635+
if (first || delta < best_delta) {
636636
best_delta = delta;
637637
hwval = i;
638638
first = false;

drivers/iio/pressure/ms5611.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,6 @@ enum {
2525
MS5607,
2626
};
2727

28-
struct ms5611_chip_info {
29-
u16 prom[MS5611_PROM_WORDS_NB];
30-
31-
int (*temp_and_pressure_compensate)(struct ms5611_chip_info *chip_info,
32-
s32 *temp, s32 *pressure);
33-
};
34-
3528
/*
3629
* OverSampling Rate descriptor.
3730
* Warning: cmd MUST be kept aligned on a word boundary (see
@@ -50,12 +43,15 @@ struct ms5611_state {
5043
const struct ms5611_osr *pressure_osr;
5144
const struct ms5611_osr *temp_osr;
5245

46+
u16 prom[MS5611_PROM_WORDS_NB];
47+
5348
int (*reset)(struct ms5611_state *st);
5449
int (*read_prom_word)(struct ms5611_state *st, int index, u16 *word);
5550
int (*read_adc_temp_and_pressure)(struct ms5611_state *st,
5651
s32 *temp, s32 *pressure);
5752

58-
struct ms5611_chip_info *chip_info;
53+
int (*compensate_temp_and_pressure)(struct ms5611_state *st, s32 *temp,
54+
s32 *pressure);
5955
struct regulator *vdd;
6056
};
6157

drivers/iio/pressure/ms5611_core.c

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,15 @@ static int ms5611_read_prom(struct iio_dev *indio_dev)
8585
struct ms5611_state *st = iio_priv(indio_dev);
8686

8787
for (i = 0; i < MS5611_PROM_WORDS_NB; i++) {
88-
ret = st->read_prom_word(st, i, &st->chip_info->prom[i]);
88+
ret = st->read_prom_word(st, i, &st->prom[i]);
8989
if (ret < 0) {
9090
dev_err(&indio_dev->dev,
9191
"failed to read prom at %d\n", i);
9292
return ret;
9393
}
9494
}
9595

96-
if (!ms5611_prom_is_valid(st->chip_info->prom, MS5611_PROM_WORDS_NB)) {
96+
if (!ms5611_prom_is_valid(st->prom, MS5611_PROM_WORDS_NB)) {
9797
dev_err(&indio_dev->dev, "PROM integrity check failed\n");
9898
return -ENODEV;
9999
}
@@ -114,21 +114,20 @@ static int ms5611_read_temp_and_pressure(struct iio_dev *indio_dev,
114114
return ret;
115115
}
116116

117-
return st->chip_info->temp_and_pressure_compensate(st->chip_info,
118-
temp, pressure);
117+
return st->compensate_temp_and_pressure(st, temp, pressure);
119118
}
120119

121-
static int ms5611_temp_and_pressure_compensate(struct ms5611_chip_info *chip_info,
120+
static int ms5611_temp_and_pressure_compensate(struct ms5611_state *st,
122121
s32 *temp, s32 *pressure)
123122
{
124123
s32 t = *temp, p = *pressure;
125124
s64 off, sens, dt;
126125

127-
dt = t - (chip_info->prom[5] << 8);
128-
off = ((s64)chip_info->prom[2] << 16) + ((chip_info->prom[4] * dt) >> 7);
129-
sens = ((s64)chip_info->prom[1] << 15) + ((chip_info->prom[3] * dt) >> 8);
126+
dt = t - (st->prom[5] << 8);
127+
off = ((s64)st->prom[2] << 16) + ((st->prom[4] * dt) >> 7);
128+
sens = ((s64)st->prom[1] << 15) + ((st->prom[3] * dt) >> 8);
130129

131-
t = 2000 + ((chip_info->prom[6] * dt) >> 23);
130+
t = 2000 + ((st->prom[6] * dt) >> 23);
132131
if (t < 2000) {
133132
s64 off2, sens2, t2;
134133

@@ -154,17 +153,17 @@ static int ms5611_temp_and_pressure_compensate(struct ms5611_chip_info *chip_inf
154153
return 0;
155154
}
156155

157-
static int ms5607_temp_and_pressure_compensate(struct ms5611_chip_info *chip_info,
156+
static int ms5607_temp_and_pressure_compensate(struct ms5611_state *st,
158157
s32 *temp, s32 *pressure)
159158
{
160159
s32 t = *temp, p = *pressure;
161160
s64 off, sens, dt;
162161

163-
dt = t - (chip_info->prom[5] << 8);
164-
off = ((s64)chip_info->prom[2] << 17) + ((chip_info->prom[4] * dt) >> 6);
165-
sens = ((s64)chip_info->prom[1] << 16) + ((chip_info->prom[3] * dt) >> 7);
162+
dt = t - (st->prom[5] << 8);
163+
off = ((s64)st->prom[2] << 17) + ((st->prom[4] * dt) >> 6);
164+
sens = ((s64)st->prom[1] << 16) + ((st->prom[3] * dt) >> 7);
166165

167-
t = 2000 + ((chip_info->prom[6] * dt) >> 23);
166+
t = 2000 + ((st->prom[6] * dt) >> 23);
168167
if (t < 2000) {
169168
s64 off2, sens2, t2, tmp;
170169

@@ -342,15 +341,6 @@ static int ms5611_write_raw(struct iio_dev *indio_dev,
342341

343342
static const unsigned long ms5611_scan_masks[] = {0x3, 0};
344343

345-
static struct ms5611_chip_info chip_info_tbl[] = {
346-
[MS5611] = {
347-
.temp_and_pressure_compensate = ms5611_temp_and_pressure_compensate,
348-
},
349-
[MS5607] = {
350-
.temp_and_pressure_compensate = ms5607_temp_and_pressure_compensate,
351-
}
352-
};
353-
354344
static const struct iio_chan_spec ms5611_channels[] = {
355345
{
356346
.type = IIO_PRESSURE,
@@ -433,7 +423,20 @@ int ms5611_probe(struct iio_dev *indio_dev, struct device *dev,
433423
struct ms5611_state *st = iio_priv(indio_dev);
434424

435425
mutex_init(&st->lock);
436-
st->chip_info = &chip_info_tbl[type];
426+
427+
switch (type) {
428+
case MS5611:
429+
st->compensate_temp_and_pressure =
430+
ms5611_temp_and_pressure_compensate;
431+
break;
432+
case MS5607:
433+
st->compensate_temp_and_pressure =
434+
ms5607_temp_and_pressure_compensate;
435+
break;
436+
default:
437+
return -EINVAL;
438+
}
439+
437440
st->temp_osr =
438441
&ms5611_avail_temp_osr[ARRAY_SIZE(ms5611_avail_temp_osr) - 1];
439442
st->pressure_osr =

drivers/iio/pressure/ms5611_spi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ static int ms5611_spi_probe(struct spi_device *spi)
9191
spi_set_drvdata(spi, indio_dev);
9292

9393
spi->mode = SPI_MODE_0;
94-
spi->max_speed_hz = 20000000;
94+
spi->max_speed_hz = min(spi->max_speed_hz, 20000000U);
9595
spi->bits_per_word = 8;
9696
ret = spi_setup(spi);
9797
if (ret < 0)

drivers/iio/trigger/iio-trig-sysfs.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,13 @@ static int iio_sysfs_trigger_remove(int id)
203203

204204
static int __init iio_sysfs_trig_init(void)
205205
{
206+
int ret;
206207
device_initialize(&iio_sysfs_trig_dev);
207208
dev_set_name(&iio_sysfs_trig_dev, "iio_sysfs_trigger");
208-
return device_add(&iio_sysfs_trig_dev);
209+
ret = device_add(&iio_sysfs_trig_dev);
210+
if (ret)
211+
put_device(&iio_sysfs_trig_dev);
212+
return ret;
209213
}
210214
module_init(iio_sysfs_trig_init);
211215

tools/iio/iio_generic_buffer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -715,12 +715,12 @@ int main(int argc, char **argv)
715715
continue;
716716
}
717717

718-
toread = buf_len;
719718
} else {
720719
usleep(timedelay);
721-
toread = 64;
722720
}
723721

722+
toread = buf_len;
723+
724724
read_size = read(buf_fd, data, toread * scan_size);
725725
if (read_size < 0) {
726726
if (errno == EAGAIN) {

0 commit comments

Comments
 (0)