* [PATCH 1/2] gpiolib: constify label in gpio_device
@ 2017-12-13 11:25 Bartosz Golaszewski
2017-12-13 11:25 ` [PATCH 2/2] gpiolib: use kstrdup_const() for gpio_device label Bartosz Golaszewski
2017-12-20 8:02 ` [PATCH 1/2] gpiolib: constify label in gpio_device Linus Walleij
0 siblings, 2 replies; 5+ messages in thread
From: Bartosz Golaszewski @ 2017-12-13 11:25 UTC (permalink / raw)
To: Linus Walleij; +Cc: linux-gpio, linux-kernel, Bartosz Golaszewski
This string is never modified. Make it const.
Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
---
drivers/gpio/gpiolib.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h
index 5e1f7cc6eeb6..6e9228b94437 100644
--- a/drivers/gpio/gpiolib.h
+++ b/drivers/gpio/gpiolib.h
@@ -58,7 +58,7 @@ struct gpio_device {
struct gpio_desc *descs;
int base;
u16 ngpio;
- char *label;
+ const char *label;
void *data;
struct list_head list;
--
2.15.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] gpiolib: use kstrdup_const() for gpio_device label
2017-12-13 11:25 [PATCH 1/2] gpiolib: constify label in gpio_device Bartosz Golaszewski
@ 2017-12-13 11:25 ` Bartosz Golaszewski
2017-12-13 19:44 ` Joe Perches
2017-12-20 8:02 ` [PATCH 1/2] gpiolib: constify label in gpio_device Linus Walleij
1 sibling, 1 reply; 5+ messages in thread
From: Bartosz Golaszewski @ 2017-12-13 11:25 UTC (permalink / raw)
To: Linus Walleij; +Cc: linux-gpio, linux-kernel, Bartosz Golaszewski
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.
Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
---
drivers/gpio/gpiolib.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 56eec094184c..c078f7f35100 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1062,7 +1062,7 @@ static void gpiodevice_release(struct device *dev)
list_del(&gdev->list);
ida_simple_remove(&gpio_ida, gdev->id);
- kfree(gdev->label);
+ kfree_const(gdev->label);
kfree(gdev->descs);
kfree(gdev);
}
@@ -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);
if (!gdev->label) {
status = -ENOMEM;
goto err_free_descs;
@@ -1294,7 +1294,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *chip, void *data,
list_del(&gdev->list);
spin_unlock_irqrestore(&gpio_lock, flags);
err_free_label:
- kfree(gdev->label);
+ kfree_const(gdev->label);
err_free_descs:
kfree(gdev->descs);
err_free_gdev:
--
2.15.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] gpiolib: use kstrdup_const() for gpio_device label
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
2017-12-14 14:30 ` Bartosz Golaszewski
0 siblings, 1 reply; 5+ messages in thread
From: Joe Perches @ 2017-12-13 19:44 UTC (permalink / raw)
To: Bartosz Golaszewski, Linus Walleij; +Cc: linux-gpio, linux-kernel
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;
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] gpiolib: use kstrdup_const() for gpio_device label
2017-12-13 19:44 ` Joe Perches
@ 2017-12-14 14:30 ` Bartosz Golaszewski
0 siblings, 0 replies; 5+ messages in thread
From: Bartosz Golaszewski @ 2017-12-14 14:30 UTC (permalink / raw)
To: Joe Perches; +Cc: Linus Walleij, linux-gpio, Linux Kernel Mailing List
2017-12-13 20:44 GMT+01:00 Joe Perches <joe@perches.com>:
> 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;
>
Good point. Sent v2.
Thanks,
Bartosz
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] gpiolib: constify label in gpio_device
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-20 8:02 ` Linus Walleij
1 sibling, 0 replies; 5+ messages in thread
From: Linus Walleij @ 2017-12-20 8:02 UTC (permalink / raw)
To: Bartosz Golaszewski; +Cc: linux-gpio, linux-kernel
On Wed, Dec 13, 2017 at 12:25 PM, Bartosz Golaszewski <brgl@bgdev.pl> wrote:
> This string is never modified. Make it const.
>
> Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
Patch applied.
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-12-20 8:02 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2017-12-14 14:30 ` Bartosz Golaszewski
2017-12-20 8:02 ` [PATCH 1/2] gpiolib: constify label in gpio_device Linus Walleij
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).