]> git.baikalelectronics.ru Git - kernel.git/commitdiff
counter: Stop using dev_get_drvdata() to get the counter device
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Fri, 11 Mar 2022 00:18:09 +0000 (19:18 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 15 Mar 2022 18:24:13 +0000 (19:24 +0100)
dev_get_drvdata() returns NULL since commit fb79586fb982 ("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: fb79586fb982 ("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>
Link: https://lore.kernel.org/all/20220204082556.370348-1-u.kleine-koenig@pengutronix.de/
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Link: https://lore.kernel.org/r/4a14311a3b935b62b33e665a97ecaaf2f078228a.1646957732.git.vilhelm.gray@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/counter/counter-sysfs.c

index 7cc4d1d523ea48697a9c0834d8a2221b98cd21f7..04eac41dad33e9227647cbd54a28cdf2468a67f7 100644 (file)
 
 #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;