From: Matt Ranostay <matt.ranostay@konsulko.com>
To: jic23@kernel.org
Cc: linux-iio@vger.kernel.org, Matt Ranostay <matt.ranostay@konsulko.com>
Subject: [PATCH] iio: add NULL pointer checks to iio device additional/removal
Date: Wed, 3 Aug 2022 19:57:20 +0800 [thread overview]
Message-ID: <20220803115720.89848-1-matt.ranostay@konsulko.com> (raw)
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
next reply other threads:[~2022-08-03 11:57 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-03 11:57 Matt Ranostay [this message]
2022-08-03 17:57 ` [PATCH] iio: add NULL pointer checks to iio device additional/removal Andy Shevchenko
2022-08-03 18:00 ` Andy Shevchenko
2022-08-06 14:46 ` Jonathan Cameron
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220803115720.89848-1-matt.ranostay@konsulko.com \
--to=matt.ranostay@konsulko.com \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox