Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: 3a3d2f6a4c64 ("ipmi: kcs_bmc: Add serio adaptor")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Message-Id: <ecbfa15e94e64f4b878ecab1541ea46c74807670.1631048724.git.christophe.jaillet@wanadoo.fr>
Reviewed-by: Andrew Jeffery <andrew@aj.id.au>
Signed-off-by: Corey Minyard <cminyard@mvista.com>

authored by

Christophe JAILLET and committed by
Corey Minyard
f281d010 fc4e7848

+3 -1
+3 -1
drivers/char/ipmi/kcs_bmc_serio.c
··· 73 73 struct serio *port; 74 74 75 75 priv = devm_kzalloc(kcs_bmc->dev, sizeof(*priv), GFP_KERNEL); 76 + if (!priv) 77 + return -ENOMEM; 76 78 77 79 /* Use kzalloc() as the allocation is cleaned up with kfree() via serio_unregister_port() */ 78 80 port = kzalloc(sizeof(*port), GFP_KERNEL); 79 - if (!(priv && port)) 81 + if (!port) 80 82 return -ENOMEM; 81 83 82 84 port->id.type = SERIO_8042;