rapidio: rio_mport_cdev: fix possible name leak in rio_mport_add_riodev()
PATCH 1/2 rapidio: rio_mport_cdev: fix possible name leak in rio_mport_add_riodev()
If rio_add_net() returns error in rio_mport_add_riodev(), the name allocated by dev_set_name() need be freed.
As comment of device_register() says, it should use put_device() to give up the reference in the error path. So fix this by calling put_device(), then the name can be freed in kobject_cleanup(), and the 'net' is freed in rio_release_net().
--- drivers/rapidio/devices/rio_mport_cdev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/rapidio/devices/rio_mport_cdev.c +1 -1
@@ -1740,7 +1740,7 @@ static int rio_mport_add_riodev(struct mport_cdev_priv *priv, err =rio_add_net (net);if (err) {rmcd_debug (RDEV ,"failed to register net, err=%d" , err); -kfree (net); +put_device (&net->dev); goto cleanup; } }
Signature · 1 line
2.25.1
PATCH 2/2 rapidio: rio-scan: fix error handling in rio_scan_alloc_net()
This patch fixes two error handling issues:
rio_free_net() calls device_unregister(), if allocate idtab fails in rio_scan_alloc_net(), the device has not been registered, in this error case, can not call rio_free_net(), use kfree() instead.
If rio_add_net() returns error in rio_scan_alloc_net(), it's need call put_device() to free memory allocated in rio_alloc_net() and dev_set_name().
--- drivers/rapidio/rio-scan.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/rapidio/rio-scan.c +5 -2
@@ -850,7 +850,7 @@ static struct rio_net *rio_scan_alloc_net(struct rio_mport *mport,if (idtab ==NULL ) {pr_err ("RIO: failed to allocate destID table\n" ); -rio_free_net (net); +kfree (net); net =NULL ; }else { net->enum_data = idtab;
@@ -867,7 +867,10 @@ static struct rio_net *rio_scan_alloc_net(struct rio_mport *mport,dev_set_name (&net->dev,"rnet_%d" , net->id); net->dev.parent = &mport->dev; net->dev.release = rio_scan_release_dev; -rio_add_net (net); +if (rio_add_net (net)) { +put_device (&net->dev); + net =NULL ; + } }return net;
Signature · 1 line
2.25.1