[PATCH] iio: add NULL pointer checks to iio device additional/removal

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

Signed-off-by: Matt Ranostay <matt.ranostay@xxxxxxxxxxxx>
---
 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




[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux