Skip to content

Commit 6a058f0

Browse files
committed
Merge tag 'staging-5.8-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging into master
Pull IIO and staging driver fixes from Greg KH: "Here are some IIO and staging driver fixes for 5.8-rc6. The majority of fixes are for IIO drivers, resolving a number of small reported issues, and there are some counter fixes in here too that were tied to the IIO fixes. There's only one staging driver fix here, a comedi fix found by code inspection. All of these have been in linux-next for a while with no reported issues" * tag 'staging-5.8-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging: staging: comedi: verify array index is correct before using it iio: adc: ad7780: Fix a resource handling path in 'ad7780_probe()' iio:pressure:ms5611 Fix buffer element alignment iio:humidity:hts221 Fix alignment and data leak issues iio:humidity:hdc100x Fix alignment and data leak issues iio:magnetometer:ak8974: Fix alignment and data leak issues iio: adc: adi-axi-adc: Fix object reference counting iio: pressure: zpa2326: handle pm_runtime_get_sync failure counter: 104-quad-8: Add lock guards - filter clock prescaler counter: 104-quad-8: Add lock guards - differential encoder iio: core: add missing IIO_MOD_H2/ETHANOL string identifiers iio: magnetometer: ak8974: Fix runtime PM imbalance on error iio: mma8452: Add missed iio_device_unregister() call in mma8452_probe() iio:health:afe4404 Fix timestamp alignment and prevent data leak. iio:health:afe4403 Fix timestamp alignment and prevent data leak.
2 parents 7531ee3 + ef75e14 commit 6a058f0

File tree

14 files changed

+91
-41
lines changed

14 files changed

+91
-41
lines changed

drivers/counter/104-quad-8.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,18 +1274,26 @@ static ssize_t quad8_signal_cable_fault_read(struct counter_device *counter,
12741274
struct counter_signal *signal,
12751275
void *private, char *buf)
12761276
{
1277-
const struct quad8_iio *const priv = counter->priv;
1277+
struct quad8_iio *const priv = counter->priv;
12781278
const size_t channel_id = signal->id / 2;
1279-
const bool disabled = !(priv->cable_fault_enable & BIT(channel_id));
1279+
bool disabled;
12801280
unsigned int status;
12811281
unsigned int fault;
12821282

1283-
if (disabled)
1283+
mutex_lock(&priv->lock);
1284+
1285+
disabled = !(priv->cable_fault_enable & BIT(channel_id));
1286+
1287+
if (disabled) {
1288+
mutex_unlock(&priv->lock);
12841289
return -EINVAL;
1290+
}
12851291

12861292
/* Logic 0 = cable fault */
12871293
status = inb(priv->base + QUAD8_DIFF_ENCODER_CABLE_STATUS);
12881294

1295+
mutex_unlock(&priv->lock);
1296+
12891297
/* Mask respective channel and invert logic */
12901298
fault = !(status & BIT(channel_id));
12911299

@@ -1317,6 +1325,8 @@ static ssize_t quad8_signal_cable_fault_enable_write(
13171325
if (ret)
13181326
return ret;
13191327

1328+
mutex_lock(&priv->lock);
1329+
13201330
if (enable)
13211331
priv->cable_fault_enable |= BIT(channel_id);
13221332
else
@@ -1327,6 +1337,8 @@ static ssize_t quad8_signal_cable_fault_enable_write(
13271337

13281338
outb(cable_fault_enable, priv->base + QUAD8_DIFF_ENCODER_CABLE_STATUS);
13291339

1340+
mutex_unlock(&priv->lock);
1341+
13301342
return len;
13311343
}
13321344

@@ -1353,6 +1365,8 @@ static ssize_t quad8_signal_fck_prescaler_write(struct counter_device *counter,
13531365
if (ret)
13541366
return ret;
13551367

1368+
mutex_lock(&priv->lock);
1369+
13561370
priv->fck_prescaler[channel_id] = prescaler;
13571371

13581372
/* Reset Byte Pointer */
@@ -1363,6 +1377,8 @@ static ssize_t quad8_signal_fck_prescaler_write(struct counter_device *counter,
13631377
outb(QUAD8_CTR_RLD | QUAD8_RLD_RESET_BP | QUAD8_RLD_PRESET_PSC,
13641378
base_offset + 1);
13651379

1380+
mutex_unlock(&priv->lock);
1381+
13661382
return len;
13671383
}
13681384

drivers/iio/accel/mma8452.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1685,10 +1685,13 @@ static int mma8452_probe(struct i2c_client *client,
16851685

16861686
ret = mma8452_set_freefall_mode(data, false);
16871687
if (ret < 0)
1688-
goto buffer_cleanup;
1688+
goto unregister_device;
16891689

16901690
return 0;
16911691

1692+
unregister_device:
1693+
iio_device_unregister(indio_dev);
1694+
16921695
buffer_cleanup:
16931696
iio_triggered_buffer_cleanup(indio_dev);
16941697

drivers/iio/adc/ad7780.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ static int ad7780_probe(struct spi_device *spi)
329329

330330
ret = ad7780_init_gpios(&spi->dev, st);
331331
if (ret)
332-
goto error_cleanup_buffer_and_trigger;
332+
return ret;
333333

334334
st->reg = devm_regulator_get(&spi->dev, "avdd");
335335
if (IS_ERR(st->reg))

drivers/iio/adc/adi-axi-adc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,12 +332,12 @@ static struct adi_axi_adc_client *adi_axi_adc_attach_client(struct device *dev)
332332
if (cl->dev->of_node != cln)
333333
continue;
334334

335-
if (!try_module_get(dev->driver->owner)) {
335+
if (!try_module_get(cl->dev->driver->owner)) {
336336
mutex_unlock(&registered_clients_lock);
337337
return ERR_PTR(-ENODEV);
338338
}
339339

340-
get_device(dev);
340+
get_device(cl->dev);
341341
cl->info = info;
342342
mutex_unlock(&registered_clients_lock);
343343
return cl;

drivers/iio/health/afe4403.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ static const struct reg_field afe4403_reg_fields[] = {
6565
* @regulator: Pointer to the regulator for the IC
6666
* @trig: IIO trigger for this device
6767
* @irq: ADC_RDY line interrupt number
68+
* @buffer: Used to construct data layout to push into IIO buffer.
6869
*/
6970
struct afe4403_data {
7071
struct device *dev;
@@ -74,6 +75,8 @@ struct afe4403_data {
7475
struct regulator *regulator;
7576
struct iio_trigger *trig;
7677
int irq;
78+
/* Ensure suitable alignment for timestamp */
79+
s32 buffer[8] __aligned(8);
7780
};
7881

7982
enum afe4403_chan_id {
@@ -309,7 +312,6 @@ static irqreturn_t afe4403_trigger_handler(int irq, void *private)
309312
struct iio_dev *indio_dev = pf->indio_dev;
310313
struct afe4403_data *afe = iio_priv(indio_dev);
311314
int ret, bit, i = 0;
312-
s32 buffer[8];
313315
u8 tx[4] = {AFE440X_CONTROL0, 0x0, 0x0, AFE440X_CONTROL0_READ};
314316
u8 rx[3];
315317

@@ -326,7 +328,7 @@ static irqreturn_t afe4403_trigger_handler(int irq, void *private)
326328
if (ret)
327329
goto err;
328330

329-
buffer[i++] = get_unaligned_be24(&rx[0]);
331+
afe->buffer[i++] = get_unaligned_be24(&rx[0]);
330332
}
331333

332334
/* Disable reading from the device */
@@ -335,7 +337,8 @@ static irqreturn_t afe4403_trigger_handler(int irq, void *private)
335337
if (ret)
336338
goto err;
337339

338-
iio_push_to_buffers_with_timestamp(indio_dev, buffer, pf->timestamp);
340+
iio_push_to_buffers_with_timestamp(indio_dev, afe->buffer,
341+
pf->timestamp);
339342
err:
340343
iio_trigger_notify_done(indio_dev->trig);
341344

drivers/iio/health/afe4404.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ static const struct reg_field afe4404_reg_fields[] = {
8383
* @regulator: Pointer to the regulator for the IC
8484
* @trig: IIO trigger for this device
8585
* @irq: ADC_RDY line interrupt number
86+
* @buffer: Used to construct a scan to push to the iio buffer.
8687
*/
8788
struct afe4404_data {
8889
struct device *dev;
@@ -91,6 +92,7 @@ struct afe4404_data {
9192
struct regulator *regulator;
9293
struct iio_trigger *trig;
9394
int irq;
95+
s32 buffer[10] __aligned(8);
9496
};
9597

9698
enum afe4404_chan_id {
@@ -328,17 +330,17 @@ static irqreturn_t afe4404_trigger_handler(int irq, void *private)
328330
struct iio_dev *indio_dev = pf->indio_dev;
329331
struct afe4404_data *afe = iio_priv(indio_dev);
330332
int ret, bit, i = 0;
331-
s32 buffer[10];
332333

333334
for_each_set_bit(bit, indio_dev->active_scan_mask,
334335
indio_dev->masklength) {
335336
ret = regmap_read(afe->regmap, afe4404_channel_values[bit],
336-
&buffer[i++]);
337+
&afe->buffer[i++]);
337338
if (ret)
338339
goto err;
339340
}
340341

341-
iio_push_to_buffers_with_timestamp(indio_dev, buffer, pf->timestamp);
342+
iio_push_to_buffers_with_timestamp(indio_dev, afe->buffer,
343+
pf->timestamp);
342344
err:
343345
iio_trigger_notify_done(indio_dev->trig);
344346

drivers/iio/humidity/hdc100x.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ struct hdc100x_data {
3838

3939
/* integration time of the sensor */
4040
int adc_int_us[2];
41+
/* Ensure natural alignment of timestamp */
42+
struct {
43+
__be16 channels[2];
44+
s64 ts __aligned(8);
45+
} scan;
4146
};
4247

4348
/* integration time in us */
@@ -322,7 +327,6 @@ static irqreturn_t hdc100x_trigger_handler(int irq, void *p)
322327
struct i2c_client *client = data->client;
323328
int delay = data->adc_int_us[0] + data->adc_int_us[1];
324329
int ret;
325-
s16 buf[8]; /* 2x s16 + padding + 8 byte timestamp */
326330

327331
/* dual read starts at temp register */
328332
mutex_lock(&data->lock);
@@ -333,13 +337,13 @@ static irqreturn_t hdc100x_trigger_handler(int irq, void *p)
333337
}
334338
usleep_range(delay, delay + 1000);
335339

336-
ret = i2c_master_recv(client, (u8 *)buf, 4);
340+
ret = i2c_master_recv(client, (u8 *)data->scan.channels, 4);
337341
if (ret < 0) {
338342
dev_err(&client->dev, "cannot read sensor data\n");
339343
goto err;
340344
}
341345

342-
iio_push_to_buffers_with_timestamp(indio_dev, buf,
346+
iio_push_to_buffers_with_timestamp(indio_dev, &data->scan,
343347
iio_get_time_ns(indio_dev));
344348
err:
345349
mutex_unlock(&data->lock);

drivers/iio/humidity/hts221.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
#include <linux/iio/iio.h>
1616

17-
#define HTS221_DATA_SIZE 2
18-
1917
enum hts221_sensor_type {
2018
HTS221_SENSOR_H,
2119
HTS221_SENSOR_T,
@@ -39,6 +37,11 @@ struct hts221_hw {
3937

4038
bool enabled;
4139
u8 odr;
40+
/* Ensure natural alignment of timestamp */
41+
struct {
42+
__le16 channels[2];
43+
s64 ts __aligned(8);
44+
} scan;
4245
};
4346

4447
extern const struct dev_pm_ops hts221_pm_ops;

drivers/iio/humidity/hts221_buffer.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ static const struct iio_buffer_setup_ops hts221_buffer_ops = {
160160

161161
static irqreturn_t hts221_buffer_handler_thread(int irq, void *p)
162162
{
163-
u8 buffer[ALIGN(2 * HTS221_DATA_SIZE, sizeof(s64)) + sizeof(s64)];
164163
struct iio_poll_func *pf = p;
165164
struct iio_dev *iio_dev = pf->indio_dev;
166165
struct hts221_hw *hw = iio_priv(iio_dev);
@@ -170,18 +169,20 @@ static irqreturn_t hts221_buffer_handler_thread(int irq, void *p)
170169
/* humidity data */
171170
ch = &iio_dev->channels[HTS221_SENSOR_H];
172171
err = regmap_bulk_read(hw->regmap, ch->address,
173-
buffer, HTS221_DATA_SIZE);
172+
&hw->scan.channels[0],
173+
sizeof(hw->scan.channels[0]));
174174
if (err < 0)
175175
goto out;
176176

177177
/* temperature data */
178178
ch = &iio_dev->channels[HTS221_SENSOR_T];
179179
err = regmap_bulk_read(hw->regmap, ch->address,
180-
buffer + HTS221_DATA_SIZE, HTS221_DATA_SIZE);
180+
&hw->scan.channels[1],
181+
sizeof(hw->scan.channels[1]));
181182
if (err < 0)
182183
goto out;
183184

184-
iio_push_to_buffers_with_timestamp(iio_dev, buffer,
185+
iio_push_to_buffers_with_timestamp(iio_dev, &hw->scan,
185186
iio_get_time_ns(iio_dev));
186187

187188
out:

drivers/iio/industrialio-core.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ static const char * const iio_modifier_names[] = {
130130
[IIO_MOD_PM2P5] = "pm2p5",
131131
[IIO_MOD_PM4] = "pm4",
132132
[IIO_MOD_PM10] = "pm10",
133+
[IIO_MOD_ETHANOL] = "ethanol",
134+
[IIO_MOD_H2] = "h2",
133135
};
134136

135137
/* relies on pairs of these shared then separate */

0 commit comments

Comments
 (0)