public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH AUTOSEL 6.2 1/9] pinctrl: at91: use devm_kasprintf() to avoid potential leaks (part 2)
@ 2023-05-10 20:49 Sasha Levin
  2023-05-10 20:49 ` [PATCH AUTOSEL 6.2 2/9] soundwire: dmi-quirks: add remapping for Intel 'Rooks County' NUC M15 Sasha Levin
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: Sasha Levin @ 2023-05-10 20:49 UTC (permalink / raw)
  To: linux-kernel, stable
  Cc: Andy Shevchenko, Claudiu Beznea, Linus Walleij, Sasha Levin,
	ludovic.desroches, nicolas.ferre, alexandre.belloni,
	linux-arm-kernel, linux-gpio

From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

[ Upstream commit f494c1913cbb34b9e2078b7b045c87c1ca6df791 ]

Use devm_kasprintf() instead of kasprintf() to avoid any potential
leaks. At the moment drivers have no remove functionality hence
there is no need for fixes tag.

While at it, switch to use devm_kasprintf_strarray().

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Claudiu Beznea <claudiu.beznea@microchip.com>
Tested-by: Claudiu Beznea <claudiu.beznea@microchip.com>
Link: https://lore.kernel.org/r/20230215134242.37618-2-andriy.shevchenko@linux.intel.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/pinctrl/pinctrl-at91.c | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-at91.c b/drivers/pinctrl/pinctrl-at91.c
index c405296e49896..2a081b13846e2 100644
--- a/drivers/pinctrl/pinctrl-at91.c
+++ b/drivers/pinctrl/pinctrl-at91.c
@@ -18,6 +18,7 @@
 #include <linux/pm.h>
 #include <linux/seq_file.h>
 #include <linux/slab.h>
+#include <linux/string_helpers.h>
 
 /* Since we request GPIOs from ourself */
 #include <linux/pinctrl/consumer.h>
@@ -1364,6 +1365,7 @@ static int at91_pinctrl_probe_dt(struct platform_device *pdev,
 
 static int at91_pinctrl_probe(struct platform_device *pdev)
 {
+	struct device *dev = &pdev->dev;
 	struct at91_pinctrl *info;
 	struct pinctrl_pin_desc *pdesc;
 	int ret, i, j, k, ngpio_chips_enabled = 0;
@@ -1404,9 +1406,19 @@ static int at91_pinctrl_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	for (i = 0, k = 0; i < gpio_banks; i++) {
+		char **names;
+
+		names = devm_kasprintf_strarray(dev, "pio", MAX_NB_GPIO_PER_BANK);
+		if (!names)
+			return -ENOMEM;
+
 		for (j = 0; j < MAX_NB_GPIO_PER_BANK; j++, k++) {
+			char *name = names[j];
+
+			strreplace(name, '-', i + 'A');
+
 			pdesc->number = k;
-			pdesc->name = kasprintf(GFP_KERNEL, "pio%c%d", i + 'A', j);
+			pdesc->name = name;
 			pdesc++;
 		}
 	}
@@ -1807,7 +1819,8 @@ static const struct of_device_id at91_gpio_of_match[] = {
 
 static int at91_gpio_probe(struct platform_device *pdev)
 {
-	struct device_node *np = pdev->dev.of_node;
+	struct device *dev = &pdev->dev;
+	struct device_node *np = dev->of_node;
 	struct at91_gpio_chip *at91_chip = NULL;
 	struct gpio_chip *chip;
 	struct pinctrl_gpio_range *range;
@@ -1876,16 +1889,14 @@ static int at91_gpio_probe(struct platform_device *pdev)
 			chip->ngpio = ngpio;
 	}
 
-	names = devm_kcalloc(&pdev->dev, chip->ngpio, sizeof(char *),
-			     GFP_KERNEL);
-
+	names = devm_kasprintf_strarray(dev, "pio", chip->ngpio);
 	if (!names) {
 		ret = -ENOMEM;
 		goto clk_enable_err;
 	}
 
 	for (i = 0; i < chip->ngpio; i++)
-		names[i] = devm_kasprintf(&pdev->dev, GFP_KERNEL, "pio%c%d", alias_idx + 'A', i);
+		strreplace(names[i], '-', alias_idx + 'A');
 
 	chip->names = (const char *const *)names;
 
-- 
2.39.2


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

end of thread, other threads:[~2023-05-10 20:52 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-10 20:49 [PATCH AUTOSEL 6.2 1/9] pinctrl: at91: use devm_kasprintf() to avoid potential leaks (part 2) Sasha Levin
2023-05-10 20:49 ` [PATCH AUTOSEL 6.2 2/9] soundwire: dmi-quirks: add remapping for Intel 'Rooks County' NUC M15 Sasha Levin
2023-05-10 20:49 ` [PATCH AUTOSEL 6.2 3/9] phy: st: miphy28lp: use _poll_timeout functions for waits Sasha Levin
2023-05-10 20:49 ` [PATCH AUTOSEL 6.2 4/9] soundwire: qcom: gracefully handle too many ports in DT Sasha Levin
2023-05-10 20:49 ` [PATCH AUTOSEL 6.2 5/9] soundwire: bus: Fix unbalanced pm_runtime_put() causing usage count underflow Sasha Levin
2023-05-10 20:49 ` [PATCH AUTOSEL 6.2 6/9] mfd: intel_soc_pmic_chtwc: Add Lenovo Yoga Book X90F to intel_cht_wc_models Sasha Levin
2023-05-10 20:49 ` [PATCH AUTOSEL 6.2 7/9] mfd: dln2: Fix memory leak in dln2_probe() Sasha Levin
2023-05-10 20:49 ` [PATCH AUTOSEL 6.2 8/9] mfd: intel-lpss: Add Intel Meteor Lake PCH-S LPSS PCI IDs Sasha Levin
2023-05-10 20:49 ` [PATCH AUTOSEL 6.2 9/9] parisc: Replace regular spinlock with spin_trylock on panic path Sasha Levin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox