Skip to contentSkip to conversation

iio: stx104: Utilize devm_ functions in driver probe callback

PATCH In review William Breathitt Gray 2 participants 2 messages Jan 24, 2017 – Jan 28, 2017 IIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: stx104: Utilize devm_ functions in driver probe callback

The devm_ resource manager functions allow memory to be automatically released when a device is unbound. This patch takes advantage of the resource manager functions and replaces the gpiochip_add_data call and iio_device_register call with the devm_gpiochip_add_data call and devm_iio_device_register call respectively. In addition, the stx104_remove function has been removed as no longer necessary due to the use of the relevant devm_ resource manager functions.

---
 drivers/iio/adc/stx104.c | 22 ++--------------------
 1 file changed, 2 insertions(+), 20 deletions(-)
drivers/iio/adc/stx104.c +2 -20
index 7e3645749eaf..c56ff286695d 100644
@@ -339,30 +339,13 @@ static int stx104_probe(struct device *dev, unsigned int id)
 	stx104dev->chip = &stx104gpio->chip;
 	dev_set_drvdata(dev, stx104dev);
 
-	err = gpiochip_add_data(&stx104gpio->chip, stx104gpio);
+	err = devm_gpiochip_add_data(dev, &stx104gpio->chip, stx104gpio);
 	if (err) {
 		dev_err(dev, "GPIO registering failed (%d)\n", err);
 		return err;
 	}
 
-	err = iio_device_register(indio_dev);
-	if (err) {
-		dev_err(dev, "IIO device registering failed (%d)\n", err);
-		gpiochip_remove(&stx104gpio->chip);
-		return err;
-	}
-
-	return 0;
-}
-
-static int stx104_remove(struct device *dev, unsigned int id)
-{
-	struct stx104_dev *const stx104dev = dev_get_drvdata(dev);
-
-	iio_device_unregister(stx104dev->indio_dev);
-	gpiochip_remove(stx104dev->chip);
-
-	return 0;
+	return devm_iio_device_register(dev, indio_dev);
 }
 
 static struct isa_driver stx104_driver = {
@@ -370,7 +353,6 @@ static struct isa_driver stx104_driver = {
 	.driver = {
 		.name = "stx104"
 	},
-	.remove = stx104_remove
 };
 
 module_isa_driver(stx104_driver, num_stx104);
Signature · 1 line
2.11.0
maintainer
#1 lore raw
Quoted 9 lines · William Breathitt Gray

The devm_ resource manager functions allow memory to be automatically released when a device is unbound. This patch takes advantage of the resource manager functions and replaces the gpiochip_add_data call and iio_device_register call with the devm_gpiochip_add_data call and devm_iio_device_register call respectively. In addition, the stx104_remove function has been removed as no longer necessary due to the use of the relevant devm_ resource manager functions.

Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to play with it.

Thanks,

Jonathan

Quoted 50 lines
---
 drivers/iio/adc/stx104.c | 22 ++--------------------
 1 file changed, 2 insertions(+), 20 deletions(-)
drivers/iio/adc/stx104.c +2 -20
index 7e3645749eaf..c56ff286695d 100644
@@ -339,30 +339,13 @@ static int stx104_probe(struct device *dev, unsigned int id)
 	stx104dev->chip = &stx104gpio->chip;
 	dev_set_drvdata(dev, stx104dev);
 
-	err = gpiochip_add_data(&stx104gpio->chip, stx104gpio);
+	err = devm_gpiochip_add_data(dev, &stx104gpio->chip, stx104gpio);
 	if (err) {
 		dev_err(dev, "GPIO registering failed (%d)\n", err);
 		return err;
 	}
 
-	err = iio_device_register(indio_dev);
-	if (err) {
-		dev_err(dev, "IIO device registering failed (%d)\n", err);
-		gpiochip_remove(&stx104gpio->chip);
-		return err;
-	}
-
-	return 0;
-}
-
-static int stx104_remove(struct device *dev, unsigned int id)
-{
-	struct stx104_dev *const stx104dev = dev_get_drvdata(dev);
-
-	iio_device_unregister(stx104dev->indio_dev);
-	gpiochip_remove(stx104dev->chip);
-
-	return 0;
+	return devm_iio_device_register(dev, indio_dev);
 }
 
 static struct isa_driver stx104_driver = {
@@ -370,7 +353,6 @@ static struct isa_driver stx104_driver = {
 	.driver = {
 		.name = "stx104"
 	},
-	.remove = stx104_remove
 };
 
 module_isa_driver(stx104_driver, num_stx104);