From: William Breathitt Gray <vilhelm.gray@gmail.com>
To: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: linux-iio@vger.kernel.org,
Robin van der Gracht <robin@protonic.nl>,
linux-kernel@vger.kernel.org,
Oleksij Rempel <o.rempel@pengutronix.de>,
Pengutronix Kernel Team <kernel@pengutronix.de>,
David Jander <david@protonic.nl>,
Jonathan Cameron <jic23@kernel.org>
Subject: Re: [PATCH] counter: Stop using dev_get_drvdata() to get the counter device
Date: Tue, 8 Feb 2022 10:42:18 +0900 [thread overview]
Message-ID: <YgHKekl9rJ2jH5j4@shinobu> (raw)
In-Reply-To: <20220204082556.370348-1-u.kleine-koenig@pengutronix.de>
[-- Attachment #1: Type: text/plain, Size: 3875 bytes --]
On Fri, Feb 04, 2022 at 09:25:56AM +0100, Uwe Kleine-König wrote:
> dev_get_drvdata() returns NULL since commit b56346ddbd82 ("counter: Use
> container_of instead of drvdata to track counter_device") which wrongly
> claimed there were no users of drvdata. Convert to container_of() to
> fix a null pointer dereference.
>
> Reported-by: Oleksij Rempel <o.rempel@pengutronix.de>
> Fixes: b56346ddbd82 ("counter: Use container_of instead of drvdata to track counter_device")
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
I'll pick this up and apply it to my tree.
Thanks,
William Breathitt Gray
> ---
> drivers/counter/counter-sysfs.c | 17 +++++++++++------
> 1 file changed, 11 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/counter/counter-sysfs.c b/drivers/counter/counter-sysfs.c
> index 7cc4d1d523ea..04eac41dad33 100644
> --- a/drivers/counter/counter-sysfs.c
> +++ b/drivers/counter/counter-sysfs.c
> @@ -19,6 +19,11 @@
>
> #include "counter-sysfs.h"
>
> +static inline struct counter_device *counter_from_dev(struct device *dev)
> +{
> + return container_of(dev, struct counter_device, dev);
> +}
> +
> /**
> * struct counter_attribute - Counter sysfs attribute
> * @dev_attr: device attribute for sysfs
> @@ -90,7 +95,7 @@ static ssize_t counter_comp_u8_show(struct device *dev,
> struct device_attribute *attr, char *buf)
> {
> const struct counter_attribute *const a = to_counter_attribute(attr);
> - struct counter_device *const counter = dev_get_drvdata(dev);
> + struct counter_device *const counter = counter_from_dev(dev);
> int err;
> u8 data = 0;
>
> @@ -122,7 +127,7 @@ static ssize_t counter_comp_u8_store(struct device *dev,
> const char *buf, size_t len)
> {
> const struct counter_attribute *const a = to_counter_attribute(attr);
> - struct counter_device *const counter = dev_get_drvdata(dev);
> + struct counter_device *const counter = counter_from_dev(dev);
> int err;
> bool bool_data = 0;
> u8 data = 0;
> @@ -158,7 +163,7 @@ static ssize_t counter_comp_u32_show(struct device *dev,
> struct device_attribute *attr, char *buf)
> {
> const struct counter_attribute *const a = to_counter_attribute(attr);
> - struct counter_device *const counter = dev_get_drvdata(dev);
> + struct counter_device *const counter = counter_from_dev(dev);
> const struct counter_available *const avail = a->comp.priv;
> int err;
> u32 data = 0;
> @@ -221,7 +226,7 @@ static ssize_t counter_comp_u32_store(struct device *dev,
> const char *buf, size_t len)
> {
> const struct counter_attribute *const a = to_counter_attribute(attr);
> - struct counter_device *const counter = dev_get_drvdata(dev);
> + struct counter_device *const counter = counter_from_dev(dev);
> struct counter_count *const count = a->parent;
> struct counter_synapse *const synapse = a->comp.priv;
> const struct counter_available *const avail = a->comp.priv;
> @@ -281,7 +286,7 @@ static ssize_t counter_comp_u64_show(struct device *dev,
> struct device_attribute *attr, char *buf)
> {
> const struct counter_attribute *const a = to_counter_attribute(attr);
> - struct counter_device *const counter = dev_get_drvdata(dev);
> + struct counter_device *const counter = counter_from_dev(dev);
> int err;
> u64 data = 0;
>
> @@ -309,7 +314,7 @@ static ssize_t counter_comp_u64_store(struct device *dev,
> const char *buf, size_t len)
> {
> const struct counter_attribute *const a = to_counter_attribute(attr);
> - struct counter_device *const counter = dev_get_drvdata(dev);
> + struct counter_device *const counter = counter_from_dev(dev);
> int err;
> u64 data = 0;
>
>
> base-commit: e783362eb54cd99b2cac8b3a9aeac942e6f6ac07
> --
> 2.34.1
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2022-02-08 1:50 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-03 13:54 [PATCH v1] counter: fix NULL pointer dereference on counter_comp_u8_store() Oleksij Rempel
2022-02-04 7:02 ` William Breathitt Gray
2022-02-04 8:25 ` [PATCH] counter: Stop using dev_get_drvdata() to get the counter device Uwe Kleine-König
2022-02-08 1:42 ` William Breathitt Gray [this message]
2022-02-17 14:48 ` Jarkko Nikula
2022-02-17 16:03 ` Uwe Kleine-König
2022-02-17 23:42 ` William Breathitt Gray
2022-02-18 7:47 ` Uwe Kleine-König
2022-02-18 9:11 ` William Breathitt Gray
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=YgHKekl9rJ2jH5j4@shinobu \
--to=vilhelm.gray@gmail.com \
--cc=david@protonic.nl \
--cc=jic23@kernel.org \
--cc=kernel@pengutronix.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=o.rempel@pengutronix.de \
--cc=robin@protonic.nl \
--cc=u.kleine-koenig@pengutronix.de \
/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
all inboxes | Powered by JetHome®