diff mbox series

[RESEND] pinctrl: check devm_kasprintf() returned value

Message ID 20240912020840.1763252-1-make24@iscas.ac.cn
State New
Headers show
Series [RESEND] pinctrl: check devm_kasprintf() returned value | expand

Commit Message

Ma Ke Sept. 12, 2024, 2:08 a.m. UTC
devm_kasprintf() can return a NULL pointer on failure but this returned
value is not checked. Fix this lack and check the returned value.

Found by code review.

Cc: stable@vger.kernel.org
Fixes: a0f160ffcb83 ("pinctrl: add pinctrl/GPIO driver for Apple SoCs")
Signed-off-by: Ma Ke <make24@iscas.ac.cn>
---
 drivers/pinctrl/pinctrl-apple-gpio.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Christophe JAILLET Sept. 13, 2024, 5:26 a.m. UTC | #1
Le 12/09/2024 à 04:08, Ma Ke a écrit :
> devm_kasprintf() can return a NULL pointer on failure but this returned
> value is not checked. Fix this lack and check the returned value.
> 
> Found by code review.
> 
> Cc: stable@vger.kernel.org
> Fixes: a0f160ffcb83 ("pinctrl: add pinctrl/GPIO driver for Apple SoCs")
> Signed-off-by: Ma Ke <make24@iscas.ac.cn>
> ---
>   drivers/pinctrl/pinctrl-apple-gpio.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/pinctrl/pinctrl-apple-gpio.c b/drivers/pinctrl/pinctrl-apple-gpio.c
> index 3751c7de37aa..f861e63f4115 100644
> --- a/drivers/pinctrl/pinctrl-apple-gpio.c
> +++ b/drivers/pinctrl/pinctrl-apple-gpio.c
> @@ -474,6 +474,9 @@ static int apple_gpio_pinctrl_probe(struct platform_device *pdev)
>   	for (i = 0; i < npins; i++) {
>   		pins[i].number = i;
>   		pins[i].name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "PIN%u", i);
> +		if (!pins[i].name)
> +			return -ENOMEM;
> +
>   		pins[i].drv_data = pctl;
>   		pin_names[i] = pins[i].name;
>   		pin_nums[i] = i;

Hi,

this is not really an issue. if pin[i].name is NULL, then 
pinctrl_generic_add_group() below will fail with -EINVAL.
So your change only returns a more correct error code and saves a few 
cycles in case of (unlikely) memory allocation issue.

Anyway:
Reviewed-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

CJ
diff mbox series

Patch

diff --git a/drivers/pinctrl/pinctrl-apple-gpio.c b/drivers/pinctrl/pinctrl-apple-gpio.c
index 3751c7de37aa..f861e63f4115 100644
--- a/drivers/pinctrl/pinctrl-apple-gpio.c
+++ b/drivers/pinctrl/pinctrl-apple-gpio.c
@@ -474,6 +474,9 @@  static int apple_gpio_pinctrl_probe(struct platform_device *pdev)
 	for (i = 0; i < npins; i++) {
 		pins[i].number = i;
 		pins[i].name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "PIN%u", i);
+		if (!pins[i].name)
+			return -ENOMEM;
+
 		pins[i].drv_data = pctl;
 		pin_names[i] = pins[i].name;
 		pin_nums[i] = i;