2021-12-27 09:46:37

by Uwe Kleine-König

[permalink] [raw]
Subject: [PATCH v2 01/23] counter: Use container_of instead of drvdata to track counter_device

The counter core uses drvdata to find a struct counter_device from a
struct device. However as the device is a member of struct counter_device,
the lookup can be done faster (and a bit type safe) using container_of.

There are no other users of drvdata, so the call to dev_set_drvdata can
go away, too.

Signed-off-by: Uwe Kleine-König <[email protected]>
---
drivers/counter/counter-core.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/counter/counter-core.c b/drivers/counter/counter-core.c
index 5acc54539623..f053a43c6c04 100644
--- a/drivers/counter/counter-core.c
+++ b/drivers/counter/counter-core.c
@@ -26,7 +26,8 @@ static DEFINE_IDA(counter_ida);

static void counter_device_release(struct device *dev)
{
- struct counter_device *const counter = dev_get_drvdata(dev);
+ struct counter_device *const counter =
+ container_of(dev, struct counter_device, dev);

counter_chrdev_remove(counter);
ida_free(&counter_ida, dev->id);
@@ -78,7 +79,6 @@ int counter_register(struct counter_device *const counter)
dev->of_node = counter->parent->of_node;
}
device_initialize(dev);
- dev_set_drvdata(dev, counter);

err = counter_sysfs_add(counter);
if (err < 0)
--
2.33.0



2021-12-28 17:09:08

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH v2 01/23] counter: Use container_of instead of drvdata to track counter_device

On Mon, 27 Dec 2021 10:45:04 +0100
Uwe Kleine-König <[email protected]> wrote:

> The counter core uses drvdata to find a struct counter_device from a
> struct device. However as the device is a member of struct counter_device,
> the lookup can be done faster (and a bit type safe) using container_of.
>
> There are no other users of drvdata, so the call to dev_set_drvdata can
> go away, too.
>
> Signed-off-by: Uwe Kleine-König <[email protected]>
LGTM

Reviewed-by: Jonathan Cameron <[email protected]>

> ---
> drivers/counter/counter-core.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/counter/counter-core.c b/drivers/counter/counter-core.c
> index 5acc54539623..f053a43c6c04 100644
> --- a/drivers/counter/counter-core.c
> +++ b/drivers/counter/counter-core.c
> @@ -26,7 +26,8 @@ static DEFINE_IDA(counter_ida);
>
> static void counter_device_release(struct device *dev)
> {
> - struct counter_device *const counter = dev_get_drvdata(dev);
> + struct counter_device *const counter =
> + container_of(dev, struct counter_device, dev);
>
> counter_chrdev_remove(counter);
> ida_free(&counter_ida, dev->id);
> @@ -78,7 +79,6 @@ int counter_register(struct counter_device *const counter)
> dev->of_node = counter->parent->of_node;
> }
> device_initialize(dev);
> - dev_set_drvdata(dev, counter);
>
> err = counter_sysfs_add(counter);
> if (err < 0)


2021-12-29 06:39:00

by William Breathitt Gray

[permalink] [raw]
Subject: Re: [PATCH v2 01/23] counter: Use container_of instead of drvdata to track counter_device

On Mon, Dec 27, 2021 at 10:45:04AM +0100, Uwe Kleine-König wrote:
> The counter core uses drvdata to find a struct counter_device from a
> struct device. However as the device is a member of struct counter_device,
> the lookup can be done faster (and a bit type safe) using container_of.
>
> There are no other users of drvdata, so the call to dev_set_drvdata can
> go away, too.
>
> Signed-off-by: Uwe Kleine-König <[email protected]>

Acked-by: William Breathitt Gray <[email protected]>

> ---
> drivers/counter/counter-core.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/counter/counter-core.c b/drivers/counter/counter-core.c
> index 5acc54539623..f053a43c6c04 100644
> --- a/drivers/counter/counter-core.c
> +++ b/drivers/counter/counter-core.c
> @@ -26,7 +26,8 @@ static DEFINE_IDA(counter_ida);
>
> static void counter_device_release(struct device *dev)
> {
> - struct counter_device *const counter = dev_get_drvdata(dev);
> + struct counter_device *const counter =
> + container_of(dev, struct counter_device, dev);
>
> counter_chrdev_remove(counter);
> ida_free(&counter_ida, dev->id);
> @@ -78,7 +79,6 @@ int counter_register(struct counter_device *const counter)
> dev->of_node = counter->parent->of_node;
> }
> device_initialize(dev);
> - dev_set_drvdata(dev, counter);
>
> err = counter_sysfs_add(counter);
> if (err < 0)
> --
> 2.33.0
>


Attachments:
(No filename) (1.41 kB)
signature.asc (833.00 B)
Download all attachments