From: Ladislav Michl <ladis@linux-mips.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2] gpio: dwapb_gpio: Change to use devm_kcalloc()
Date: Fri, 7 Sep 2018 12:58:38 +0200 [thread overview]
Message-ID: <20180907105838.GB6202@lenoch> (raw)
In-Reply-To: <230a06f3-ed6e-3fea-2de8-f0a12ae02f03@denx.de>
On Fri, Sep 07, 2018 at 10:51:00AM +0200, Marek Vasut wrote:
> On 09/07/2018 08:24 AM, Ley Foon Tan wrote:
> > Change to use managed resource function devm_kcalloc(),
> > so it will auto free memory when driver is removed.
> >
> > Signed-off-by: Ley Foon Tan <ley.foon.tan@intel.com>
> >
> > ---
> > v2:
> > - Remove free() function.
> > ---
> > drivers/gpio/dwapb_gpio.c | 4 +---
> > 1 file changed, 1 insertion(+), 3 deletions(-)
> >
> > diff --git a/drivers/gpio/dwapb_gpio.c b/drivers/gpio/dwapb_gpio.c
> > index 0f6574d..6f9d17d 100644
> > --- a/drivers/gpio/dwapb_gpio.c
> > +++ b/drivers/gpio/dwapb_gpio.c
> > @@ -171,8 +171,7 @@ static int gpio_dwapb_bind(struct udevice *dev)
> > if (!fdtdec_get_bool(blob, node, "gpio-controller"))
> > continue;
> >
> > - plat = NULL;
> > - plat = calloc(1, sizeof(*plat));
> > + plat = devm_kcalloc(dev, 1, sizeof(*plat), GFP_KERNEL);
> > if (!plat)
> > return -ENOMEM;
> >
> > @@ -196,7 +195,6 @@ static int gpio_dwapb_bind(struct udevice *dev)
> > return 0;
> >
> > err:
> > - free(plat);
> > return ret;
>
> Well, this becomes return ret, right ? ;-)
Well, this vanishes completely ;-) But there're more strange snipets,
better to show patch:
diff --git a/drivers/gpio/dwapb_gpio.c b/drivers/gpio/dwapb_gpio.c
index a118f58b22..7b3c5af6a7 100644
--- a/drivers/gpio/dwapb_gpio.c
+++ b/drivers/gpio/dwapb_gpio.c
@@ -123,8 +123,7 @@ static int gpio_dwapb_bind(struct udevice *dev)
if (!fdtdec_get_bool(blob, node, "gpio-controller"))
continue;
- plat = NULL;
- plat = calloc(1, sizeof(*plat));
+ plat = devm_kcalloc(dev, 1, sizeof(*plat), GFP_KERNEL);
if (!plat)
return -ENOMEM;
@@ -133,23 +132,17 @@ static int gpio_dwapb_bind(struct udevice *dev)
plat->pins = fdtdec_get_int(blob, node, "snps,nr-gpios", 0);
plat->name = fdt_stringlist_get(blob, node, "bank-name", 0,
NULL);
- if (ret)
- goto err;
ret = device_bind(dev, dev->driver, plat->name,
plat, -1, &subdev);
if (ret)
- goto err;
+ return ret;
dev_set_of_offset(subdev, node);
bank++;
}
return 0;
-
-err:
- free(plat);
- return ret;
}
static const struct udevice_id gpio_dwapb_ids[] = {
> > }
> >
> >
>
>
> --
> Best regards,
> Marek Vasut
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> https://lists.denx.de/listinfo/u-boot
prev parent reply other threads:[~2018-09-07 10:58 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-07 6:24 [U-Boot] [PATCH v2] gpio: dwapb_gpio: Change to use devm_kcalloc() Ley Foon Tan
2018-09-07 8:51 ` Marek Vasut
2018-09-07 10:58 ` Ladislav Michl [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180907105838.GB6202@lenoch \
--to=ladis@linux-mips.org \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox