Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

gpio: ich: Use devm_request_region

By 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.

Cc: Peter Tyser <ptyser@xes-inc.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

William Breathitt Gray and committed by
Linus Walleij
8a06b08e 35568c40

+9 -42
+9 -42
drivers/gpio/gpio-ich.c
··· 20 20 21 21 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 22 22 23 + #include <linux/ioport.h> 23 24 #include <linux/module.h> 24 25 #include <linux/pci.h> 25 26 #include <linux/gpio.h> ··· 385 384 .use_outlvl_cache = true, 386 385 }; 387 386 388 - static int ichx_gpio_request_regions(struct resource *res_base, 389 - const char *name, u8 use_gpio) 387 + static int ichx_gpio_request_regions(struct device *dev, 388 + struct resource *res_base, const char *name, u8 use_gpio) 390 389 { 391 390 int i; 392 391 ··· 396 395 for (i = 0; i < ARRAY_SIZE(ichx_priv.desc->regs[0]); i++) { 397 396 if (!(use_gpio & (1 << i))) 398 397 continue; 399 - if (!request_region( 398 + if (!devm_request_region(dev, 400 399 res_base->start + ichx_priv.desc->regs[0][i], 401 400 ichx_priv.desc->reglen[i], name)) 402 - goto request_err; 401 + return -EBUSY; 403 402 } 404 403 return 0; 405 - 406 - request_err: 407 - /* Clean up: release already requested regions, if any */ 408 - for (i--; i >= 0; i--) { 409 - if (!(use_gpio & (1 << i))) 410 - continue; 411 - release_region(res_base->start + ichx_priv.desc->regs[0][i], 412 - ichx_priv.desc->reglen[i]); 413 - } 414 - return -EBUSY; 415 - } 416 - 417 - static void ichx_gpio_release_regions(struct resource *res_base, u8 use_gpio) 418 - { 419 - int i; 420 - 421 - for (i = 0; i < ARRAY_SIZE(ichx_priv.desc->regs[0]); i++) { 422 - if (!(use_gpio & (1 << i))) 423 - continue; 424 - release_region(res_base->start + ichx_priv.desc->regs[0][i], 425 - ichx_priv.desc->reglen[i]); 426 - } 427 404 } 428 405 429 406 static int ichx_gpio_probe(struct platform_device *pdev) ··· 447 468 spin_lock_init(&ichx_priv.lock); 448 469 res_base = platform_get_resource(pdev, IORESOURCE_IO, ICH_RES_GPIO); 449 470 ichx_priv.use_gpio = ich_info->use_gpio; 450 - err = ichx_gpio_request_regions(res_base, pdev->name, 471 + err = ichx_gpio_request_regions(&pdev->dev, res_base, pdev->name, 451 472 ichx_priv.use_gpio); 452 473 if (err) 453 474 return err; ··· 468 489 goto init; 469 490 } 470 491 471 - if (!request_region(res_pm->start, resource_size(res_pm), 472 - pdev->name)) { 492 + if (!devm_request_region(&pdev->dev, res_pm->start, 493 + resource_size(res_pm), pdev->name)) { 473 494 pr_warn("ACPI BAR is busy, GPI 0 - 15 unavailable\n"); 474 495 goto init; 475 496 } ··· 481 502 err = gpiochip_add_data(&ichx_priv.chip, NULL); 482 503 if (err) { 483 504 pr_err("Failed to register GPIOs\n"); 484 - goto add_err; 505 + return err; 485 506 } 486 507 487 508 pr_info("GPIO from %d to %d on %s\n", ichx_priv.chip.base, 488 509 ichx_priv.chip.base + ichx_priv.chip.ngpio - 1, DRV_NAME); 489 510 490 511 return 0; 491 - 492 - add_err: 493 - ichx_gpio_release_regions(ichx_priv.gpio_base, ichx_priv.use_gpio); 494 - if (ichx_priv.pm_base) 495 - release_region(ichx_priv.pm_base->start, 496 - resource_size(ichx_priv.pm_base)); 497 - return err; 498 512 } 499 513 500 514 static int ichx_gpio_remove(struct platform_device *pdev) 501 515 { 502 516 gpiochip_remove(&ichx_priv.chip); 503 - 504 - ichx_gpio_release_regions(ichx_priv.gpio_base, ichx_priv.use_gpio); 505 - if (ichx_priv.pm_base) 506 - release_region(ichx_priv.pm_base->start, 507 - resource_size(ichx_priv.pm_base)); 508 517 509 518 return 0; 510 519 }