for (k = 0; k < pfc->pdata->num_resources; k++)
if (pfc->window[k].virt)
iounmap(pfc->window[k].virt);
-
- kfree(pfc->window);
- pfc->window = NULL;
}
static int pfc_ioremap(struct sh_pfc *pfc)
if (!pfc->pdata->num_resources)
return 0;
- pfc->window = kzalloc(pfc->pdata->num_resources * sizeof(*pfc->window),
- GFP_NOWAIT);
+ pfc->window = devm_kzalloc(pfc->dev, pfc->pdata->num_resources *
+ sizeof(*pfc->window), GFP_NOWAIT);
if (!pfc->window)
- goto err1;
+ return -ENOMEM;
for (k = 0; k < pfc->pdata->num_resources; k++) {
res = pfc->pdata->resource + k;
pfc->window[k].size = resource_size(res);
pfc->window[k].virt = ioremap_nocache(res->start,
resource_size(res));
- if (!pfc->window[k].virt)
- goto err2;
+ if (!pfc->window[k].virt) {
+ pfc_iounmap(pfc);
+ return -ENOMEM;
+ }
}
return 0;
-
-err2:
- pfc_iounmap(pfc);
-err1:
- return -1;
}
static void __iomem *pfc_phys_to_virt(struct sh_pfc *pfc,
#define pr_fmt(fmt) KBUILD_MODNAME " gpio: " fmt
+#include <linux/device.h>
#include <linux/init.h>
#include <linux/gpio.h>
#include <linux/slab.h>
struct sh_pfc_chip *chip;
int ret;
- chip = kzalloc(sizeof(struct sh_pfc_chip), GFP_KERNEL);
+ chip = devm_kzalloc(pfc->dev, sizeof(*chip), GFP_KERNEL);
if (unlikely(!chip))
return -ENOMEM;
sh_pfc_gpio_setup(chip);
ret = gpiochip_add(&chip->gpio_chip);
- if (unlikely(ret < 0)) {
- kfree(chip);
+ if (unlikely(ret < 0))
return ret;
- }
pfc->gpio = chip;
if (unlikely(ret < 0))
return ret;
- kfree(chip);
pfc->gpio = NULL;
return 0;
}
#define DRV_NAME "sh-pfc"
#define pr_fmt(fmt) KBUILD_MODNAME " pinctrl: " fmt
+#include <linux/device.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/sh_pfc.h>
pmx->nr_pads = pfc->pdata->last_gpio - pfc->pdata->first_gpio + 1;
- pmx->pads = kmalloc(sizeof(struct pinctrl_pin_desc) * pmx->nr_pads,
- GFP_KERNEL);
+ pmx->pads = devm_kzalloc(pfc->dev, sizeof(*pmx->pads) * pmx->nr_pads,
+ GFP_KERNEL);
if (unlikely(!pmx->pads)) {
pmx->nr_pads = 0;
return -ENOMEM;
unsigned long flags;
int i, fn;
- pmx->functions = kzalloc(pmx->nr_functions * sizeof(void *),
- GFP_KERNEL);
+ pmx->functions = devm_kzalloc(pfc->dev, pmx->nr_functions *
+ sizeof(*pmx->functions), GFP_KERNEL);
if (unlikely(!pmx->functions))
return -ENOMEM;
struct sh_pfc_pinctrl *pmx;
int ret;
- pmx = kzalloc(sizeof(struct sh_pfc_pinctrl), GFP_KERNEL);
+ pmx = devm_kzalloc(pfc->dev, sizeof(*pmx), GFP_KERNEL);
if (unlikely(!pmx))
return -ENOMEM;
ret = sh_pfc_map_functions(pfc, pmx);
if (unlikely(ret != 0))
- goto free_pads;
+ return ret;
pmx->pctl = pinctrl_register(&sh_pfc_pinctrl_desc, pfc->dev, pmx);
- if (IS_ERR(pmx->pctl)) {
- ret = PTR_ERR(pmx->pctl);
- goto free_functions;
- }
+ if (IS_ERR(pmx->pctl))
+ return PTR_ERR(pmx->pctl);
sh_pfc_gpio_range.npins = pfc->pdata->last_gpio
- pfc->pdata->first_gpio + 1;
pinctrl_add_gpio_range(pmx->pctl, &sh_pfc_gpio_range);
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)
pinctrl_unregister(pmx->pctl);
- kfree(pmx->functions);
- kfree(pmx->pads);
- kfree(pmx);
-
pfc->pinctrl = NULL;
return 0;
}