Message ID | 20230719083208.88149-1-mzamazal@redhat.com (mailing list archive) |
---|---|
State | Accepted |
Headers | show |
Series | [v3] iio: core: Prevent invalid memory access when there is no parent | expand |
On Wed, Jul 19, 2023 at 10:32:08AM +0200, Milan Zamazal wrote: > Changes in v3: > - The call trace in the commit message reduced to the minimum lines > needed to explain the problem. Precisely, that deserves my tag which I already had given :-) Thank you!
On Wed, 19 Jul 2023 18:27:45 +0300 Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote: > On Wed, Jul 19, 2023 at 10:32:08AM +0200, Milan Zamazal wrote: > > > Changes in v3: > > - The call trace in the commit message reduced to the minimum lines > > needed to explain the problem. > > Precisely, that deserves my tag which I already had given :-) > Thank you! > Applied to the fixes-togreg branch of iio.git. In theory every device should have a parent, but this fix is more minimal than adding one for the dummy device (which we should still do - even if it's a virtual device of some type that we create just for this purpose). That reminds me, I was in process of fixing this for perf drivers and forgot to finish it off :) Jonathan
diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c index c117f50d0cf3..adcba832e6fa 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c @@ -1888,7 +1888,7 @@ static const struct iio_buffer_setup_ops noop_ring_setup_ops; int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod) { struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); - struct fwnode_handle *fwnode; + struct fwnode_handle *fwnode = NULL; int ret; if (!indio_dev->info) @@ -1899,7 +1899,8 @@ int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod) /* If the calling driver did not initialize firmware node, do it here */ if (dev_fwnode(&indio_dev->dev)) fwnode = dev_fwnode(&indio_dev->dev); - else + /* The default dummy IIO device has no parent */ + else if (indio_dev->dev.parent) fwnode = dev_fwnode(indio_dev->dev.parent); device_set_node(&indio_dev->dev, fwnode);