Skip to content

Commit

Permalink
pinctrl: armada-37xx: Switch to use devm_kasprintf_strarray()
Browse files Browse the repository at this point in the history
Since we have a generic helper, switch the module to use it.

As a side effect, add check for the memory allocation failures and
cleanup it either in error case or when driver is unloading.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Gregory CLEMENT <gregory.clement@bootlin.com>
  • Loading branch information
Andy Shevchenko committed Nov 18, 2021
1 parent 06cb10e commit b32b195
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions drivers/pinctrl/mvebu/pinctrl-armada-37xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <linux/platform_device.h>
#include <linux/regmap.h>
#include <linux/slab.h>
#include <linux/string_helpers.h>

#include "../pinctrl-utils.h"

Expand Down Expand Up @@ -951,6 +952,7 @@ static int armada_37xx_pinctrl_register(struct platform_device *pdev,
struct pinctrl_desc *ctrldesc = &info->pctl;
struct pinctrl_pin_desc *pindesc, *pdesc;
struct device *dev = &pdev->dev;
char **pin_names;
int pin, ret;

info->groups = pin_data->groups;
Expand All @@ -969,11 +971,14 @@ static int armada_37xx_pinctrl_register(struct platform_device *pdev,
ctrldesc->pins = pindesc;
ctrldesc->npins = pin_data->nr_pins;

pin_names = devm_kasprintf_strarray(dev, pin_data->name, pin_data->nr_pins);
if (IS_ERR(pin_names))
return PTR_ERR(pin_names);

pdesc = pindesc;
for (pin = 0; pin < pin_data->nr_pins; pin++) {
pdesc->number = pin;
pdesc->name = kasprintf(GFP_KERNEL, "%s-%d",
pin_data->name, pin);
pdesc->name = pin_names[pin];
pdesc++;
}

Expand Down

0 comments on commit b32b195

Please sign in to comment.