mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-22 18:44:44 +08:00
RDMA/rtrs-clt: Refactor the failure cases in alloc_clt
Make all failure cases go to the common path to avoid duplicate code.
And some issued existed before.
1. clt need to be freed to avoid memory leak.
2. return ERR_PTR(-ENOMEM) if kobject_create_and_add fails, because
rtrs_clt_open checks the return value of by call "IS_ERR(clt)".
Fixes: 6a98d71dae
("RDMA/rtrs: client: main functionality")
Link: https://lore.kernel.org/r/20201217141915.56989-15-jinpu.wang@cloud.ionos.com
Signed-off-by: Guoqing Jiang <guoqing.jiang@cloud.ionos.com>
Reviewed-by: Md Haris Iqbal <haris.iqbal@cloud.ionos.com>
Signed-off-by: Jack Wang <jinpu.wang@cloud.ionos.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
This commit is contained in:
parent
8537f2de65
commit
eab0982466
@ -2568,11 +2568,8 @@ static struct rtrs_clt *alloc_clt(const char *sessname, size_t paths_num,
|
||||
clt->dev.class = rtrs_clt_dev_class;
|
||||
clt->dev.release = rtrs_clt_dev_release;
|
||||
err = dev_set_name(&clt->dev, "%s", sessname);
|
||||
if (err) {
|
||||
free_percpu(clt->pcpu_path);
|
||||
kfree(clt);
|
||||
return ERR_PTR(err);
|
||||
}
|
||||
if (err)
|
||||
goto err;
|
||||
/*
|
||||
* Suppress user space notification until
|
||||
* sysfs files are created
|
||||
@ -2580,29 +2577,31 @@ static struct rtrs_clt *alloc_clt(const char *sessname, size_t paths_num,
|
||||
dev_set_uevent_suppress(&clt->dev, true);
|
||||
err = device_register(&clt->dev);
|
||||
if (err) {
|
||||
free_percpu(clt->pcpu_path);
|
||||
put_device(&clt->dev);
|
||||
return ERR_PTR(err);
|
||||
goto err;
|
||||
}
|
||||
|
||||
clt->kobj_paths = kobject_create_and_add("paths", &clt->dev.kobj);
|
||||
if (!clt->kobj_paths) {
|
||||
free_percpu(clt->pcpu_path);
|
||||
device_unregister(&clt->dev);
|
||||
return NULL;
|
||||
err = -ENOMEM;
|
||||
goto err_dev;
|
||||
}
|
||||
err = rtrs_clt_create_sysfs_root_files(clt);
|
||||
if (err) {
|
||||
free_percpu(clt->pcpu_path);
|
||||
kobject_del(clt->kobj_paths);
|
||||
kobject_put(clt->kobj_paths);
|
||||
device_unregister(&clt->dev);
|
||||
return ERR_PTR(err);
|
||||
goto err_dev;
|
||||
}
|
||||
dev_set_uevent_suppress(&clt->dev, false);
|
||||
kobject_uevent(&clt->dev.kobj, KOBJ_ADD);
|
||||
|
||||
return clt;
|
||||
err_dev:
|
||||
device_unregister(&clt->dev);
|
||||
err:
|
||||
free_percpu(clt->pcpu_path);
|
||||
kfree(clt);
|
||||
return ERR_PTR(err);
|
||||
}
|
||||
|
||||
static void free_clt(struct rtrs_clt *clt)
|
||||
|
Loading…
Reference in New Issue
Block a user