* [PATCH] iio: iio_device_alloc(): Remove unnecessary self drvdata
@ 2021-12-05 12:50 Lars-Peter Clausen
2021-12-16 11:44 ` Jonathan Cameron
0 siblings, 1 reply; 2+ messages in thread
From: Lars-Peter Clausen @ 2021-12-05 12:50 UTC (permalink / raw)
To: Jonathan Cameron; +Cc: linux-iio, Lars-Peter Clausen
Drvdata is typically used by drivers to attach driver specific data to a
device. It is used to retrieve driver specific information when only the
device to which the data is attached is available.
In the IIO core in the `iio_device_alloc()` function we call
`iio_device_set_drvdata(indio_dev, indio_dev)`. This sets the drvdata of
the IIO device to itself.
This is rather unnecessary since if we have a pointer to the IIO device to
call `iio_device_get_drvdata()` on it we don't need to call the function
since we already have the pointer. If we only have a pointer to the `struct
device` we can use `dev_to_iio_dev()` to get the IIO device from it.
Furthermore the drvdata is supposed to be reserved for drivers, so it
should not be used by the IIO core in the first place.
The `set_drvdata()` has been around from the very beginning of the IIO
framework and back then it was used in the IIO device sysfs attribute
handling code. But that was subsequently replaced with a `dev_to_iio_dev()`
in commit e53f5ac52ec1 ("iio: Use dev_to_iio_dev()") and other cleanups.
The self `set_drvdata()` is now no longer needed and can be removed.
Verified that there no longer any users by checking for potential users
using the following two coccinelle scripts and reviewing that none of the
matches are problematic code.
<smpl>
@@
struct iio_dev *iio_dev;
expression dev;
identifier fn !~ "(remove|resume|suspend)";
@@
fn(...)
{
...
*iio_dev = dev_get_drvdata(dev)
...
}
</smpl>
<smpl>
@r1@
position p;
struct iio_dev *indio_dev;
identifier dev_fn =~ "^dev_";
identifier devm_fn =~ "^devm_";
@@
(
dev_fn
|
devm_fn
)
(&indio_dev@p->dev, ...)
@@
struct iio_dev *indio_dev;
position p != r1.p;
@@
*&indio_dev@p->dev</smpl>
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
drivers/iio/industrialio-core.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index 20d5178ca073..409c278a4c2c 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -1656,7 +1656,6 @@ struct iio_dev *iio_device_alloc(struct device *parent, int sizeof_priv)
indio_dev->dev.type = &iio_device_type;
indio_dev->dev.bus = &iio_bus_type;
device_initialize(&indio_dev->dev);
- iio_device_set_drvdata(indio_dev, (void *)indio_dev);
mutex_init(&indio_dev->mlock);
mutex_init(&iio_dev_opaque->info_exist_lock);
INIT_LIST_HEAD(&iio_dev_opaque->channel_attr_list);
--
2.30.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] iio: iio_device_alloc(): Remove unnecessary self drvdata
2021-12-05 12:50 [PATCH] iio: iio_device_alloc(): Remove unnecessary self drvdata Lars-Peter Clausen
@ 2021-12-16 11:44 ` Jonathan Cameron
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2021-12-16 11:44 UTC (permalink / raw)
To: Lars-Peter Clausen; +Cc: linux-iio
On Sun, 5 Dec 2021 13:50:52 +0100
Lars-Peter Clausen <lars@metafoo.de> wrote:
> Drvdata is typically used by drivers to attach driver specific data to a
> device. It is used to retrieve driver specific information when only the
> device to which the data is attached is available.
>
> In the IIO core in the `iio_device_alloc()` function we call
> `iio_device_set_drvdata(indio_dev, indio_dev)`. This sets the drvdata of
> the IIO device to itself.
>
> This is rather unnecessary since if we have a pointer to the IIO device to
> call `iio_device_get_drvdata()` on it we don't need to call the function
> since we already have the pointer. If we only have a pointer to the `struct
> device` we can use `dev_to_iio_dev()` to get the IIO device from it.
>
> Furthermore the drvdata is supposed to be reserved for drivers, so it
> should not be used by the IIO core in the first place.
>
> The `set_drvdata()` has been around from the very beginning of the IIO
> framework and back then it was used in the IIO device sysfs attribute
> handling code. But that was subsequently replaced with a `dev_to_iio_dev()`
> in commit e53f5ac52ec1 ("iio: Use dev_to_iio_dev()") and other cleanups.
>
> The self `set_drvdata()` is now no longer needed and can be removed.
>
> Verified that there no longer any users by checking for potential users
> using the following two coccinelle scripts and reviewing that none of the
> matches are problematic code.
>
> <smpl>
> @@
> struct iio_dev *iio_dev;
> expression dev;
> identifier fn !~ "(remove|resume|suspend)";
> @@
> fn(...)
> {
> ...
> *iio_dev = dev_get_drvdata(dev)
> ...
> }
> </smpl>
>
> <smpl>
> @r1@
> position p;
> struct iio_dev *indio_dev;
> identifier dev_fn =~ "^dev_";
> identifier devm_fn =~ "^devm_";
> @@
> (
> dev_fn
> |
> devm_fn
> )
> (&indio_dev@p->dev, ...)
>
> @@
> struct iio_dev *indio_dev;
> position p != r1.p;
> @@
> *&indio_dev@p->dev</smpl>
>
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Applied to the togreg branch of iio.git and pushed out as testing for 0-day
to poke it.
Thanks,
Jonathan
> ---
> drivers/iio/industrialio-core.c | 1 -
> 1 file changed, 1 deletion(-)
>
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index 20d5178ca073..409c278a4c2c 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -1656,7 +1656,6 @@ struct iio_dev *iio_device_alloc(struct device *parent, int sizeof_priv)
> indio_dev->dev.type = &iio_device_type;
> indio_dev->dev.bus = &iio_bus_type;
> device_initialize(&indio_dev->dev);
> - iio_device_set_drvdata(indio_dev, (void *)indio_dev);
> mutex_init(&indio_dev->mlock);
> mutex_init(&iio_dev_opaque->info_exist_lock);
> INIT_LIST_HEAD(&iio_dev_opaque->channel_attr_list);
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-12-16 11:39 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-12-05 12:50 [PATCH] iio: iio_device_alloc(): Remove unnecessary self drvdata Lars-Peter Clausen
2021-12-16 11:44 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).