mirror of
https://github.com/torvalds/linux.git
synced 2026-07-27 09:36:22 +02:00
net: dsa: realtek: fix memory leak in rtl8366rb_setup_led()
led_classdev_register_ext() only reads init_data.devicename - it never
stores the pointer. However, the caller allocated devicename with
kasprintf() but never freed it, leaking the string memory.
Fix it with a stack buffer to avoid dynamic buffers completely.
Fixes: 32d6170054 ("net: dsa: realtek: add LED drivers for rtl8366rb")
Signed-off-by: David Yang <mmyangfl@gmail.com>
Reviewed-by: Linus Walleij <linusw@kernel.org>
Link: https://patch.msgid.link/20260618140200.1888707-1-mmyangfl@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
parent
db818b0e8a
commit
056a5087d8
|
|
@ -89,6 +89,7 @@ static int rtl8366rb_setup_led(struct realtek_priv *priv, struct dsa_port *dp,
|
|||
struct led_init_data init_data = { };
|
||||
enum led_default_state state;
|
||||
struct rtl8366rb_led *led;
|
||||
char name[64];
|
||||
u32 led_group;
|
||||
int ret;
|
||||
|
||||
|
|
@ -129,10 +130,9 @@ static int rtl8366rb_setup_led(struct realtek_priv *priv, struct dsa_port *dp,
|
|||
init_data.fwnode = led_fwnode;
|
||||
init_data.devname_mandatory = true;
|
||||
|
||||
init_data.devicename = kasprintf(GFP_KERNEL, "Realtek-%d:0%d:%d",
|
||||
dp->ds->index, dp->index, led_group);
|
||||
if (!init_data.devicename)
|
||||
return -ENOMEM;
|
||||
snprintf(name, sizeof(name), "Realtek-%d:0%d:%d",
|
||||
dp->ds->index, dp->index, led_group);
|
||||
init_data.devicename = name;
|
||||
|
||||
ret = devm_led_classdev_register_ext(priv->dev, &led->cdev, &init_data);
|
||||
if (ret) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user