Skip to content

Commit ac917a8

Browse files
jic23gregkh
authored andcommitted
staging:iio:core set the iio_dev.info pointer to null on unregister under lock.
This prevents use of provider callbacks after it has been unregistered. Note that all code using this that can be called from a consumer *must* check the pointer before using and hold the info_exist_lock throughout the usage of the callbacks in info. Signed-off-by: Jonathan Cameron <[email protected]> Acked-by: Linus Walleij <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 08cd9ef commit ac917a8

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

drivers/staging/iio/iio.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ struct iio_buffer_setup_ops {
310310
* @chan_attr_group: [INTERN] group for all attrs in base directory
311311
* @name: [DRIVER] name of the device.
312312
* @info: [DRIVER] callbacks and constant info from driver
313+
* @info_exist_lock: [INTERN] lock to prevent use during removal
313314
* @chrdev: [INTERN] associated character device
314315
* @groups: [INTERN] attribute groups
315316
* @groupcounter: [INTERN] index of next attribute group
@@ -340,6 +341,7 @@ struct iio_dev {
340341
struct attribute_group chan_attr_group;
341342
const char *name;
342343
const struct iio_info *info;
344+
struct mutex info_exist_lock;
343345
const struct iio_buffer_setup_ops *setup_ops;
344346
struct cdev chrdev;
345347
#define IIO_MAX_GROUPS 6

drivers/staging/iio/industrialio-core.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,7 @@ struct iio_dev *iio_allocate_device(int sizeof_priv)
594594
device_initialize(&dev->dev);
595595
dev_set_drvdata(&dev->dev, (void *)dev);
596596
mutex_init(&dev->mlock);
597+
mutex_init(&dev->info_exist_lock);
597598

598599
dev->id = ida_simple_get(&iio_ida, 0, 0, GFP_KERNEL);
599600
if (dev->id < 0) {
@@ -718,6 +719,9 @@ EXPORT_SYMBOL(iio_device_register);
718719

719720
void iio_device_unregister(struct iio_dev *indio_dev)
720721
{
722+
mutex_lock(&indio_dev->info_exist_lock);
723+
indio_dev->info = NULL;
724+
mutex_unlock(&indio_dev->info_exist_lock);
721725
device_unregister(&indio_dev->dev);
722726
}
723727
EXPORT_SYMBOL(iio_device_unregister);

0 commit comments

Comments
 (0)