diff mbox series

gpio: grgpio: Add NULL check in grgpio_probe

Message ID 20241114091822.78199-1-hanchunchao@inspur.com
State New
Headers show
Series gpio: grgpio: Add NULL check in grgpio_probe | expand

Commit Message

Charles Han Nov. 14, 2024, 9:18 a.m. UTC
devm_kasprintf() can return a NULL pointer on failure,but this
returned value in grgpio_probe is not checked.
Add NULL check in grgpio_probe, to handle kernel NULL
pointer dereference error.

Fixes: 7eb6ce2f2723 ("gpio: Convert to using %pOF instead of full_name")
Signed-off-by: Charles Han <hanchunchao@inspur.com>
---
 drivers/gpio/gpio-grgpio.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Bartosz Golaszewski Nov. 14, 2024, 1:18 p.m. UTC | #1
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>


On Thu, 14 Nov 2024 17:18:22 +0800, Charles Han wrote:
> devm_kasprintf() can return a NULL pointer on failure,but this
> returned value in grgpio_probe is not checked.
> Add NULL check in grgpio_probe, to handle kernel NULL
> pointer dereference error.
> 
> 

Good catch. I would typically send it upstream quickly through my fixes
branch but I'm about to make my big PR for Linus so I'l route it together
with stuff aimed for v6.13.

Applied, thanks!

[1/1] gpio: grgpio: Add NULL check in grgpio_probe
      commit: 7445640b245877a8d248b6ca4153dd532e79a5d6

Best regards,
diff mbox series

Patch

diff --git a/drivers/gpio/gpio-grgpio.c b/drivers/gpio/gpio-grgpio.c
index 7ffe59d845f0..169f33c41c59 100644
--- a/drivers/gpio/gpio-grgpio.c
+++ b/drivers/gpio/gpio-grgpio.c
@@ -369,6 +369,9 @@  static int grgpio_probe(struct platform_device *ofdev)
 	gc->owner = THIS_MODULE;
 	gc->to_irq = grgpio_to_irq;
 	gc->label = devm_kasprintf(dev, GFP_KERNEL, "%pOF", np);
+	if (!gc->label)
+		return -ENOMEM;
+
 	gc->base = -1;
 
 	err = of_property_read_u32(np, "nbits", &prop);