public inbox for linux-iio@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] counter: Stop using dev_get_drvdata() to get the counter device
  2022-02-04  7:02 [PATCH v1] counter: fix NULL pointer dereference on counter_comp_u8_store() William Breathitt Gray
@ 2022-02-04  8:25 ` Uwe Kleine-König
  2022-02-08  1:42   ` William Breathitt Gray
  0 siblings, 1 reply; 9+ messages in thread
From: Uwe Kleine-König @ 2022-02-04  8:25 UTC (permalink / raw)
  To: William Breathitt Gray
  Cc: linux-iio, Robin van der Gracht, linux-kernel, Oleksij Rempel,
	Pengutronix Kernel Team, David Jander, Jonathan Cameron

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>
---
 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


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

* Re: [PATCH] counter: Stop using dev_get_drvdata() to get the counter device
  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
  2022-02-17 14:48     ` Jarkko Nikula
  0 siblings, 1 reply; 9+ messages in thread
From: William Breathitt Gray @ 2022-02-08  1:42 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: linux-iio, Robin van der Gracht, linux-kernel, Oleksij Rempel,
	Pengutronix Kernel Team, David Jander, Jonathan Cameron

[-- 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 --]

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

* Re: [PATCH] counter: Stop using dev_get_drvdata() to get the counter device
  2022-02-08  1:42   ` William Breathitt Gray
@ 2022-02-17 14:48     ` Jarkko Nikula
  2022-02-17 16:03       ` Uwe Kleine-König
  0 siblings, 1 reply; 9+ messages in thread
From: Jarkko Nikula @ 2022-02-17 14:48 UTC (permalink / raw)
  To: William Breathitt Gray, Uwe Kleine-König
  Cc: linux-iio, Robin van der Gracht, linux-kernel, Oleksij Rempel,
	Pengutronix Kernel Team, David Jander, Jonathan Cameron

Hi

On 2/8/22 03:42, William Breathitt Gray wrote:
> 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.
> 
Perhaps late but I hit this same issue, patch here fixes it and I wanted 
to confirm it.

Tested-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>

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

* Re: [PATCH] counter: Stop using dev_get_drvdata() to get the counter device
  2022-02-17 14:48     ` Jarkko Nikula
@ 2022-02-17 16:03       ` Uwe Kleine-König
  2022-02-17 23:42         ` William Breathitt Gray
  0 siblings, 1 reply; 9+ messages in thread
From: Uwe Kleine-König @ 2022-02-17 16:03 UTC (permalink / raw)
  To: William Breathitt Gray
  Cc: Jarkko Nikula, linux-iio, Robin van der Gracht, linux-kernel,
	Oleksij Rempel, Pengutronix Kernel Team, David Jander,
	Jonathan Cameron

[-- Attachment #1: Type: text/plain, Size: 1184 bytes --]

On Thu, Feb 17, 2022 at 04:48:50PM +0200, Jarkko Nikula wrote:
> On 2/8/22 03:42, William Breathitt Gray wrote:
> > 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.
>
> Perhaps late but I hit this same issue, patch here fixes it and I wanted to
> confirm it.
> 
> Tested-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>

I wonder if this patch is scheduled for 5.17. Currently it's not even in
next ... :-\

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH] counter: Stop using dev_get_drvdata() to get the counter device
  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
  0 siblings, 1 reply; 9+ messages in thread
From: William Breathitt Gray @ 2022-02-17 23:42 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Jarkko Nikula, linux-iio, Robin van der Gracht, linux-kernel,
	Oleksij Rempel, Pengutronix Kernel Team, David Jander,
	Jonathan Cameron

[-- Attachment #1: Type: text/plain, Size: 1334 bytes --]

On Thu, Feb 17, 2022 at 05:03:08PM +0100, Uwe Kleine-König wrote:
> On Thu, Feb 17, 2022 at 04:48:50PM +0200, Jarkko Nikula wrote:
> > On 2/8/22 03:42, William Breathitt Gray wrote:
> > > 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.
> >
> > Perhaps late but I hit this same issue, patch here fixes it and I wanted to
> > confirm it.
> > 
> > Tested-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
> 
> I wonder if this patch is scheduled for 5.17. Currently it's not even in
> next ... :-\
> 
> Best regards
> Uwe

Hi Uwe,

I've got it in my tree. I'm sending a pull request for the Counter
patches for 5.17 next week, so they should all be merged after that.

Sincerely,

William Breathitt Gray

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH] counter: Stop using dev_get_drvdata() to get the counter device
  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
  0 siblings, 1 reply; 9+ messages in thread
From: Uwe Kleine-König @ 2022-02-18  7:47 UTC (permalink / raw)
  To: William Breathitt Gray
  Cc: linux-iio, Robin van der Gracht, linux-kernel, Oleksij Rempel,
	Jarkko Nikula, Pengutronix Kernel Team, David Jander,
	Jonathan Cameron

[-- Attachment #1: Type: text/plain, Size: 1708 bytes --]

Hello,

On Fri, Feb 18, 2022 at 08:42:51AM +0900, William Breathitt Gray wrote:
> On Thu, Feb 17, 2022 at 05:03:08PM +0100, Uwe Kleine-König wrote:
> > On Thu, Feb 17, 2022 at 04:48:50PM +0200, Jarkko Nikula wrote:
> > > On 2/8/22 03:42, William Breathitt Gray wrote:
> > > > 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.
> > >
> > > Perhaps late but I hit this same issue, patch here fixes it and I wanted to
> > > confirm it.
> > > 
> > > Tested-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
> > 
> > I wonder if this patch is scheduled for 5.17. Currently it's not even in
> > next ... :-\
> 
> I've got it in my tree. I'm sending a pull request for the Counter
> patches for 5.17 next week, so they should all be merged after that.

That's good. Still I think you could make live easier for your users to
find fixes if your tree was included in next. And in MAINTAINERS.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH] counter: Stop using dev_get_drvdata() to get the counter device
  2022-02-18  7:47           ` Uwe Kleine-König
@ 2022-02-18  9:11             ` William Breathitt Gray
  0 siblings, 0 replies; 9+ messages in thread
From: William Breathitt Gray @ 2022-02-18  9:11 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: linux-iio, Robin van der Gracht, linux-kernel, Oleksij Rempel,
	Jarkko Nikula, Pengutronix Kernel Team, David Jander,
	Jonathan Cameron

[-- Attachment #1: Type: text/plain, Size: 1969 bytes --]

On Fri, Feb 18, 2022 at 08:47:51AM +0100, Uwe Kleine-König wrote:
> Hello,
> 
> On Fri, Feb 18, 2022 at 08:42:51AM +0900, William Breathitt Gray wrote:
> > On Thu, Feb 17, 2022 at 05:03:08PM +0100, Uwe Kleine-König wrote:
> > > On Thu, Feb 17, 2022 at 04:48:50PM +0200, Jarkko Nikula wrote:
> > > > On 2/8/22 03:42, William Breathitt Gray wrote:
> > > > > 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.
> > > >
> > > > Perhaps late but I hit this same issue, patch here fixes it and I wanted to
> > > > confirm it.
> > > > 
> > > > Tested-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
> > > 
> > > I wonder if this patch is scheduled for 5.17. Currently it's not even in
> > > next ... :-\
> > 
> > I've got it in my tree. I'm sending a pull request for the Counter
> > patches for 5.17 next week, so they should all be merged after that.
> 
> That's good. Still I think you could make live easier for your users to
> find fixes if your tree was included in next. And in MAINTAINERS.
> 
> Best regards
> Uwe

That's a fair point, I'll update MAINTAINERS and set up my fixes branch
for inclusion in linux-next.

Incidentally, it looks like this is the only fix I have merged; I'll
submit it now by itself so we don't have to wait until next week.

Thanks,

William Breathitt Gray

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* [PATCH] counter: Stop using dev_get_drvdata() to get the counter device
@ 2022-02-18  9:20 William Breathitt Gray
  2022-02-18 10:07 ` Uwe Kleine-König
  0 siblings, 1 reply; 9+ messages in thread
From: William Breathitt Gray @ 2022-02-18  9:20 UTC (permalink / raw)
  To: gregkh
  Cc: linux-iio, Uwe Kleine-König, Oleksij Rempel, Jarkko Nikula,
	William Breathitt Gray

From: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

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>
Tested-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
---
 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: e6cb9c167eeb8f90ab924666c573e69e85e700a0
-- 
2.35.1


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

* Re: [PATCH] counter: Stop using dev_get_drvdata() to get the counter device
  2022-02-18  9:20 [PATCH] counter: Stop using dev_get_drvdata() to get the counter device William Breathitt Gray
@ 2022-02-18 10:07 ` Uwe Kleine-König
  0 siblings, 0 replies; 9+ messages in thread
From: Uwe Kleine-König @ 2022-02-18 10:07 UTC (permalink / raw)
  To: William Breathitt Gray; +Cc: gregkh, linux-iio, Oleksij Rempel, Jarkko Nikula

[-- Attachment #1: Type: text/plain, Size: 1034 bytes --]

Hello,

On Fri, Feb 18, 2022 at 06:20:31PM +0900, William Breathitt Gray wrote:
> From: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> 
> 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>
> Tested-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
> Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
> ---

William didn't tell explicitly, so in case there are doubts: This patch
is targeted for v5.17.

Thanks
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

end of thread, other threads:[~2022-02-18 10:07 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-18  9:20 [PATCH] counter: Stop using dev_get_drvdata() to get the counter device William Breathitt Gray
2022-02-18 10:07 ` Uwe Kleine-König
  -- strict thread matches above, loose matches on Subject: below --
2022-02-04  7:02 [PATCH v1] counter: fix NULL pointer dereference on counter_comp_u8_store() 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
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

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