Skip to content

Commit f281d01

Browse files
tititiou36cminyard
authored andcommitted
ipmi: kcs_bmc: Fix a memory leak in the error handling path of 'kcs_bmc_serio_add_device()'
In the unlikely event where 'devm_kzalloc()' fails and 'kzalloc()' succeeds, 'port' would be leaking. Test each allocation separately to avoid the leak. Fixes: 3a3d2f6 ("ipmi: kcs_bmc: Add serio adaptor") Signed-off-by: Christophe JAILLET <[email protected]> Message-Id: <ecbfa15e94e64f4b878ecab1541ea46c74807670.1631048724.git.christophe.jaillet@wanadoo.fr> Reviewed-by: Andrew Jeffery <[email protected]> Signed-off-by: Corey Minyard <[email protected]>
1 parent fc4e784 commit f281d01

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

drivers/char/ipmi/kcs_bmc_serio.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,12 @@ static int kcs_bmc_serio_add_device(struct kcs_bmc_device *kcs_bmc)
7373
struct serio *port;
7474

7575
priv = devm_kzalloc(kcs_bmc->dev, sizeof(*priv), GFP_KERNEL);
76+
if (!priv)
77+
return -ENOMEM;
7678

7779
/* Use kzalloc() as the allocation is cleaned up with kfree() via serio_unregister_port() */
7880
port = kzalloc(sizeof(*port), GFP_KERNEL);
79-
if (!(priv && port))
81+
if (!port)
8082
return -ENOMEM;
8183

8284
port->id.type = SERIO_8042;

0 commit comments

Comments
 (0)