asahi.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH] pinctrl: apple-gpio: Fix null pointer dereference in apple_gpio_pinctrl_probe()
@ 2024-04-09 11:02 Ma Ke
  2024-04-09 11:53 ` Krzysztof Kozlowski
  0 siblings, 1 reply; 2+ messages in thread
From: Ma Ke @ 2024-04-09 11:02 UTC (permalink / raw)
  To: marcan, sven, alyssa, linus.walleij
  Cc: asahi, linux-arm-kernel, linux-gpio, linux-kernel, Ma Ke

devm_kasprintf() returns a pointer to dynamically allocated memory which
can be NULL upon failure. We add a check to ensure that failure does not
occur.

Signed-off-by: Ma Ke <make_ruc2021@163.com>
---
 drivers/pinctrl/pinctrl-apple-gpio.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/pinctrl/pinctrl-apple-gpio.c b/drivers/pinctrl/pinctrl-apple-gpio.c
index 3751c7de37aa..af2f90d1950f 100644
--- a/drivers/pinctrl/pinctrl-apple-gpio.c
+++ b/drivers/pinctrl/pinctrl-apple-gpio.c
@@ -474,6 +474,8 @@ 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;
-- 
2.37.2


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

* Re: [PATCH] pinctrl: apple-gpio: Fix null pointer dereference in apple_gpio_pinctrl_probe()
  2024-04-09 11:02 [PATCH] pinctrl: apple-gpio: Fix null pointer dereference in apple_gpio_pinctrl_probe() Ma Ke
@ 2024-04-09 11:53 ` Krzysztof Kozlowski
  0 siblings, 0 replies; 2+ messages in thread
From: Krzysztof Kozlowski @ 2024-04-09 11:53 UTC (permalink / raw)
  To: Ma Ke, marcan, sven, alyssa, linus.walleij
  Cc: asahi, linux-arm-kernel, linux-gpio, linux-kernel

On 09/04/2024 13:02, Ma Ke wrote:
> devm_kasprintf() returns a pointer to dynamically allocated memory which
> can be NULL upon failure. We add a check to ensure that failure does not
> occur.
> 

Subject: I doubt that there is null pointer dereference... Don't just
copy existing commit msgs or subjects without adjusting to real case.

> Signed-off-by: Ma Ke <make_ruc2021@163.com>
> ---
>  drivers/pinctrl/pinctrl-apple-gpio.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/pinctrl/pinctrl-apple-gpio.c b/drivers/pinctrl/pinctrl-apple-gpio.c
> index 3751c7de37aa..af2f90d1950f 100644
> --- a/drivers/pinctrl/pinctrl-apple-gpio.c
> +++ b/drivers/pinctrl/pinctrl-apple-gpio.c
> @@ -474,6 +474,8 @@ 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;

The check is a bit later, so please be more precise how do you fix it
and how did you reproduced it.

Maybe checking earlier is reasonable, maybe is redundant. You did not
address it...

Best regards,
Krzysztof


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

end of thread, other threads:[~2024-04-09 11:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-09 11:02 [PATCH] pinctrl: apple-gpio: Fix null pointer dereference in apple_gpio_pinctrl_probe() Ma Ke
2024-04-09 11:53 ` Krzysztof Kozlowski

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).