[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250331151238.13703-1-bsdhenrymartin@gmail.com>
Date: Mon, 31 Mar 2025 23:12:38 +0800
From: Henry Martin <bsdhenrymartin@...il.com>
To: joel@....id.au,
andrew@...econstruct.com.au
Cc: bsdhenrymartin@...il.com,
u.kleine-koenig@...libre.com,
arnd@...db.de,
herve.codina@...tlin.com,
gsomlo@...il.com,
linux-arm-kernel@...ts.infradead.org,
linux-aspeed@...ts.ozlabs.org,
linux-kernel@...r.kernel.org
Subject: [PATCH v2] drivers/misc: Add NULL check in aspeed_lpc_enable_snoop
devm_kasprintf() returns NULL if memory allocation fails. Currently,
aspeed_lpc_enable_snoop() does not check for this case, leading to a NULL
pointer dereference.
Add NULL check after devm_kasprintf() to prevent this issue.
Fixes: 3772e5da4454 ("drivers/misc: Aspeed LPC snoop output using misc chardev")
Signed-off-by: Henry Martin <bsdhenrymartin@...il.com>
---
V1 -> V2: Removed blank line between tags.
Signed-off-by: Henry Martin <bsdhenrymartin@...il.com>
---
drivers/soc/aspeed/aspeed-lpc-snoop.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/soc/aspeed/aspeed-lpc-snoop.c b/drivers/soc/aspeed/aspeed-lpc-snoop.c
index 9ab5ba9cf1d6..376b3a910797 100644
--- a/drivers/soc/aspeed/aspeed-lpc-snoop.c
+++ b/drivers/soc/aspeed/aspeed-lpc-snoop.c
@@ -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);
--
2.34.1
Powered by blists - more mailing lists