linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch] pinctrl: samsung: don't truncate the last char of "-grp"
@ 2015-06-11 15:46 Dan Carpenter
  2015-06-15  4:17 ` Krzysztof Kozlowski
  0 siblings, 1 reply; 9+ messages in thread
From: Dan Carpenter @ 2015-06-11 15:46 UTC (permalink / raw)
  To: Tomasz Figa
  Cc: Thomas Abraham, Linus Walleij, Kukjin Kim, Krzysztof Kozlowski,
	linux-samsung-soc, linux-gpio, kernel-janitors

We allocate sizeof("-grp") which is 5 bytes but then we pass 4 to the
snprintf() so the last 'p' char is truncated away.

The kzalloc() can be made into kmalloc() since we are going to fill
the whole buffer.  But I know that Walter Harms is going to grumble if I
don't use kasprintf().  :P  And also checkpatch.pl these days complains
that the "allocation failed" printks aren't needed so I removed them.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/drivers/pinctrl/samsung/pinctrl-exynos5440.c b/drivers/pinctrl/samsung/pinctrl-exynos5440.c
index f5619fb..f804a61c 100644
--- a/drivers/pinctrl/samsung/pinctrl-exynos5440.c
+++ b/drivers/pinctrl/samsung/pinctrl-exynos5440.c
@@ -215,12 +215,9 @@ static int exynos5440_dt_node_to_map(struct pinctrl_dev *pctldev,
 	 * Allocate memory for pin group name. The pin group name is derived
 	 * from the node name from which these map entries are be created.
 	 */
-	gname = kzalloc(strlen(np->name) + GSUFFIX_LEN, GFP_KERNEL);
-	if (!gname) {
-		dev_err(dev, "failed to alloc memory for group name\n");
+	gname = kasprintf(GFP_KERNEL, "%s%s", np->name, GROUP_SUFFIX);
+	if (!gname)
 		goto free_map;
-	}
-	snprintf(gname, strlen(np->name) + 4, "%s%s", np->name, GROUP_SUFFIX);
 
 	/*
 	 * don't have config options? then skip over to creating function
@@ -710,14 +707,10 @@ static int exynos5440_pinctrl_parse_dt(struct platform_device *pdev,
 		}
 
 		/* derive pin group name from the node name */
-		gname = devm_kzalloc(dev, strlen(cfg_np->name) + GSUFFIX_LEN,
-					GFP_KERNEL);
-		if (!gname) {
-			dev_err(dev, "failed to alloc memory for group name\n");
+		gname = devm_kasprintf(dev, GFP_KERNEL,
+				       "%s%s", cfg_np->name, GROUP_SUFFIX);
+		if (!gname)
 			return -ENOMEM;
-		}
-		snprintf(gname, strlen(cfg_np->name) + 4, "%s%s", cfg_np->name,
-			 GROUP_SUFFIX);
 
 		grp->name = gname;
 		grp->pins = pin_list;

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

end of thread, other threads:[~2015-07-16  8:22 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-11 15:46 [patch] pinctrl: samsung: don't truncate the last char of "-grp" Dan Carpenter
2015-06-15  4:17 ` Krzysztof Kozlowski
2015-06-19  8:52   ` Dan Carpenter
2015-06-22 15:12     ` [patch v2 1/2] pinctrl: samsung: don't truncate the last char Dan Carpenter
2015-06-22 23:51       ` Krzysztof Kozlowski
2015-07-16  8:21       ` Linus Walleij
2015-06-22 15:13     ` [patch v2 2/2] pinctrl: samsung: remove "out of memory" messages Dan Carpenter
2015-06-22 23:53       ` Krzysztof Kozlowski
2015-07-16  8:22       ` 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).