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>
This commit is contained in:
parent
c6193eacda
commit
1724acfd59
@ -33,9 +33,6 @@ static void pfc_iounmap(struct sh_pfc *pfc)
|
|||||||
for (k = 0; k < pfc->pdata->num_resources; k++)
|
for (k = 0; k < pfc->pdata->num_resources; k++)
|
||||||
if (pfc->window[k].virt)
|
if (pfc->window[k].virt)
|
||||||
iounmap(pfc->window[k].virt);
|
iounmap(pfc->window[k].virt);
|
||||||
|
|
||||||
kfree(pfc->window);
|
|
||||||
pfc->window = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int pfc_ioremap(struct sh_pfc *pfc)
|
static int pfc_ioremap(struct sh_pfc *pfc)
|
||||||
@ -46,10 +43,10 @@ static int pfc_ioremap(struct sh_pfc *pfc)
|
|||||||
if (!pfc->pdata->num_resources)
|
if (!pfc->pdata->num_resources)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
pfc->window = kzalloc(pfc->pdata->num_resources * sizeof(*pfc->window),
|
pfc->window = devm_kzalloc(pfc->dev, pfc->pdata->num_resources *
|
||||||
GFP_NOWAIT);
|
sizeof(*pfc->window), GFP_NOWAIT);
|
||||||
if (!pfc->window)
|
if (!pfc->window)
|
||||||
goto err1;
|
return -ENOMEM;
|
||||||
|
|
||||||
for (k = 0; k < pfc->pdata->num_resources; k++) {
|
for (k = 0; k < pfc->pdata->num_resources; k++) {
|
||||||
res = pfc->pdata->resource + k;
|
res = pfc->pdata->resource + k;
|
||||||
@ -58,16 +55,13 @@ static int pfc_ioremap(struct sh_pfc *pfc)
|
|||||||
pfc->window[k].size = resource_size(res);
|
pfc->window[k].size = resource_size(res);
|
||||||
pfc->window[k].virt = ioremap_nocache(res->start,
|
pfc->window[k].virt = ioremap_nocache(res->start,
|
||||||
resource_size(res));
|
resource_size(res));
|
||||||
if (!pfc->window[k].virt)
|
if (!pfc->window[k].virt) {
|
||||||
goto err2;
|
pfc_iounmap(pfc);
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err2:
|
|
||||||
pfc_iounmap(pfc);
|
|
||||||
err1:
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __iomem *pfc_phys_to_virt(struct sh_pfc *pfc,
|
static void __iomem *pfc_phys_to_virt(struct sh_pfc *pfc,
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
#define pr_fmt(fmt) KBUILD_MODNAME " gpio: " fmt
|
#define pr_fmt(fmt) KBUILD_MODNAME " gpio: " fmt
|
||||||
|
|
||||||
|
#include <linux/device.h>
|
||||||
#include <linux/init.h>
|
#include <linux/init.h>
|
||||||
#include <linux/gpio.h>
|
#include <linux/gpio.h>
|
||||||
#include <linux/slab.h>
|
#include <linux/slab.h>
|
||||||
@ -143,7 +144,7 @@ int sh_pfc_register_gpiochip(struct sh_pfc *pfc)
|
|||||||
struct sh_pfc_chip *chip;
|
struct sh_pfc_chip *chip;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
chip = kzalloc(sizeof(struct sh_pfc_chip), GFP_KERNEL);
|
chip = devm_kzalloc(pfc->dev, sizeof(*chip), GFP_KERNEL);
|
||||||
if (unlikely(!chip))
|
if (unlikely(!chip))
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
@ -152,10 +153,8 @@ int sh_pfc_register_gpiochip(struct sh_pfc *pfc)
|
|||||||
sh_pfc_gpio_setup(chip);
|
sh_pfc_gpio_setup(chip);
|
||||||
|
|
||||||
ret = gpiochip_add(&chip->gpio_chip);
|
ret = gpiochip_add(&chip->gpio_chip);
|
||||||
if (unlikely(ret < 0)) {
|
if (unlikely(ret < 0))
|
||||||
kfree(chip);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
|
||||||
|
|
||||||
pfc->gpio = chip;
|
pfc->gpio = chip;
|
||||||
|
|
||||||
@ -175,7 +174,6 @@ int sh_pfc_unregister_gpiochip(struct sh_pfc *pfc)
|
|||||||
if (unlikely(ret < 0))
|
if (unlikely(ret < 0))
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
kfree(chip);
|
|
||||||
pfc->gpio = NULL;
|
pfc->gpio = NULL;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#define DRV_NAME "sh-pfc"
|
#define DRV_NAME "sh-pfc"
|
||||||
#define pr_fmt(fmt) KBUILD_MODNAME " pinctrl: " fmt
|
#define pr_fmt(fmt) KBUILD_MODNAME " pinctrl: " fmt
|
||||||
|
|
||||||
|
#include <linux/device.h>
|
||||||
#include <linux/init.h>
|
#include <linux/init.h>
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
#include <linux/sh_pfc.h>
|
#include <linux/sh_pfc.h>
|
||||||
@ -357,8 +358,8 @@ static int sh_pfc_map_gpios(struct sh_pfc *pfc, struct sh_pfc_pinctrl *pmx)
|
|||||||
|
|
||||||
pmx->nr_pads = pfc->pdata->last_gpio - pfc->pdata->first_gpio + 1;
|
pmx->nr_pads = pfc->pdata->last_gpio - pfc->pdata->first_gpio + 1;
|
||||||
|
|
||||||
pmx->pads = kmalloc(sizeof(struct pinctrl_pin_desc) * pmx->nr_pads,
|
pmx->pads = devm_kzalloc(pfc->dev, sizeof(*pmx->pads) * pmx->nr_pads,
|
||||||
GFP_KERNEL);
|
GFP_KERNEL);
|
||||||
if (unlikely(!pmx->pads)) {
|
if (unlikely(!pmx->pads)) {
|
||||||
pmx->nr_pads = 0;
|
pmx->nr_pads = 0;
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
@ -399,8 +400,8 @@ static int sh_pfc_map_functions(struct sh_pfc *pfc, struct sh_pfc_pinctrl *pmx)
|
|||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
int i, fn;
|
int i, fn;
|
||||||
|
|
||||||
pmx->functions = kzalloc(pmx->nr_functions * sizeof(void *),
|
pmx->functions = devm_kzalloc(pfc->dev, pmx->nr_functions *
|
||||||
GFP_KERNEL);
|
sizeof(*pmx->functions), GFP_KERNEL);
|
||||||
if (unlikely(!pmx->functions))
|
if (unlikely(!pmx->functions))
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
@ -423,7 +424,7 @@ int sh_pfc_register_pinctrl(struct sh_pfc *pfc)
|
|||||||
struct sh_pfc_pinctrl *pmx;
|
struct sh_pfc_pinctrl *pmx;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
pmx = kzalloc(sizeof(struct sh_pfc_pinctrl), GFP_KERNEL);
|
pmx = devm_kzalloc(pfc->dev, sizeof(*pmx), GFP_KERNEL);
|
||||||
if (unlikely(!pmx))
|
if (unlikely(!pmx))
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
@ -438,13 +439,11 @@ int sh_pfc_register_pinctrl(struct sh_pfc *pfc)
|
|||||||
|
|
||||||
ret = sh_pfc_map_functions(pfc, pmx);
|
ret = sh_pfc_map_functions(pfc, pmx);
|
||||||
if (unlikely(ret != 0))
|
if (unlikely(ret != 0))
|
||||||
goto free_pads;
|
return ret;
|
||||||
|
|
||||||
pmx->pctl = pinctrl_register(&sh_pfc_pinctrl_desc, pfc->dev, pmx);
|
pmx->pctl = pinctrl_register(&sh_pfc_pinctrl_desc, pfc->dev, pmx);
|
||||||
if (IS_ERR(pmx->pctl)) {
|
if (IS_ERR(pmx->pctl))
|
||||||
ret = PTR_ERR(pmx->pctl);
|
return PTR_ERR(pmx->pctl);
|
||||||
goto free_functions;
|
|
||||||
}
|
|
||||||
|
|
||||||
sh_pfc_gpio_range.npins = pfc->pdata->last_gpio
|
sh_pfc_gpio_range.npins = pfc->pdata->last_gpio
|
||||||
- pfc->pdata->first_gpio + 1;
|
- pfc->pdata->first_gpio + 1;
|
||||||
@ -454,14 +453,6 @@ int sh_pfc_register_pinctrl(struct sh_pfc *pfc)
|
|||||||
pinctrl_add_gpio_range(pmx->pctl, &sh_pfc_gpio_range);
|
pinctrl_add_gpio_range(pmx->pctl, &sh_pfc_gpio_range);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
free_functions:
|
|
||||||
kfree(pmx->functions);
|
|
||||||
free_pads:
|
|
||||||
kfree(pmx->pads);
|
|
||||||
kfree(pmx);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int sh_pfc_unregister_pinctrl(struct sh_pfc *pfc)
|
int sh_pfc_unregister_pinctrl(struct sh_pfc *pfc)
|
||||||
@ -470,10 +461,6 @@ int sh_pfc_unregister_pinctrl(struct sh_pfc *pfc)
|
|||||||
|
|
||||||
pinctrl_unregister(pmx->pctl);
|
pinctrl_unregister(pmx->pctl);
|
||||||
|
|
||||||
kfree(pmx->functions);
|
|
||||||
kfree(pmx->pads);
|
|
||||||
kfree(pmx);
|
|
||||||
|
|
||||||
pfc->pinctrl = NULL;
|
pfc->pinctrl = NULL;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user