Linux IIO development
 help / color / mirror / Atom feed
* [PATCH] iio: add NULL pointer checks to iio device additional/removal
@ 2022-08-03 11:57 Matt Ranostay
  2022-08-03 17:57 ` Andy Shevchenko
  0 siblings, 1 reply; 4+ messages in thread
From: Matt Ranostay @ 2022-08-03 11:57 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, Matt Ranostay

Check if __iio_device_register and iio_device_unregister indio_dev
parameter isn't a NULL pointer.

Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com>
---
 drivers/iio/industrialio-core.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index 0f4dbda3b9d3..6071e52903e5 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -1896,13 +1896,14 @@ 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 iio_dev_opaque *iio_dev_opaque;
 	struct fwnode_handle *fwnode;
 	int ret;
 
-	if (!indio_dev->info)
+	if (!indio_dev || !indio_dev->info)
 		return -EINVAL;
 
+	iio_dev_opaque = to_iio_dev_opaque(indio_dev);
 	iio_dev_opaque->driver_module = this_mod;
 
 	/* If the calling driver did not initialize firmware node, do it here */
@@ -1987,7 +1988,12 @@ EXPORT_SYMBOL(__iio_device_register);
  **/
 void iio_device_unregister(struct iio_dev *indio_dev)
 {
-	struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
+	struct iio_dev_opaque *iio_dev_opaque;
+
+	if (!indio_dev)
+		return;
+
+	iio_dev_opaque = to_iio_dev_opaque(indio_dev);
 
 	cdev_device_del(&iio_dev_opaque->chrdev, &indio_dev->dev);
 
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-08-06 14:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-03 11:57 [PATCH] iio: add NULL pointer checks to iio device additional/removal Matt Ranostay
2022-08-03 17:57 ` Andy Shevchenko
2022-08-03 18:00   ` Andy Shevchenko
2022-08-06 14:46     ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox