staging: iio: accel: Replace iio_device_register with devm_iio_device_register
Subsystems (3)
PATCH 1/1 staging: iio: accel: Replace iio_device_register with devm_iio_device_register
Devm_ functions allocate memory that is released when a driver detaches. Replace iio_device_register with the resource-managed version devm_iio_device_register. Subsequently, remove iio_device_unregister from probe and remove functions of this driver.
Also, an unnecessary label was dropped.
--- drivers/staging/iio/accel/sca3000_core.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/staging/iio/accel/sca3000_core.c +2 -5
@@ -1123,7 +1123,7 @@ static int sca3000_probe(struct spi_device *spi) indio_dev->modes =INDIO_DIRECT_MODE ;sca3000_configure_ring (indio_dev); - ret =iio_device_register (indio_dev); + ret =devm_iio_device_register (indio_dev->dev.parent, indio_dev);if (ret <0 )return ret;
@@ -1135,7 +1135,7 @@ static int sca3000_probe(struct spi_device *spi)"sca3000" , indio_dev);if (ret) - goto error_unregister_dev; +return ret; }sca3000_register_ring_funcs (indio_dev); ret =sca3000_clean_setup (st);
@@ -1146,8 +1146,6 @@ static int sca3000_probe(struct spi_device *spi) error_free_irq:if (spi->irq)free_irq (spi->irq, indio_dev); -error_unregister_dev: -iio_device_unregister (indio_dev);return ret; }
@@ -1178,7 +1176,6 @@ static int sca3000_remove(struct spi_device *spi)sca3000_stop_all_interrupts (st);if (spi->irq)free_irq (spi->irq, indio_dev); -iio_device_unregister (indio_dev);sca3000_unconfigure_ring (indio_dev);return 0 ;
Signature · 1 line
1.9.1
reordering remove actions in iio drivers
Hi Amitoj,
I just worked on a similar patch, and yours caught my attention. It's not clear that it is OK to reorder the .remove actions. Although it may seem counterintuitive to do anything *after* you've unregistered your device, it is indeed done purposely and safely in many iio drivers. It usually needs to stay that way.
Check out more discussions of this on linux-iio.
And, consider the source...I'm just trying to figure this stuff out too!
alisons
Re: [Outreachy kernel] reordering remove actions in iio drivers
Quoted 8 lines · Alison Schofield
Hi Amitoj,
I just worked on a similar patch, and yours caught my attention. It's not clear that it is OK to reorder the .remove actions. Although it may seem counterintuitive to do anything *after* you've unregistered your device, it is indeed done purposely and safely in many iio drivers. It usually needs to stay that way.
Quoted 4 lines
Check out more discussions of this on linux-iio.
And, consider the source...I'm just trying to figure this stuff out too!
Which patch of Amitoj's are you referring to (or which file), and if possible do you have a more specific link for the discussion on linux-iio?
thanks,
julia
Re: [Outreachy kernel] reordering remove actions in iio drivers
Quoted 12 lines · Julia Lawall
Quoted 10 lines · Alison Schofield
Hi Amitoj,
I just worked on a similar patch, and yours caught my attention. It's not clear that it is OK to reorder the .remove actions. Although it may seem counterintuitive to do anything *after* you've unregistered your device, it is indeed done purposely and safely in many iio drivers. It usually needs to stay that way.
Check out more discussions of this on linux-iio.
Quoted 8 lines
Quoted 2 lines
And, consider the source...I'm just trying to figure this stuff out too!
Which patch of Amitoj's are you referring to (or which file), and if possible do you have a more specific link for the discussion on linux-iio?
thanks,
julia
I'm seeing this threaded with original patch, but I guess you're not. It is in reference to:
[PATCH] staging: iio: accel: Replace iio_device_register with devm_iio_device_register
There is a lot of linux-iio discussion when this devm was originally introduced with 30+ patches to migrate. Search devm_iio_device_register
and another later on when an intern tried to apply it:
http://article.gmane.org/gmane.linux.kernel.iio/13354/match=devm_iio_register
The accel case might be ok...just a heads up on the considerations.
alisons
Re: [Outreachy kernel] reordering remove actions in iio drivers
Quoted 19 lines · Alison Schofield
Quoted 18 lines · Julia Lawall
Quoted 8 lines · Alison Schofield
Hi Amitoj,
I just worked on a similar patch, and yours caught my attention. It's not clear that it is OK to reorder the .remove actions. Although it may seem counterintuitive to do anything *after* you've unregistered your device, it is indeed done purposely and safely in many iio drivers. It usually needs to stay that way.
Quoted 4 lines
Check out more discussions of this on linux-iio.
And, consider the source...I'm just trying to figure this stuff out too!
Which patch of Amitoj's are you referring to (or which file), and if possible do you have a more specific link for the discussion on linux-iio?
Quoted 7 lines
Quoted 2 lines
thanks,
juliaI'm seeing this threaded with original patch, but I guess you're not. It is in reference to:
[PATCH] staging: iio: accel: Replaceiio_device_registerwithdevm_iio_device_register
Thanks for the pointer. Another question about this code is why there is no call to sca3000_unconfigure_ring in the probe function. It loos like there should be one under the unregister call, if it is useful to do so in the remove function.
julia
Quoted 12 lines
There is a lot of linux-iio discussion when this devm was originally introduced with 30+ patches to migrate. Search
devm_iio_device_registerand another later on when an intern tried to apply it:
http://article.gmane.org/gmane.linux.kernel.iio/13354/match=devm_iio_registerThe accel case might be ok...just a heads up on the considerations.
alisons
Re: [Outreachy kernel] reordering remove actions in iio drivers
In reply to Alison SchofieldQuoted 30 lines · Alison Schofield
Quoted 12 lines · Julia Lawall
Quoted 10 lines · Alison Schofield
Hi Amitoj,
I just worked on a similar patch, and yours caught my attention. It's not clear that it is OK to reorder the .remove actions. Although it may seem counterintuitive to do anything *after* you've unregistered your device, it is indeed done purposely and safely in many iio drivers. It usually needs to stay that way.
Check out more discussions of this on linux-iio.
Quoted 8 lines
Quoted 2 lines
And, consider the source...I'm just trying to figure this stuff out too!
Which patch of Amitoj's are you referring to (or which file), and if possible do you have a more specific link for the discussion on linux-iio?
thanks,
juliaI'm seeing this threaded with original patch, but I guess you're not. It is in reference to:
[PATCH] staging: iio: accel: Replaceiio_device_registerwithdevm_iio_device_registerThere is a lot of linux-iio discussion when this devm was originally introduced with 30+ patches to migrate. Search
devm_iio_device_register
Quoted 6 lines
and another later on when an intern tried to apply it:
http://article.gmane.org/gmane.linux.kernel.iio/13354/match=devm_iio_registerThe accel case might be ok...just a heads up on the considerations.
alisons
I did not know this, but after your heads up I did check previous such patches accepted for iio drivers and I believe you're right. Thanks for pointing it out. Will be careful about this in the future.
Thanks,
Amitoj
Quoted 9 lines · Amitoj Kaur Chawla
Devm_functions allocate memory that is released when a driver detaches. Replaceiio_device_registerwith the resource-managed versiondevm_iio_device_register. Subsequently, removeiio_device_unregisterfrom probe and remove functions of this driver.Also, an unnecessary label was dropped.
Signed-off-by Amitoj Kaur Chawla <[email protected]>---
This patch is incorrect and should be dropped.
Amitoj