Skip to content
/ linux Public
forked from torvalds/linux

Commit

Permalink
rapidio: rio: fix possible name leak in rio_register_mport()
Browse files Browse the repository at this point in the history
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/[email protected]
Fixes: 2aaf308 ("rapidio: rework device hierarchy and introduce mport class of devices")
Signed-off-by: Yang Yingliang <[email protected]>
Cc: Alexandre Bounine <[email protected]>
Cc: Matt Porter <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
  • Loading branch information
Yang Yingliang authored and akpm00 committed Dec 1, 2022
1 parent f9574cd commit e92a216
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions drivers/rapidio/rio.c
Original file line number Diff line number Diff line change
Expand Up @@ -2186,11 +2186,16 @@ int rio_register_mport(struct rio_mport *port)
atomic_set(&port->state, RIO_DEVICE_RUNNING);

res = device_register(&port->dev);
if (res)
if (res) {
dev_err(&port->dev, "RIO: mport%d registration failed ERR=%d\n",
port->id, res);
else
mutex_lock(&rio_mport_list_lock);
list_del(&port->node);
mutex_unlock(&rio_mport_list_lock);
put_device(&port->dev);
} else {
dev_dbg(&port->dev, "RIO: registered mport%d\n", port->id);
}

return res;
}
Expand Down

0 comments on commit e92a216

Please sign in to comment.