Merge branch 'fix-some-issues-in-netdevsim-driver'

Zhengchao Shao says:

====================
fix some issues in netdevsim driver

When strace tool is used to perform memory injection, memory leaks and
files not removed issues are found. Fix them.
====================

Link: https://lore.kernel.org/r/20221026014642.116261-1-shaozhengchao@huawei.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Jakub Kicinski 2022-10-27 10:47:31 -07:00
commit 9ddcead06d

View File

@ -309,8 +309,10 @@ static int nsim_dev_debugfs_init(struct nsim_dev *nsim_dev)
if (IS_ERR(nsim_dev->ddir))
return PTR_ERR(nsim_dev->ddir);
nsim_dev->ports_ddir = debugfs_create_dir("ports", nsim_dev->ddir);
if (IS_ERR(nsim_dev->ports_ddir))
return PTR_ERR(nsim_dev->ports_ddir);
if (IS_ERR(nsim_dev->ports_ddir)) {
err = PTR_ERR(nsim_dev->ports_ddir);
goto err_ddir;
}
debugfs_create_bool("fw_update_status", 0600, nsim_dev->ddir,
&nsim_dev->fw_update_status);
debugfs_create_u32("fw_update_overwrite_mask", 0600, nsim_dev->ddir,
@ -346,7 +348,7 @@ static int nsim_dev_debugfs_init(struct nsim_dev *nsim_dev)
nsim_dev->nodes_ddir = debugfs_create_dir("rate_nodes", nsim_dev->ddir);
if (IS_ERR(nsim_dev->nodes_ddir)) {
err = PTR_ERR(nsim_dev->nodes_ddir);
goto err_out;
goto err_ports_ddir;
}
debugfs_create_bool("fail_trap_drop_counter_get", 0600,
nsim_dev->ddir,
@ -354,8 +356,9 @@ static int nsim_dev_debugfs_init(struct nsim_dev *nsim_dev)
nsim_udp_tunnels_debugfs_create(nsim_dev);
return 0;
err_out:
err_ports_ddir:
debugfs_remove_recursive(nsim_dev->ports_ddir);
err_ddir:
debugfs_remove_recursive(nsim_dev->ddir);
return err;
}
@ -442,7 +445,7 @@ static int nsim_dev_resources_register(struct devlink *devlink)
&params);
if (err) {
pr_err("Failed to register IPv4 top resource\n");
goto out;
goto err_out;
}
err = devl_resource_register(devlink, "fib", (u64)-1,
@ -450,7 +453,7 @@ static int nsim_dev_resources_register(struct devlink *devlink)
NSIM_RESOURCE_IPV4, &params);
if (err) {
pr_err("Failed to register IPv4 FIB resource\n");
return err;
goto err_out;
}
err = devl_resource_register(devlink, "fib-rules", (u64)-1,
@ -458,7 +461,7 @@ static int nsim_dev_resources_register(struct devlink *devlink)
NSIM_RESOURCE_IPV4, &params);
if (err) {
pr_err("Failed to register IPv4 FIB rules resource\n");
return err;
goto err_out;
}
/* Resources for IPv6 */
@ -468,7 +471,7 @@ static int nsim_dev_resources_register(struct devlink *devlink)
&params);
if (err) {
pr_err("Failed to register IPv6 top resource\n");
goto out;
goto err_out;
}
err = devl_resource_register(devlink, "fib", (u64)-1,
@ -476,7 +479,7 @@ static int nsim_dev_resources_register(struct devlink *devlink)
NSIM_RESOURCE_IPV6, &params);
if (err) {
pr_err("Failed to register IPv6 FIB resource\n");
return err;
goto err_out;
}
err = devl_resource_register(devlink, "fib-rules", (u64)-1,
@ -484,7 +487,7 @@ static int nsim_dev_resources_register(struct devlink *devlink)
NSIM_RESOURCE_IPV6, &params);
if (err) {
pr_err("Failed to register IPv6 FIB rules resource\n");
return err;
goto err_out;
}
/* Resources for nexthops */
@ -492,8 +495,14 @@ static int nsim_dev_resources_register(struct devlink *devlink)
NSIM_RESOURCE_NEXTHOPS,
DEVLINK_RESOURCE_ID_PARENT_TOP,
&params);
if (err) {
pr_err("Failed to register NEXTHOPS resource\n");
goto err_out;
}
return 0;
out:
err_out:
devl_resources_unregister(devlink);
return err;
}