Use devm_request_region
Subsystems (7)
v2 cover Use devm_request_region
By the time request_region is called in several GPIO drivers, a corresponding device structure has already been allocated. The devm_request_region function should be used to help simplify the cleanup code and reduce the possible points of failure.
Changes in v2:
- Remove unused extent member from 104-dio-48e, 104-idi-48, 104-idio-16, and ws16c48 respective private data structures
- Remove unused pdata pointer from sch311x_gpio_remove function
William Breathitt Gray (7):
gpio: 104-dio-48e: Use devm_request_region
gpio: 104-idi-48: Use devm_request_region
gpio: 104-idio-16: Use devm_request_region
gpio: amd8111: Use devm_request_region
gpio: ich: Use devm_request_region
gpio: sch311x: Use devm_request_region
gpio: ws16c48: Use devm_request_region
drivers/gpio/gpio-104-dio-48e.c | 25 +++++++------------- drivers/gpio/gpio-104-idi-48.c | 25 +++++++------------- drivers/gpio/gpio-104-idio-16.c | 25 +++++++------------- drivers/gpio/gpio-amd8111.c | 7 +++--- drivers/gpio/gpio-ich.c | 51 ++++++++--------------------------------- drivers/gpio/gpio-sch311x.c | 8 +++---- drivers/gpio/gpio-ws16c48.c | 25 +++++++------------- 7 files changed, 47 insertions(+), 119 deletions(-)
Signature · 1 line
2.4.10
PATCH v2 1/7 gpio: 104-dio-48e: Use devm_request_region
By the time request_region is called in the ACCES 104-DIO-48E GPIO driver, a corresponding device structure has already been allocated. The devm_request_region function should be used to help simplify the cleanup code and reduce the possible points of failure.
--- drivers/gpio/gpio-104-dio-48e.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-)
drivers/gpio/gpio-104-dio-48e.c +8 -17
@@ -40,7 +40,6 @@ MODULE_PARM_DESC(dio_48e_irq, "ACCES 104-DIO-48E interrupt line number");* @control: Control registers state * @lock: synchronization lock to prevent I/O race conditions * @base: base port address of the GPIO device -* @extent: extent of port address region of the GPIO device * @irq: Interrupt line number * @irq_mask: I/O bits affected by interrupts */
@@ -51,7 +50,6 @@ struct dio48e_gpio {unsigned char control[2 ];spinlock_t lock;unsigned base; -unsigned extent;unsigned irq;unsigned char irq_mask; };
@@ -310,11 +308,10 @@ static int __init dio48e_probe(struct platform_device *pdev)if (!dio48egpio)return -ENOMEM ; -if (!request_region (base, extent, name)) { -dev_err (dev,"Unable to lock %s port addresses (0x%X-0x%X)\n" , - name, base, base + extent); - err = -EBUSY ; - goto err_lock_io_port; +if (!devm_request_region (dev, base, extent, name)) { +dev_err (dev,"Unable to lock port addresses (0x%X-0x%X)\n" , + base, base + extent); +return -EBUSY ; } dio48egpio->chip.label = name;
@@ -328,7 +325,6 @@ static int __init dio48e_probe(struct platform_device *pdev) dio48egpio->chip.get = dio48e_gpio_get; dio48egpio->chip.set = dio48e_gpio_set; dio48egpio->base = base; - dio48egpio->extent = extent; dio48egpio->irq = irq;spin_lock_init (&dio48egpio->lock);
@@ -338,7 +334,7 @@ static int __init dio48e_probe(struct platform_device *pdev) err =gpiochip_add_data (&dio48egpio->chip, dio48egpio);if (err) {dev_err (dev,"GPIO registering failed (%d)\n" , err); - goto err_gpio_register; +return err; }/* initialize all GPIO as output */
@@ -360,23 +356,19 @@ static int __init dio48e_probe(struct platform_device *pdev) handle_edge_irq, IRQ_TYPE_NONE);if (err) {dev_err (dev,"Could not add irqchip (%d)\n" , err); - goto err_gpiochip_irqchip_add; + goto err_gpiochip_remove; } err =request_irq (irq, dio48e_irq_handler,0 , name, dio48egpio);if (err) {dev_err (dev,"IRQ handler registering failed (%d)\n" , err); - goto err_request_irq; + goto err_gpiochip_remove; }return 0 ; -err_request_irq: -err_gpiochip_irqchip_add: +err_gpiochip_remove:gpiochip_remove (&dio48egpio->chip); -err_gpio_register: -release_region (base, extent); -err_lock_io_port:return err; }
@@ -386,7 +378,6 @@ static int dio48e_remove(struct platform_device *pdev)free_irq (dio48egpio->irq, dio48egpio);gpiochip_remove (&dio48egpio->chip); -release_region (dio48egpio->base, dio48egpio->extent);return 0 ; }
Signature · 1 line
2.4.10
PATCH v2 2/7 gpio: 104-idi-48: Use devm_request_region
In reply to William Breathitt GrayBy the time request_region is called in the ACCES 104-IDI-48 GPIO driver, a corresponding device structure has already been allocated. The devm_request_region function should be used to help simplify the cleanup code and reduce the possible points of failure.
--- drivers/gpio/gpio-104-idi-48.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-)
drivers/gpio/gpio-104-idi-48.c +8 -17
@@ -39,7 +39,6 @@ MODULE_PARM_DESC(idi_48_irq, "ACCES 104-IDI-48 interrupt line number");* @ack_lock: synchronization lock to prevent IRQ handler race conditions * @irq_mask: input bits affected by interrupts * @base: base port address of the GPIO device -* @extent: extent of port address region of the GPIO device * @irq: Interrupt line number * @cos_enb: Change-Of-State IRQ enable boundaries mask */
@@ -49,7 +48,6 @@ struct idi_48_gpio {spinlock_t ack_lock;unsigned char irq_mask[6 ];unsigned base; -unsigned extent;unsigned irq;unsigned char cos_enb; };
@@ -227,11 +225,10 @@ static int __init idi_48_probe(struct platform_device *pdev)if (!idi48gpio)return -ENOMEM ; -if (!request_region (base, extent, name)) { -dev_err (dev,"Unable to lock %s port addresses (0x%X-0x%X)\n" , - name, base, base + extent); - err = -EBUSY ; - goto err_lock_io_port; +if (!devm_request_region (dev, base, extent, name)) { +dev_err (dev,"Unable to lock port addresses (0x%X-0x%X)\n" , + base, base + extent); +return -EBUSY ; } idi48gpio->chip.label = name;
@@ -243,7 +240,6 @@ static int __init idi_48_probe(struct platform_device *pdev) idi48gpio->chip.direction_input = idi_48_gpio_direction_input; idi48gpio->chip.get = idi_48_gpio_get; idi48gpio->base = base; - idi48gpio->extent = extent; idi48gpio->irq = irq;spin_lock_init (&idi48gpio->lock);
@@ -253,7 +249,7 @@ static int __init idi_48_probe(struct platform_device *pdev) err =gpiochip_add_data (&idi48gpio->chip, idi48gpio);if (err) {dev_err (dev,"GPIO registering failed (%d)\n" , err); - goto err_gpio_register; +return err; }/* Disable IRQ by default */
@@ -264,24 +260,20 @@ static int __init idi_48_probe(struct platform_device *pdev) handle_edge_irq, IRQ_TYPE_NONE);if (err) {dev_err (dev,"Could not add irqchip (%d)\n" , err); - goto err_gpiochip_irqchip_add; + goto err_gpiochip_remove; } err =request_irq (irq, idi_48_irq_handler,IRQF_SHARED , name, idi48gpio);if (err) {dev_err (dev,"IRQ handler registering failed (%d)\n" , err); - goto err_request_irq; + goto err_gpiochip_remove; }return 0 ; -err_request_irq: -err_gpiochip_irqchip_add: +err_gpiochip_remove:gpiochip_remove (&idi48gpio->chip); -err_gpio_register: -release_region (base, extent); -err_lock_io_port:return err; }
@@ -291,7 +283,6 @@ static int idi_48_remove(struct platform_device *pdev)free_irq (idi48gpio->irq, idi48gpio);gpiochip_remove (&idi48gpio->chip); -release_region (idi48gpio->base, idi48gpio->extent);return 0 ; }
Signature · 1 line
2.4.10
PATCH v2 3/7 gpio: 104-idio-16: Use devm_request_region
In reply to William Breathitt GrayBy the time request_region is called in the ACCES 104-IDIO-16 GPIO driver, a corresponding device structure has already been allocated. The devm_request_region function should be used to help simplify the cleanup code and reduce the possible points of failure.
--- drivers/gpio/gpio-104-idio-16.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-)
drivers/gpio/gpio-104-idio-16.c +8 -17
@@ -38,7 +38,6 @@ MODULE_PARM_DESC(idio_16_irq, "ACCES 104-IDIO-16 interrupt line number");* @lock: synchronization lock to prevent I/O race conditions * @irq_mask: I/O bits affected by interrupts * @base: base port address of the GPIO device -* @extent: extent of port address region of the GPIO device * @irq: Interrupt line number * @out_state: output bits state */
@@ -47,7 +46,6 @@ struct idio_16_gpio {spinlock_t lock;unsigned long irq_mask;unsigned base; -unsigned extent;unsigned irq;unsigned out_state; };
@@ -201,11 +199,10 @@ static int __init idio_16_probe(struct platform_device *pdev)if (!idio16gpio)return -ENOMEM ; -if (!request_region (base, extent, name)) { -dev_err (dev,"Unable to lock %s port addresses (0x%X-0x%X)\n" , - name, base, base + extent); - err = -EBUSY ; - goto err_lock_io_port; +if (!devm_request_region (dev, base, extent, name)) { +dev_err (dev,"Unable to lock port addresses (0x%X-0x%X)\n" , + base, base + extent); +return -EBUSY ; } idio16gpio->chip.label = name;
@@ -219,7 +216,6 @@ static int __init idio_16_probe(struct platform_device *pdev) idio16gpio->chip.get = idio_16_gpio_get; idio16gpio->chip.set = idio_16_gpio_set; idio16gpio->base = base; - idio16gpio->extent = extent; idio16gpio->irq = irq; idio16gpio->out_state =0xFFFF ;
@@ -230,7 +226,7 @@ static int __init idio_16_probe(struct platform_device *pdev) err =gpiochip_add_data (&idio16gpio->chip, idio16gpio);if (err) {dev_err (dev,"GPIO registering failed (%d)\n" , err); - goto err_gpio_register; +return err; }/* Disable IRQ by default */
@@ -241,23 +237,19 @@ static int __init idio_16_probe(struct platform_device *pdev) handle_edge_irq, IRQ_TYPE_NONE);if (err) {dev_err (dev,"Could not add irqchip (%d)\n" , err); - goto err_gpiochip_irqchip_add; + goto err_gpiochip_remove; } err =request_irq (irq, idio_16_irq_handler,0 , name, idio16gpio);if (err) {dev_err (dev,"IRQ handler registering failed (%d)\n" , err); - goto err_request_irq; + goto err_gpiochip_remove; }return 0 ; -err_request_irq: -err_gpiochip_irqchip_add: +err_gpiochip_remove:gpiochip_remove (&idio16gpio->chip); -err_gpio_register: -release_region (base, extent); -err_lock_io_port:return err; }
@@ -267,7 +259,6 @@ static int idio_16_remove(struct platform_device *pdev)free_irq (idio16gpio->irq, idio16gpio);gpiochip_remove (&idio16gpio->chip); -release_region (idio16gpio->base, idio16gpio->extent);return 0 ; }
Signature · 1 line
2.4.10
PATCH v2 4/7 gpio: amd8111: Use devm_request_region
In reply to William Breathitt GrayBy the time request_region is called in the AMD 8111 GPIO driver, a corresponding device structure has already been allocated. The devm_request_region function should be used to help simplify the cleanup code and reduce the possible points of failure.
--- drivers/gpio/gpio-amd8111.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/gpio/gpio-amd8111.c +3 -4
@@ -25,6 +25,7 @@* License version 2. This program is licensed "as is" without any * warranty of any kind, whether express or implied. */ +#include <linux/ioport.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/gpio.h>
@@ -204,7 +205,8 @@ found: gp.pmbase &=0x0000FF00 ;if (gp.pmbase ==0 ) goto out; -if (!request_region (gp.pmbase +PMBASE_OFFSET ,PMBASE_SIZE ,"AMD GPIO" )) { +if (!devm_request_region (&pdev->dev, gp.pmbase +PMBASE_OFFSET , +PMBASE_SIZE ,"AMD GPIO" )) {dev_err (&pdev->dev,"AMD GPIO region 0x%x already in use!\n" , gp.pmbase +PMBASE_OFFSET ); err = -EBUSY ;
@@ -213,7 +215,6 @@ found: gp.pm =ioport_map (gp.pmbase +PMBASE_OFFSET ,PMBASE_SIZE );if (!gp.pm) {dev_err (&pdev->dev,"Couldn't map io port into io memory\n" ); -release_region (gp.pmbase +PMBASE_OFFSET ,PMBASE_SIZE ); err = -ENOMEM ; goto out; }
@@ -228,7 +229,6 @@ found:printk (KERN_ERR "GPIO registering failed (%d)\n" , err);ioport_unmap (gp.pm); -release_region (gp.pmbase +PMBASE_OFFSET ,PMBASE_SIZE ); goto out; } out:
@@ -239,7 +239,6 @@ static void __exit amd_gpio_exit(void) {gpiochip_remove (&gp.chip);ioport_unmap (gp.pm); -release_region (gp.pmbase +PMBASE_OFFSET ,PMBASE_SIZE ); }module_init (amd_gpio_init);
Signature · 1 line
2.4.10
PATCH v2 5/7 gpio: ich: Use devm_request_region
In reply to William Breathitt GrayBy the time request_region is called in the Intel ICH series GPIO driver, a corresponding device structure has already been allocated. The devm_request_region function should be used to help simplify the cleanup code and reduce the possible points of failure.
--- drivers/gpio/gpio-ich.c | 51 +++++++++---------------------------------------- 1 file changed, 9 insertions(+), 42 deletions(-)
drivers/gpio/gpio-ich.c +9 -42
@@ -20,6 +20,7 @@#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt +#include <linux/ioport.h> #include <linux/module.h> #include <linux/pci.h> #include <linux/gpio.h>
@@ -384,8 +385,8 @@ static struct ichx_desc avoton_desc = { .use_outlvl_cache = true, }; -static int ichx_gpio_request_regions (struct resource *res_base, -const char *name,u8 use_gpio) +static int ichx_gpio_request_regions (struct device *dev, +struct resource *res_base,const char *name,u8 use_gpio) {int i;
@@ -395,34 +396,12 @@ static int ichx_gpio_request_regions(struct resource *res_base,for (i =0 ; i <ARRAY_SIZE (ichx_priv.desc->regs[0 ]); i++) {if (!(use_gpio & (1 << i)))continue ; -if (!request_region ( +if (!devm_request_region (dev, res_base->start + ichx_priv.desc->regs[0 ][i], ichx_priv.desc->reglen[i], name)) - goto request_err; +return -EBUSY ; }return 0 ; - -request_err: -/* Clean up: release already requested regions, if any */ -for (i--; i >=0 ; i--) { -if (!(use_gpio & (1 << i))) -continue ; -release_region (res_base->start + ichx_priv.desc->regs[0 ][i], - ichx_priv.desc->reglen[i]); - } -return -EBUSY ; -} - -static void ichx_gpio_release_regions (struct resource *res_base,u8 use_gpio) -{ -int i; - -for (i =0 ; i <ARRAY_SIZE (ichx_priv.desc->regs[0 ]); i++) { -if (!(use_gpio & (1 << i))) -continue ; -release_region (res_base->start + ichx_priv.desc->regs[0 ][i], - ichx_priv.desc->reglen[i]); - } }static int ichx_gpio_probe (struct platform_device *pdev)
@@ -468,7 +447,7 @@ static int ichx_gpio_probe(struct platform_device *pdev)spin_lock_init (&ichx_priv.lock); res_base =platform_get_resource (pdev,IORESOURCE_IO ,ICH_RES_GPIO ); ichx_priv.use_gpio = ich_info->use_gpio; - err =ichx_gpio_request_regions (res_base, pdev->name, + err =ichx_gpio_request_regions (&pdev->dev, res_base, pdev->name, ichx_priv.use_gpio);if (err)return err;
@@ -489,8 +468,8 @@ static int ichx_gpio_probe(struct platform_device *pdev) goto init; } -if (!request_region (res_pm->start,resource_size (res_pm), - pdev->name)) { +if (!devm_request_region (&pdev->dev, res_pm->start, +resource_size (res_pm), pdev->name)) {pr_warn ("ACPI BAR is busy, GPI 0 - 15 unavailable\n" ); goto init; }
@@ -502,31 +481,19 @@ init: err =gpiochip_add_data (&ichx_priv.chip,NULL );if (err) {pr_err ("Failed to register GPIOs\n" ); - goto add_err; +return err; }pr_info ("GPIO from %d to %d on %s\n" , ichx_priv.chip.base, ichx_priv.chip.base + ichx_priv.chip.ngpio -1 ,DRV_NAME );return 0 ; - -add_err: -ichx_gpio_release_regions (ichx_priv.gpio_base, ichx_priv.use_gpio); -if (ichx_priv.pm_base) -release_region (ichx_priv.pm_base->start, -resource_size (ichx_priv.pm_base)); -return err; }static int ichx_gpio_remove (struct platform_device *pdev) {gpiochip_remove (&ichx_priv.chip); -ichx_gpio_release_regions (ichx_priv.gpio_base, ichx_priv.use_gpio); -if (ichx_priv.pm_base) -release_region (ichx_priv.pm_base->start, -resource_size (ichx_priv.pm_base)); -return 0 ; }
Signature · 1 line
2.4.10
PATCH v2 6/7 gpio: sch311x: Use devm_request_region
In reply to William Breathitt GrayBy the time request_region is called in the SMSC SCH311x GPIO driver, a corresponding device structure has already been allocated. The devm_request_region function should be used to help simplify the cleanup code and reduce the possible points of failure.
--- drivers/gpio/gpio-sch311x.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/gpio/gpio-sch311x.c +3 -5
@@ -12,6 +12,7 @@* (at your option) any later version. */ +#include <linux/ioport.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/init.h>
@@ -228,7 +229,8 @@ static int sch311x_gpio_probe(struct platform_device *pdev)int err, i;/* we can register all GPIO data registers at once */ -if (!request_region (pdata->runtime_reg +GP1 ,6 ,DRV_NAME )) { +if (!devm_request_region (&pdev->dev, pdata->runtime_reg +GP1 ,6 , +DRV_NAME )) {dev_err (&pdev->dev,"Failed to request region 0x%04x-0x%04x.\n" , pdata->runtime_reg +GP1 , pdata->runtime_reg +GP1 +5 );return -EBUSY ;
@@ -273,7 +275,6 @@ static int sch311x_gpio_probe(struct platform_device *pdev)return 0 ; exit_err: -release_region (pdata->runtime_reg +GP1 ,6 );/* release already registered chips */ for (--i; i >=0 ; i--)gpiochip_remove (&priv->blocks[i].chip);
@@ -282,12 +283,9 @@ exit_err:static int sch311x_gpio_remove (struct platform_device *pdev) { -struct sch311x_pdev_data *pdata =dev_get_platdata (&pdev->dev);struct sch311x_gpio_priv *priv =platform_get_drvdata (pdev);int i; -release_region (pdata->runtime_reg +GP1 ,6 ); -for (i =0 ; i <ARRAY_SIZE (priv->blocks); i++) {gpiochip_remove (&priv->blocks[i].chip); dev_info(&pdev->dev,
Signature · 1 line
2.4.10
PATCH v2 7/7 gpio: ws16c48: Use devm_request_region
In reply to William Breathitt GrayBy the time request_region is called in the WinSystems WS16C48 GPIO driver, a corresponding device structure has already been allocated. The devm_request_region function should be used to help simplify the cleanup code and reduce the possible points of failure.
--- drivers/gpio/gpio-ws16c48.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-)
drivers/gpio/gpio-ws16c48.c +8 -17
@@ -41,7 +41,6 @@ MODULE_PARM_DESC(ws16c48_irq, "WinSystems WS16C48 interrupt line number");* @irq_mask: I/O bits affected by interrupts * @flow_mask: IRQ flow type mask for the respective I/O bits * @base: base port address of the GPIO device -* @extent: extent of port address region of the GPIO device * @irq: Interrupt line number */ struct ws16c48_gpio {
@@ -52,7 +51,6 @@ struct ws16c48_gpio {unsigned long irq_mask;unsigned long flow_mask;unsigned base; -unsigned extent;unsigned irq; };
@@ -314,11 +312,10 @@ static int __init ws16c48_probe(struct platform_device *pdev)if (!ws16c48gpio)return -ENOMEM ; -if (!request_region (base, extent, name)) { -dev_err (dev,"Unable to lock %s port addresses (0x%X-0x%X)\n" , - name, base, base + extent); - err = -EBUSY ; - goto err_lock_io_port; +if (!devm_request_region (dev, base, extent, name)) { +dev_err (dev,"Unable to lock port addresses (0x%X-0x%X)\n" , + base, base + extent); +return -EBUSY ; } ws16c48gpio->chip.label = name;
@@ -332,7 +329,6 @@ static int __init ws16c48_probe(struct platform_device *pdev) ws16c48gpio->chip.get = ws16c48_gpio_get; ws16c48gpio->chip.set = ws16c48_gpio_set; ws16c48gpio->base = base; - ws16c48gpio->extent = extent; ws16c48gpio->irq = irq;spin_lock_init (&ws16c48gpio->lock);
@@ -342,7 +338,7 @@ static int __init ws16c48_probe(struct platform_device *pdev) err =gpiochip_add_data (&ws16c48gpio->chip, ws16c48gpio);if (err) {dev_err (dev,"GPIO registering failed (%d)\n" , err); - goto err_gpio_register; +return err; }/* Disable IRQ by default */
@@ -356,24 +352,20 @@ static int __init ws16c48_probe(struct platform_device *pdev) handle_edge_irq, IRQ_TYPE_NONE);if (err) {dev_err (dev,"Could not add irqchip (%d)\n" , err); - goto err_gpiochip_irqchip_add; + goto err_gpiochip_remove; } err =request_irq (irq, ws16c48_irq_handler,IRQF_SHARED , name, ws16c48gpio);if (err) {dev_err (dev,"IRQ handler registering failed (%d)\n" , err); - goto err_request_irq; + goto err_gpiochip_remove; }return 0 ; -err_request_irq: -err_gpiochip_irqchip_add: +err_gpiochip_remove:gpiochip_remove (&ws16c48gpio->chip); -err_gpio_register: -release_region (base, extent); -err_lock_io_port:return err; }
@@ -383,7 +375,6 @@ static int ws16c48_remove(struct platform_device *pdev)free_irq (ws16c48gpio->irq, ws16c48gpio);gpiochip_remove (&ws16c48gpio->chip); -release_region (ws16c48gpio->base, ws16c48gpio->extent);return 0 ; }
Signature · 1 line
2.4.10
Quoted 9 lines · William Breathitt Gray
By the time
request_regionis called in several GPIO drivers, a corresponding device structure has already been allocated. Thedevm_request_regionfunction should be used to help simplify the cleanup code and reduce the possible points of failure.Changes in v2:
- Remove unused extent member from 104-dio-48e, 104-idi-48, 104-idio-16, and ws16c48 respective private data structures
- Remove unused pdata pointer fromsch311x_gpio_removefunction
All 7 patches applied.
Yours,
Linus Walleij