Skip to content

Commit

Permalink
pinctrl: at91: use devm_kasprintf() to avoid potential leaks (part 2)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
andy-shev authored and intel-lab-lkp committed Feb 10, 2023
1 parent 1ec033f commit 0562771
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions drivers/pinctrl/pinctrl-at91.c
Expand Up @@ -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>
Expand Down Expand Up @@ -1371,6 +1372,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;
Expand All @@ -1394,9 +1396,19 @@ static int at91_pinctrl_probe(struct platform_device *pdev)
return -ENOMEM;

for (i = 0, k = 0; i < gpio_banks; i++) {
char **pin_names;

pin_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 *pin_name = pin_names[j];

strreplace(pin_name, '-', i + 'A');

pdesc->number = k;
pdesc->name = kasprintf(GFP_KERNEL, "pio%c%d", i + 'A', j);
pdesc->name = pin_name;
pdesc++;
}
}
Expand Down Expand Up @@ -1797,7 +1809,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;
Expand Down Expand Up @@ -1866,16 +1879,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('-', alias_idx + 'A');

chip->names = (const char *const *)names;

Expand Down

0 comments on commit 0562771

Please sign in to comment.