From patchwork Fri Mar 29 02:42:11 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Horman X-Patchwork-Id: 2362441 Return-Path: X-Original-To: patchwork-ltsi-dev@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) by patchwork1.kernel.org (Postfix) with ESMTP id 135DB3FD40 for ; Fri, 29 Mar 2013 02:53:22 +0000 (UTC) Received: from mail.linux-foundation.org (localhost [IPv6:::1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 556AD9F9; Fri, 29 Mar 2013 02:46:55 +0000 (UTC) X-Original-To: ltsi-dev@lists.linuxfoundation.org Delivered-To: ltsi-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTP id 731F1D77 for ; Fri, 29 Mar 2013 02:46:26 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from kirsty.vergenet.net (kirsty.vergenet.net [202.4.237.240]) by smtp1.linuxfoundation.org (Postfix) with ESMTP id BADA220182 for ; Fri, 29 Mar 2013 02:46:14 +0000 (UTC) Received: from ayumi.akashicho.tokyo.vergenet.net (p8120-ipbfp1001kobeminato.hyogo.ocn.ne.jp [118.10.137.120]) by kirsty.vergenet.net (Postfix) with ESMTP id 238872C6A3C; Fri, 29 Mar 2013 13:45:48 +1100 (EST) Received: by ayumi.akashicho.tokyo.vergenet.net (Postfix, from userid 7100) id BC206EDEA28; Fri, 29 Mar 2013 11:45:46 +0900 (JST) From: Simon Horman To: ltsi-dev@lists.linuxfoundation.org Date: Fri, 29 Mar 2013 11:42:11 +0900 Message-Id: <1364525119-31791-203-git-send-email-horms+renesas@verge.net.au> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1364525119-31791-1-git-send-email-horms+renesas@verge.net.au> References: <1364525119-31791-1-git-send-email-horms+renesas@verge.net.au> X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Magnus Damm Subject: [LTSI-dev] [PATCH/RFC 202/390] sh-pfc: Use devm_kzalloc() X-BeenThere: ltsi-dev@lists.linuxfoundation.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: "A list to discuss patches, development, and other things related to the LTSI project" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ltsi-dev-bounces@lists.linuxfoundation.org Errors-To: ltsi-dev-bounces@lists.linuxfoundation.org From: Laurent Pinchart Replace probe-time kmalloc()/kzalloc() calls with devm_kzalloc() and get rid of the corresponding kfree() calls. Signed-off-by: Laurent Pinchart Acked-by: Linus Walleij Signed-off-by: Simon Horman (cherry picked from commit 1724acfd598bdf688218bdd26a5f02dd55b6ec62) Signed-off-by: Simon Horman --- drivers/sh/pfc/core.c | 20 +++++++------------- drivers/sh/pfc/gpio.c | 8 +++----- 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 6d162e6..5491902 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) 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) @@ -46,10 +43,10 @@ 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; @@ -58,16 +55,13 @@ static int pfc_ioremap(struct sh_pfc *pfc) 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, diff --git a/drivers/sh/pfc/gpio.c b/drivers/sh/pfc/gpio.c index a32ea80..37493e5 100644 --- a/drivers/sh/pfc/gpio.c +++ b/drivers/sh/pfc/gpio.c @@ -11,6 +11,7 @@ #define pr_fmt(fmt) KBUILD_MODNAME " gpio: " fmt +#include #include #include #include @@ -143,7 +144,7 @@ int sh_pfc_register_gpiochip(struct sh_pfc *pfc) 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; @@ -152,10 +153,8 @@ int sh_pfc_register_gpiochip(struct sh_pfc *pfc) 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; @@ -175,7 +174,6 @@ int sh_pfc_unregister_gpiochip(struct sh_pfc *pfc) if (unlikely(ret < 0)) return ret; - kfree(chip); pfc->gpio = NULL; return 0; } diff --git a/drivers/sh/pfc/pinctrl.c b/drivers/sh/pfc/pinctrl.c index 2fc8731..b3dbefd 100644 --- a/drivers/sh/pfc/pinctrl.c +++ b/drivers/sh/pfc/pinctrl.c @@ -11,6 +11,7 @@ #define DRV_NAME "sh-pfc" #define pr_fmt(fmt) KBUILD_MODNAME " pinctrl: " fmt +#include #include #include #include @@ -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->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; @@ -399,8 +400,8 @@ static int sh_pfc_map_functions(struct sh_pfc *pfc, struct sh_pfc_pinctrl *pmx) 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; @@ -423,7 +424,7 @@ int sh_pfc_register_pinctrl(struct sh_pfc *pfc) 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; @@ -438,13 +439,11 @@ int sh_pfc_register_pinctrl(struct sh_pfc *pfc) 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; @@ -454,14 +453,6 @@ int sh_pfc_register_pinctrl(struct sh_pfc *pfc) 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) @@ -470,10 +461,6 @@ 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; }