From: Joe Perches <joe@perches.com>
To: Bartosz Golaszewski <brgl@bgdev.pl>,
Linus Walleij <linus.walleij@linaro.org>
Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] gpiolib: use kstrdup_const() for gpio_device label
Date: Wed, 13 Dec 2017 11:44:39 -0800 [thread overview]
Message-ID: <1513194279.27409.37.camel@perches.com> (raw)
In-Reply-To: <20171213112520.7479-2-brgl@bgdev.pl>
On Wed, 2017-12-13 at 12:25 +0100, Bartosz Golaszewski wrote:
> Users often pass a pointer to a static string to gpiochip_add_data()
> family of functions. Avoid unnecessary memory allocations with the
> provided helper routine.
[]
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
[]
> @@ -1171,9 +1171,9 @@ int gpiochip_add_data_with_key(struct gpio_chip *chip, void *data,
> }
>
> if (chip->label)
> - gdev->label = kstrdup(chip->label, GFP_KERNEL);
> + gdev->label = kstrdup_const(chip->label, GFP_KERNEL);
> else
> - gdev->label = kstrdup("unknown", GFP_KERNEL);
> + gdev->label = kstrdup_const("unknown", GFP_KERNEL);
A plain ?: would be more intelligible
and a bit smaller object code too.
ie:
gdev->label = kstrdup_const(chip->label ?: "unknown", GFP_KERNEL);
> if (!gdev->label) {
> status = -ENOMEM;
> goto err_free_descs;
next prev parent reply other threads:[~2017-12-13 19:44 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-13 11:25 [PATCH 1/2] gpiolib: constify label in gpio_device Bartosz Golaszewski
2017-12-13 11:25 ` [PATCH 2/2] gpiolib: use kstrdup_const() for gpio_device label Bartosz Golaszewski
2017-12-13 19:44 ` Joe Perches [this message]
2017-12-14 14:30 ` Bartosz Golaszewski
2017-12-20 8:02 ` [PATCH 1/2] gpiolib: constify label in gpio_device Linus Walleij
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=1513194279.27409.37.camel@perches.com \
--to=joe@perches.com \
--cc=brgl@bgdev.pl \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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