[PATCH v2] net: dsa: vsc73xx: Add null pointer check to vsc73xx_gpio_probe

From: Kunwu Chan
Date: Thu Jan 11 2024 - 02:21:24 EST


devm_kasprintf() returns a pointer to dynamically allocated memory
which can be NULL upon failure.

Cc: Kunwu Chan <kunwu.chan@xxxxxxxxxxx>
Signed-off-by: Kunwu Chan <chentao@xxxxxxxxxx>
Suggested-by: Jakub Kicinski <kuba@xxxxxxxxxx>

---
v2: Remove error print
---
drivers/net/dsa/vitesse-vsc73xx-core.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/net/dsa/vitesse-vsc73xx-core.c b/drivers/net/dsa/vitesse-vsc73xx-core.c
index e6f29e4e508c..571f037fe649 100644
--- a/drivers/net/dsa/vitesse-vsc73xx-core.c
+++ b/drivers/net/dsa/vitesse-vsc73xx-core.c
@@ -1135,6 +1135,8 @@ static int vsc73xx_gpio_probe(struct vsc73xx *vsc)

vsc->gc.label = devm_kasprintf(vsc->dev, GFP_KERNEL, "VSC%04x",
vsc->chipid);
+ if (!vsc->gc.label)
+ return -ENOMEM;
vsc->gc.ngpio = 4;
vsc->gc.owner = THIS_MODULE;
vsc->gc.parent = vsc->dev;
--
2.39.2