]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
pcmcia: ds: fix possible name leak in error path in pcmcia_device_add()
authorYang Yingliang <yangyingliang@huawei.com>
Sat, 12 Nov 2022 09:29:24 +0000 (17:29 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 20 Nov 2023 09:27:35 +0000 (10:27 +0100)
commit2527dddb4efc5a9cddcf478fd787090bef7f52ef
tree1e50ea2d61514241a9aed2a2d1e1394a3fa6682d
parent0dea47ba11a6b715e85eba9f84153949fac476d6
pcmcia: ds: fix possible name leak in error path in pcmcia_device_add()

[ Upstream commit 99e1241049a92dd3e9a90a0f91e32ce390133278 ]

Afer commit 1fa5ae857bb1 ("driver core: get rid of struct device's
bus_id string array"), the name of device is allocated dynamically.
Therefore, it needs to be freed, which is done by the driver core for
us once all references to the device are gone. Therefore, move the
dev_set_name() call immediately before the call device_register(), which
either succeeds (then the freeing will be done upon subsequent remvoal),
or puts the reference in the error call. Also, it is not unusual that the
return value of dev_set_name is not checked.

Fixes: 1fa5ae857bb1 ("driver core: get rid of struct device's bus_id string array")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
[linux@dominikbrodowski.net: simplification, commit message modified]
Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/pcmcia/ds.c