Skip to contentSkip to conversation

drivers/misc: Add NULL check in aspeed_lpc_enable_snoop

PATCH Superseded Henry Martin 2 participants 2 messages Mar 31, 2025 Arm/Aspeed machine support

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers/misc: Add NULL check in aspeed_lpc_enable_snoop

When devm_kasprintf() fails, it returns a NULL pointer. However, this return value is not properly checked in the function aspeed_lpc_enable_snoop.

A NULL check should be added after the devm_kasprintf() to prevent potential NULL pointer dereference error.

Fixes 3772e5da44542 ("Aspeed LPC snoop output using misc chardev")
---
 drivers/soc/aspeed/aspeed-lpc-snoop.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/soc/aspeed/aspeed-lpc-snoop.c +2 -0
index 9ab5ba9cf1d6..376b3a910797 100644
@@ -200,6 +200,8 @@ static int aspeed_lpc_enable_snoop(struct aspeed_lpc_snoop *lpc_snoop,
 	lpc_snoop->chan[channel].miscdev.minor = MISC_DYNAMIC_MINOR;
 	lpc_snoop->chan[channel].miscdev.name =
 		devm_kasprintf(dev, GFP_KERNEL, "%s%d", DEVICE_NAME, channel);
+	if (!lpc_snoop->chan[channel].miscdev.name)
+		return -ENOMEM;
 	lpc_snoop->chan[channel].miscdev.fops = &snoop_fops;
 	lpc_snoop->chan[channel].miscdev.parent = dev;
 	rc = misc_register(&lpc_snoop->chan[channel].miscdev);
Signature · 1 line
2.34.1
#1 lore raw
Quoted 4 lines · Henry Martin

When devm_kasprintf() fails, it returns a NULL pointer. However, this return value is not properly checked in the function aspeed_lpc_enable_snoop.

A NULL check should be added after the devm_kasprintf() to prevent potential NULL pointer dereference error.

Same comments.

Quoted 2 lines
Fixes 3772e5da44542 ("Aspeed LPC snoop output using misc chardev")

There is never a blank line between tags.

Quoted 10 lines
---
 drivers/soc/aspeed/aspeed-lpc-snoop.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/soc/aspeed/aspeed-lpc-snoop.c +0 -0
index 9ab5ba9cf1d6..376b3a910797 100644

drivers/soc/aspeed/aspeed-lpc-snoop.c static int aspeed_lpc_enable_snoop(struct aspeed_lpc_snoop *lpc_snoop, · line 204

Quoted 5 lines
drivers/soc/aspeed/aspeed-lpc-snoop.c +2 -0
@@ -200,6 +200,8 @@ static int aspeed_lpc_enable_snoop(struct aspeed_lpc_snoop *lpc_snoop,
 	lpc_snoop->chan[channel].miscdev.minor = MISC_DYNAMIC_MINOR;
 	lpc_snoop->chan[channel].miscdev.name =
 		devm_kasprintf(dev, GFP_KERNEL, "%s%d", DEVICE_NAME, channel);
+	if (!lpc_snoop->chan[channel].miscdev.name)
+		return -ENOMEM;

Missing cleanup.

Best regards,
Krzysztof