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

rapidio: rio: fix possible name leak in rio_register_mport()

If device_register() returns error, the name allocated by dev_set_name()
need be freed. It should use put_device() to give up the reference in the
error path, so that the name can be freed in kobject_cleanup(), and
list_del() is called to delete the port from rio_mports.

Link: https://lkml.kernel.org/r/20221114152636.2939035-3-yangyingliang@huawei.com
Fixes: 2aaf308b95b2 ("rapidio: rework device hierarchy and introduce mport class of devices")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Cc: Alexandre Bounine <alex.bou9@gmail.com>
Cc: Matt Porter <mporter@kernel.crashing.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Yang Yingliang and committed by
Andrew Morton
e92a216d f9574cd4

+7 -2
+7 -2
drivers/rapidio/rio.c
··· 2186 2186 atomic_set(&port->state, RIO_DEVICE_RUNNING); 2187 2187 2188 2188 res = device_register(&port->dev); 2189 - if (res) 2189 + if (res) { 2190 2190 dev_err(&port->dev, "RIO: mport%d registration failed ERR=%d\n", 2191 2191 port->id, res); 2192 - else 2192 + mutex_lock(&rio_mport_list_lock); 2193 + list_del(&port->node); 2194 + mutex_unlock(&rio_mport_list_lock); 2195 + put_device(&port->dev); 2196 + } else { 2193 2197 dev_dbg(&port->dev, "RIO: registered mport%d\n", port->id); 2198 + } 2194 2199 2195 2200 return res; 2196 2201 }