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

Configure Feed

Select the types of activity you want to include in your feed.

most: core: fix resource leak in most_register_interface error paths

The function most_register_interface() did not correctly release resources
if it failed early (before registering the device). In these cases, it
returned an error code immediately, leaking the memory allocated for the
interface.

Fix this by initializing the device early via device_initialize() and
calling put_device() on all error paths.

The most_register_interface() is expected to call put_device() on
error which frees the resources allocated in the caller. The
put_device() either calls release_mdev() or dim2_release(),
depending on the caller.

Switch to using device_add() instead of device_register() to handle
the split initialization.

Acked-by: Abdun Nihaal <abdun.nihaal@gmail.com>
Signed-off-by: Navaneeth K <knavaneeth786@gmail.com>
Reviewed-by: Dan Carpenter <dan.carpenter@linaro.org>
Link: https://patch.msgid.link/20251127165337.19172-1-knavaneeth786@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Navaneeth K and committed by
Greg Kroah-Hartman
1f4c9d8a 9448598b

+5 -1
+5 -1
drivers/most/core.c
··· 1286 1286 !iface->poison_channel || (iface->num_channels > MAX_CHANNELS)) 1287 1287 return -EINVAL; 1288 1288 1289 + device_initialize(iface->dev); 1290 + 1289 1291 id = ida_alloc(&mdev_id, GFP_KERNEL); 1290 1292 if (id < 0) { 1291 1293 dev_err(iface->dev, "Failed to allocate device ID\n"); 1294 + put_device(iface->dev); 1292 1295 return id; 1293 1296 } 1294 1297 1295 1298 iface->p = kzalloc(sizeof(*iface->p), GFP_KERNEL); 1296 1299 if (!iface->p) { 1297 1300 ida_free(&mdev_id, id); 1301 + put_device(iface->dev); 1298 1302 return -ENOMEM; 1299 1303 } 1300 1304 ··· 1308 1304 iface->dev->bus = &mostbus; 1309 1305 iface->dev->groups = interface_attr_groups; 1310 1306 dev_set_drvdata(iface->dev, iface); 1311 - if (device_register(iface->dev)) { 1307 + if (device_add(iface->dev)) { 1312 1308 dev_err(iface->dev, "Failed to register interface device\n"); 1313 1309 kfree(iface->p); 1314 1310 put_device(iface->dev);