Skip to contentSkip to conversation

staging: iio: accel: Replace iio_device_register with devm_iio_device_register

PATCH In review Amitoj Kaur Chawla 3 participants 7 messages Feb 22, 2016 – Feb 29, 2016

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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
index a8f533a..f7dd359 100644
@@ -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
#1 lore raw

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

#2 lore raw

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

#3 lore raw

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

#4 lore raw

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

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

#5 lore raw

Re: [Outreachy kernel] reordering remove actions in iio drivers

In reply to Alison Schofield
Quoted 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,
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

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_register

The 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

#6 lore raw
In reply to Amitoj Kaur Chawla
Quoted 9 lines · Amitoj Kaur Chawla

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.

---

This patch is incorrect and should be dropped.

Amitoj