linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] pinctrl: Avoid hardcoded string offsets and buffer lengths
@ 2019-07-31 13:29 Geert Uytterhoeven
  2019-07-31 13:29 ` [PATCH 1/3] pinctrl: devicetree: Use strlen() instead of hardcoded number Geert Uytterhoeven
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Geert Uytterhoeven @ 2019-07-31 13:29 UTC (permalink / raw)
  To: Linus Walleij; +Cc: linux-gpio, linux-kernel, Geert Uytterhoeven

	Hi Linus,

This patch series gets rid of hardcoded string offsets and buffer
lengths, in favor of using strlen() and (devm_)kasprintf().

Thanks!

Geert Uytterhoeven (3):
  pinctrl: devicetree: Use strlen() instead of hardcoded number
  pinctrl: lantiq: Use kasprintf() instead of fixed buffer formatting
  pinctrl: xway: Use devm_kasprintf() instead of fixed buffer formatting

 drivers/pinctrl/devicetree.c     | 6 ++----
 drivers/pinctrl/pinctrl-falcon.c | 6 +-----
 drivers/pinctrl/pinctrl-xway.c   | 4 +---
 3 files changed, 4 insertions(+), 12 deletions(-)

-- 
2.17.1

Gr{oetje,eeting}s,

						Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
							    -- Linus Torvalds

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/3] pinctrl: devicetree: Use strlen() instead of hardcoded number
  2019-07-31 13:29 [PATCH 0/3] pinctrl: Avoid hardcoded string offsets and buffer lengths Geert Uytterhoeven
@ 2019-07-31 13:29 ` Geert Uytterhoeven
  2019-08-05 11:29   ` Linus Walleij
  2019-07-31 13:29 ` [PATCH 2/3] pinctrl: lantiq: Use kasprintf() instead of fixed buffer formatting Geert Uytterhoeven
  2019-07-31 13:29 ` [PATCH 3/3] pinctrl: xway: Use devm_kasprintf() " Geert Uytterhoeven
  2 siblings, 1 reply; 7+ messages in thread
From: Geert Uytterhoeven @ 2019-07-31 13:29 UTC (permalink / raw)
  To: Linus Walleij; +Cc: linux-gpio, linux-kernel, Geert Uytterhoeven

Improve readability by replacing a hardcoded number requiring a comment
by strlen().

Gcc is smart enough to evaluate the length of a constant string at
compile-time.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
 drivers/pinctrl/devicetree.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/pinctrl/devicetree.c b/drivers/pinctrl/devicetree.c
index 88ddbb2e30de10f6..5d6d8b1e906203af 100644
--- a/drivers/pinctrl/devicetree.c
+++ b/drivers/pinctrl/devicetree.c
@@ -228,10 +228,8 @@ int pinctrl_dt_to_map(struct pinctrl *p, struct pinctrl_dev *pctldev)
 		 * than dynamically allocate it and have to free it later,
 		 * just point part way into the property name for the string.
 		 */
-		if (ret < 0) {
-			/* strlen("pinctrl-") == 8 */
-			statename = prop->name + 8;
-		}
+		if (ret < 0)
+			statename = prop->name + strlen("pinctrl-");
 
 		/* For every referenced pin configuration node in it */
 		for (config = 0; config < size; config++) {
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/3] pinctrl: lantiq: Use kasprintf() instead of fixed buffer formatting
  2019-07-31 13:29 [PATCH 0/3] pinctrl: Avoid hardcoded string offsets and buffer lengths Geert Uytterhoeven
  2019-07-31 13:29 ` [PATCH 1/3] pinctrl: devicetree: Use strlen() instead of hardcoded number Geert Uytterhoeven
@ 2019-07-31 13:29 ` Geert Uytterhoeven
  2019-08-05 11:30   ` Linus Walleij
  2019-07-31 13:29 ` [PATCH 3/3] pinctrl: xway: Use devm_kasprintf() " Geert Uytterhoeven
  2 siblings, 1 reply; 7+ messages in thread
From: Geert Uytterhoeven @ 2019-07-31 13:29 UTC (permalink / raw)
  To: Linus Walleij; +Cc: linux-gpio, linux-kernel, Geert Uytterhoeven

Improve readability and maintainability by replacing a hardcoded string
allocation and formatting by the use of the kasprintf() helper.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
 drivers/pinctrl/pinctrl-falcon.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-falcon.c b/drivers/pinctrl/pinctrl-falcon.c
index ef133a82e612544a..4a3b8d2677fd498f 100644
--- a/drivers/pinctrl/pinctrl-falcon.c
+++ b/drivers/pinctrl/pinctrl-falcon.c
@@ -96,12 +96,8 @@ static void lantiq_load_pin_desc(struct pinctrl_pin_desc *d, int bank, int len)
 	int i;
 
 	for (i = 0; i < len; i++) {
-		/* strlen("ioXYZ") + 1 = 6 */
-		char *name = kzalloc(6, GFP_KERNEL);
-
-		snprintf(name, 6, "io%d", base + i);
 		d[i].number = base + i;
-		d[i].name = name;
+		d[i].name = kasprintf(GFP_KERNEL, "io%d", base + i);
 	}
 	pad_count[bank] = len;
 }
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/3] pinctrl: xway: Use devm_kasprintf() instead of fixed buffer formatting
  2019-07-31 13:29 [PATCH 0/3] pinctrl: Avoid hardcoded string offsets and buffer lengths Geert Uytterhoeven
  2019-07-31 13:29 ` [PATCH 1/3] pinctrl: devicetree: Use strlen() instead of hardcoded number Geert Uytterhoeven
  2019-07-31 13:29 ` [PATCH 2/3] pinctrl: lantiq: Use kasprintf() instead of fixed buffer formatting Geert Uytterhoeven
@ 2019-07-31 13:29 ` Geert Uytterhoeven
  2019-08-05 11:31   ` Linus Walleij
  2 siblings, 1 reply; 7+ messages in thread
From: Geert Uytterhoeven @ 2019-07-31 13:29 UTC (permalink / raw)
  To: Linus Walleij; +Cc: linux-gpio, linux-kernel, Geert Uytterhoeven

Improve readability and maintainability by replacing a hardcoded string
allocation and formatting by the use of the devm_kasprintf() helper.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
 drivers/pinctrl/pinctrl-xway.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-xway.c b/drivers/pinctrl/pinctrl-xway.c
index 376222d0e5c570eb..913d38f29b7306f3 100644
--- a/drivers/pinctrl/pinctrl-xway.c
+++ b/drivers/pinctrl/pinctrl-xway.c
@@ -1731,13 +1731,11 @@ static int pinmux_xway_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	for (i = 0; i < xway_chip.ngpio; i++) {
-		/* strlen("ioXY") + 1 = 5 */
-		char *name = devm_kzalloc(&pdev->dev, 5, GFP_KERNEL);
+		char *name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "io%d", i);
 
 		if (!name)
 			return -ENOMEM;
 
-		snprintf(name, 5, "io%d", i);
 		xway_info.pads[i].number = GPIO0 + i;
 		xway_info.pads[i].name = name;
 	}
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/3] pinctrl: devicetree: Use strlen() instead of hardcoded number
  2019-07-31 13:29 ` [PATCH 1/3] pinctrl: devicetree: Use strlen() instead of hardcoded number Geert Uytterhoeven
@ 2019-08-05 11:29   ` Linus Walleij
  0 siblings, 0 replies; 7+ messages in thread
From: Linus Walleij @ 2019-08-05 11:29 UTC (permalink / raw)
  To: Geert Uytterhoeven; +Cc: open list:GPIO SUBSYSTEM, linux-kernel

On Wed, Jul 31, 2019 at 3:29 PM Geert Uytterhoeven
<geert+renesas@glider.be> wrote:

> Improve readability by replacing a hardcoded number requiring a comment
> by strlen().
>
> Gcc is smart enough to evaluate the length of a constant string at
> compile-time.
>
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>

Patch applied.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/3] pinctrl: lantiq: Use kasprintf() instead of fixed buffer formatting
  2019-07-31 13:29 ` [PATCH 2/3] pinctrl: lantiq: Use kasprintf() instead of fixed buffer formatting Geert Uytterhoeven
@ 2019-08-05 11:30   ` Linus Walleij
  0 siblings, 0 replies; 7+ messages in thread
From: Linus Walleij @ 2019-08-05 11:30 UTC (permalink / raw)
  To: Geert Uytterhoeven; +Cc: open list:GPIO SUBSYSTEM, linux-kernel

On Wed, Jul 31, 2019 at 3:29 PM Geert Uytterhoeven
<geert+renesas@glider.be> wrote:

> Improve readability and maintainability by replacing a hardcoded string
> allocation and formatting by the use of the kasprintf() helper.
>
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>

Patch applied.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/3] pinctrl: xway: Use devm_kasprintf() instead of fixed buffer formatting
  2019-07-31 13:29 ` [PATCH 3/3] pinctrl: xway: Use devm_kasprintf() " Geert Uytterhoeven
@ 2019-08-05 11:31   ` Linus Walleij
  0 siblings, 0 replies; 7+ messages in thread
From: Linus Walleij @ 2019-08-05 11:31 UTC (permalink / raw)
  To: Geert Uytterhoeven; +Cc: open list:GPIO SUBSYSTEM, linux-kernel

On Wed, Jul 31, 2019 at 3:29 PM Geert Uytterhoeven
<geert+renesas@glider.be> wrote:

> Improve readability and maintainability by replacing a hardcoded string
> allocation and formatting by the use of the devm_kasprintf() helper.
>
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>

Patch applied.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-08-05 11:31 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-31 13:29 [PATCH 0/3] pinctrl: Avoid hardcoded string offsets and buffer lengths Geert Uytterhoeven
2019-07-31 13:29 ` [PATCH 1/3] pinctrl: devicetree: Use strlen() instead of hardcoded number Geert Uytterhoeven
2019-08-05 11:29   ` Linus Walleij
2019-07-31 13:29 ` [PATCH 2/3] pinctrl: lantiq: Use kasprintf() instead of fixed buffer formatting Geert Uytterhoeven
2019-08-05 11:30   ` Linus Walleij
2019-07-31 13:29 ` [PATCH 3/3] pinctrl: xway: Use devm_kasprintf() " Geert Uytterhoeven
2019-08-05 11:31   ` 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).