diff options
| author | Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com> | 2012-12-15 17:50:48 -0500 |
|---|---|---|
| committer | Simon Horman <horms+renesas@verge.net.au> | 2013-01-24 19:24:21 -0500 |
| commit | 1724acfd598bdf688218bdd26a5f02dd55b6ec62 (patch) | |
| tree | de92bd2a54456da3df5bc9a4f082f025447fe4fa /drivers/sh | |
| parent | c6193eacda6d50c405b0d484f5f2577ff9068a13 (diff) | |
sh-pfc: Use devm_kzalloc()
Replace probe-time kmalloc()/kzalloc() calls with devm_kzalloc() and get
rid of the corresponding kfree() calls.
Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Simon Horman <horms+renesas@verge.net.au>
Diffstat (limited to 'drivers/sh')
| -rw-r--r-- | drivers/sh/pfc/core.c | 20 | ||||
| -rw-r--r-- | drivers/sh/pfc/gpio.c | 8 | ||||
| -rw-r--r-- | drivers/sh/pfc/pinctrl.c | 31 |
3 files changed, 19 insertions, 40 deletions
diff --git a/drivers/sh/pfc/core.c b/drivers/sh/pfc/core.c index 6d162e694e68..54919026ac12 100644 --- a/drivers/sh/pfc/core.c +++ b/drivers/sh/pfc/core.c | |||
| @@ -33,9 +33,6 @@ static void pfc_iounmap(struct sh_pfc *pfc) | |||
| 33 | for (k = 0; k < pfc->pdata->num_resources; k++) | 33 | for (k = 0; k < pfc->pdata->num_resources; k++) |
| 34 | if (pfc->window[k].virt) | 34 | if (pfc->window[k].virt) |
| 35 | iounmap(pfc->window[k].virt); | 35 | iounmap(pfc->window[k].virt); |
| 36 | |||
| 37 | kfree(pfc->window); | ||
| 38 | pfc->window = NULL; | ||
| 39 | } | 36 | } |
| 40 | 37 | ||
| 41 | static int pfc_ioremap(struct sh_pfc *pfc) | 38 | static int pfc_ioremap(struct sh_pfc *pfc) |
| @@ -46,10 +43,10 @@ static int pfc_ioremap(struct sh_pfc *pfc) | |||
| 46 | if (!pfc->pdata->num_resources) | 43 | if (!pfc->pdata->num_resources) |
| 47 | return 0; | 44 | return 0; |
| 48 | 45 | ||
| 49 | pfc->window = kzalloc(pfc->pdata->num_resources * sizeof(*pfc->window), | 46 | pfc->window = devm_kzalloc(pfc->dev, pfc->pdata->num_resources * |
| 50 | GFP_NOWAIT); | 47 | sizeof(*pfc->window), GFP_NOWAIT); |
| 51 | if (!pfc->window) | 48 | if (!pfc->window) |
| 52 | goto err1; | 49 | return -ENOMEM; |
| 53 | 50 | ||
| 54 | for (k = 0; k < pfc->pdata->num_resources; k++) { | 51 | for (k = 0; k < pfc->pdata->num_resources; k++) { |
| 55 | res = pfc->pdata->resource + k; | 52 | res = pfc->pdata->resource + k; |
| @@ -58,16 +55,13 @@ static int pfc_ioremap(struct sh_pfc *pfc) | |||
| 58 | pfc->window[k].size = resource_size(res); | 55 | pfc->window[k].size = resource_size(res); |
| 59 | pfc->window[k].virt = ioremap_nocache(res->start, | 56 | pfc->window[k].virt = ioremap_nocache(res->start, |
| 60 | resource_size(res)); | 57 | resource_size(res)); |
| 61 | if (!pfc->window[k].virt) | 58 | if (!pfc->window[k].virt) { |
| 62 | goto err2; | 59 | pfc_iounmap(pfc); |
| 60 | return -ENOMEM; | ||
| 61 | } | ||
| 63 | } | 62 | } |
| 64 | 63 | ||
| 65 | return 0; | 64 | return 0; |
| 66 | |||
| 67 | err2: | ||
| 68 | pfc_iounmap(pfc); | ||
| 69 | err1: | ||
| 70 | return -1; | ||
| 71 | } | 65 | } |
| 72 | 66 | ||
| 73 | static void __iomem *pfc_phys_to_virt(struct sh_pfc *pfc, | 67 | static void __iomem *pfc_phys_to_virt(struct sh_pfc *pfc, |
diff --git a/drivers/sh/pfc/gpio.c b/drivers/sh/pfc/gpio.c index a32ea8083b91..37493e5fe2ee 100644 --- a/drivers/sh/pfc/gpio.c +++ b/drivers/sh/pfc/gpio.c | |||
| @@ -11,6 +11,7 @@ | |||
| 11 | 11 | ||
| 12 | #define pr_fmt(fmt) KBUILD_MODNAME " gpio: " fmt | 12 | #define pr_fmt(fmt) KBUILD_MODNAME " gpio: " fmt |
| 13 | 13 | ||
| 14 | #include <linux/device.h> | ||
| 14 | #include <linux/init.h> | 15 | #include <linux/init.h> |
| 15 | #include <linux/gpio.h> | 16 | #include <linux/gpio.h> |
| 16 | #include <linux/slab.h> | 17 | #include <linux/slab.h> |
| @@ -143,7 +144,7 @@ int sh_pfc_register_gpiochip(struct sh_pfc *pfc) | |||
| 143 | struct sh_pfc_chip *chip; | 144 | struct sh_pfc_chip *chip; |
| 144 | int ret; | 145 | int ret; |
| 145 | 146 | ||
| 146 | chip = kzalloc(sizeof(struct sh_pfc_chip), GFP_KERNEL); | 147 | chip = devm_kzalloc(pfc->dev, sizeof(*chip), GFP_KERNEL); |
| 147 | if (unlikely(!chip)) | 148 | if (unlikely(!chip)) |
| 148 | return -ENOMEM; | 149 | return -ENOMEM; |
| 149 | 150 | ||
| @@ -152,10 +153,8 @@ int sh_pfc_register_gpiochip(struct sh_pfc *pfc) | |||
| 152 | sh_pfc_gpio_setup(chip); | 153 | sh_pfc_gpio_setup(chip); |
| 153 | 154 | ||
| 154 | ret = gpiochip_add(&chip->gpio_chip); | 155 | ret = gpiochip_add(&chip->gpio_chip); |
| 155 | if (unlikely(ret < 0)) { | 156 | if (unlikely(ret < 0)) |
| 156 | kfree(chip); | ||
| 157 | return ret; | 157 | return ret; |
| 158 | } | ||
| 159 | 158 | ||
| 160 | pfc->gpio = chip; | 159 | pfc->gpio = chip; |
| 161 | 160 | ||
| @@ -175,7 +174,6 @@ int sh_pfc_unregister_gpiochip(struct sh_pfc *pfc) | |||
| 175 | if (unlikely(ret < 0)) | 174 | if (unlikely(ret < 0)) |
| 176 | return ret; | 175 | return ret; |
| 177 | 176 | ||
| 178 | kfree(chip); | ||
| 179 | pfc->gpio = NULL; | 177 | pfc->gpio = NULL; |
| 180 | return 0; | 178 | return 0; |
| 181 | } | 179 | } |
diff --git a/drivers/sh/pfc/pinctrl.c b/drivers/sh/pfc/pinctrl.c index 2fc873137ce8..b3dbefd5658b 100644 --- a/drivers/sh/pfc/pinctrl.c +++ b/drivers/sh/pfc/pinctrl.c | |||
| @@ -11,6 +11,7 @@ | |||
| 11 | #define DRV_NAME "sh-pfc" | 11 | #define DRV_NAME "sh-pfc" |
| 12 | #define pr_fmt(fmt) KBUILD_MODNAME " pinctrl: " fmt | 12 | #define pr_fmt(fmt) KBUILD_MODNAME " pinctrl: " fmt |
| 13 | 13 | ||
| 14 | #include <linux/device.h> | ||
| 14 | #include <linux/init.h> | 15 | #include <linux/init.h> |
| 15 | #include <linux/module.h> | 16 | #include <linux/module.h> |
| 16 | #include <linux/sh_pfc.h> | 17 | #include <linux/sh_pfc.h> |
| @@ -357,8 +358,8 @@ static int sh_pfc_map_gpios(struct sh_pfc *pfc, struct sh_pfc_pinctrl *pmx) | |||
| 357 | 358 | ||
| 358 | pmx->nr_pads = pfc->pdata->last_gpio - pfc->pdata->first_gpio + 1; | 359 | pmx->nr_pads = pfc->pdata->last_gpio - pfc->pdata->first_gpio + 1; |
| 359 | 360 | ||
| 360 | pmx->pads = kmalloc(sizeof(struct pinctrl_pin_desc) * pmx->nr_pads, | 361 | pmx->pads = devm_kzalloc(pfc->dev, sizeof(*pmx->pads) * pmx->nr_pads, |
| 361 | GFP_KERNEL); | 362 | GFP_KERNEL); |
| 362 | if (unlikely(!pmx->pads)) { | 363 | if (unlikely(!pmx->pads)) { |
| 363 | pmx->nr_pads = 0; | 364 | pmx->nr_pads = 0; |
| 364 | return -ENOMEM; | 365 | return -ENOMEM; |
| @@ -399,8 +400,8 @@ static int sh_pfc_map_functions(struct sh_pfc *pfc, struct sh_pfc_pinctrl *pmx) | |||
| 399 | unsigned long flags; | 400 | unsigned long flags; |
| 400 | int i, fn; | 401 | int i, fn; |
| 401 | 402 | ||
| 402 | pmx->functions = kzalloc(pmx->nr_functions * sizeof(void *), | 403 | pmx->functions = devm_kzalloc(pfc->dev, pmx->nr_functions * |
| 403 | GFP_KERNEL); | 404 | sizeof(*pmx->functions), GFP_KERNEL); |
| 404 | if (unlikely(!pmx->functions)) | 405 | if (unlikely(!pmx->functions)) |
| 405 | return -ENOMEM; | 406 | return -ENOMEM; |
| 406 | 407 | ||
| @@ -423,7 +424,7 @@ int sh_pfc_register_pinctrl(struct sh_pfc *pfc) | |||
| 423 | struct sh_pfc_pinctrl *pmx; | 424 | struct sh_pfc_pinctrl *pmx; |
| 424 | int ret; | 425 | int ret; |
| 425 | 426 | ||
| 426 | pmx = kzalloc(sizeof(struct sh_pfc_pinctrl), GFP_KERNEL); | 427 | pmx = devm_kzalloc(pfc->dev, sizeof(*pmx), GFP_KERNEL); |
| 427 | if (unlikely(!pmx)) | 428 | if (unlikely(!pmx)) |
| 428 | return -ENOMEM; | 429 | return -ENOMEM; |
| 429 | 430 | ||
| @@ -438,13 +439,11 @@ int sh_pfc_register_pinctrl(struct sh_pfc *pfc) | |||
| 438 | 439 | ||
| 439 | ret = sh_pfc_map_functions(pfc, pmx); | 440 | ret = sh_pfc_map_functions(pfc, pmx); |
| 440 | if (unlikely(ret != 0)) | 441 | if (unlikely(ret != 0)) |
| 441 | goto free_pads; | 442 | return ret; |
| 442 | 443 | ||
| 443 | pmx->pctl = pinctrl_register(&sh_pfc_pinctrl_desc, pfc->dev, pmx); | 444 | pmx->pctl = pinctrl_register(&sh_pfc_pinctrl_desc, pfc->dev, pmx); |
| 444 | if (IS_ERR(pmx->pctl)) { | 445 | if (IS_ERR(pmx->pctl)) |
| 445 | ret = PTR_ERR(pmx->pctl); | 446 | return PTR_ERR(pmx->pctl); |
| 446 | goto free_functions; | ||
| 447 | } | ||
| 448 | 447 | ||
| 449 | sh_pfc_gpio_range.npins = pfc->pdata->last_gpio | 448 | sh_pfc_gpio_range.npins = pfc->pdata->last_gpio |
| 450 | - pfc->pdata->first_gpio + 1; | 449 | - pfc->pdata->first_gpio + 1; |
| @@ -454,14 +453,6 @@ int sh_pfc_register_pinctrl(struct sh_pfc *pfc) | |||
| 454 | pinctrl_add_gpio_range(pmx->pctl, &sh_pfc_gpio_range); | 453 | pinctrl_add_gpio_range(pmx->pctl, &sh_pfc_gpio_range); |
| 455 | 454 | ||
| 456 | return 0; | 455 | return 0; |
| 457 | |||
| 458 | free_functions: | ||
| 459 | kfree(pmx->functions); | ||
| 460 | free_pads: | ||
| 461 | kfree(pmx->pads); | ||
| 462 | kfree(pmx); | ||
| 463 | |||
| 464 | return ret; | ||
| 465 | } | 456 | } |
| 466 | 457 | ||
| 467 | int sh_pfc_unregister_pinctrl(struct sh_pfc *pfc) | 458 | int sh_pfc_unregister_pinctrl(struct sh_pfc *pfc) |
| @@ -470,10 +461,6 @@ int sh_pfc_unregister_pinctrl(struct sh_pfc *pfc) | |||
| 470 | 461 | ||
| 471 | pinctrl_unregister(pmx->pctl); | 462 | pinctrl_unregister(pmx->pctl); |
| 472 | 463 | ||
| 473 | kfree(pmx->functions); | ||
| 474 | kfree(pmx->pads); | ||
| 475 | kfree(pmx); | ||
| 476 | |||
| 477 | pfc->pinctrl = NULL; | 464 | pfc->pinctrl = NULL; |
| 478 | return 0; | 465 | return 0; |
| 479 | } | 466 | } |
