Commit 8d9efe53 authored by Sebastian Andrzej Siewior's avatar Sebastian Andrzej Siewior Committed by Nicholas Bellinger

target: fix return code of core_tpg_.*_lun

- core_tpg_pre_addlun()
  returns always ERR_PTR() or the pointer, never NULL. The additional
  check for NULL in core_dev_add_lun() is not required.

- core_tpg_pre_dellun()
  returns always ERR_PTR() or the pointer, never NULL. The check for NULL
  in core_dev_del_lun() is wrong. The third argument (int *) is never
  used, remove it.

- core_dev_add_lun()
  returns always NULL or the pointer, never ERR_PTR. The check for
  IS_ERR() is not required.

(nab: Convert core_dev_add_lun() use err.h macros for failure
handling to be consistent with the rest of target_core_fabric_configfs.c
callers)
Signed-off-by: default avatarSebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: <stable@vger.kernel.org>
Signed-off-by: default avatarNicholas Bellinger <nab@linux-iscsi.org>
parent 1dd0a067
...@@ -1295,24 +1295,26 @@ struct se_lun *core_dev_add_lun( ...@@ -1295,24 +1295,26 @@ struct se_lun *core_dev_add_lun(
{ {
struct se_lun *lun_p; struct se_lun *lun_p;
u32 lun_access = 0; u32 lun_access = 0;
int rc;
if (atomic_read(&dev->dev_access_obj.obj_access_count) != 0) { if (atomic_read(&dev->dev_access_obj.obj_access_count) != 0) {
pr_err("Unable to export struct se_device while dev_access_obj: %d\n", pr_err("Unable to export struct se_device while dev_access_obj: %d\n",
atomic_read(&dev->dev_access_obj.obj_access_count)); atomic_read(&dev->dev_access_obj.obj_access_count));
return NULL; return ERR_PTR(-EACCES);
} }
lun_p = core_tpg_pre_addlun(tpg, lun); lun_p = core_tpg_pre_addlun(tpg, lun);
if ((IS_ERR(lun_p)) || !lun_p) if (IS_ERR(lun_p))
return NULL; return lun_p;
if (dev->dev_flags & DF_READ_ONLY) if (dev->dev_flags & DF_READ_ONLY)
lun_access = TRANSPORT_LUNFLAGS_READ_ONLY; lun_access = TRANSPORT_LUNFLAGS_READ_ONLY;
else else
lun_access = TRANSPORT_LUNFLAGS_READ_WRITE; lun_access = TRANSPORT_LUNFLAGS_READ_WRITE;
if (core_tpg_post_addlun(tpg, lun_p, lun_access, dev) < 0) rc = core_tpg_post_addlun(tpg, lun_p, lun_access, dev);
return NULL; if (rc < 0)
return ERR_PTR(rc);
pr_debug("%s_TPG[%u]_LUN[%u] - Activated %s Logical Unit from" pr_debug("%s_TPG[%u]_LUN[%u] - Activated %s Logical Unit from"
" CORE HBA: %u\n", tpg->se_tpg_tfo->get_fabric_name(), " CORE HBA: %u\n", tpg->se_tpg_tfo->get_fabric_name(),
...@@ -1349,11 +1351,10 @@ int core_dev_del_lun( ...@@ -1349,11 +1351,10 @@ int core_dev_del_lun(
u32 unpacked_lun) u32 unpacked_lun)
{ {
struct se_lun *lun; struct se_lun *lun;
int ret = 0;
lun = core_tpg_pre_dellun(tpg, unpacked_lun, &ret); lun = core_tpg_pre_dellun(tpg, unpacked_lun);
if (!lun) if (IS_ERR(lun))
return ret; return PTR_ERR(lun);
core_tpg_post_dellun(tpg, lun); core_tpg_post_dellun(tpg, lun);
......
...@@ -766,9 +766,9 @@ static int target_fabric_port_link( ...@@ -766,9 +766,9 @@ static int target_fabric_port_link(
lun_p = core_dev_add_lun(se_tpg, dev->se_hba, dev, lun_p = core_dev_add_lun(se_tpg, dev->se_hba, dev,
lun->unpacked_lun); lun->unpacked_lun);
if (IS_ERR(lun_p) || !lun_p) { if (IS_ERR(lun_p)) {
pr_err("core_dev_add_lun() failed\n"); pr_err("core_dev_add_lun() failed\n");
ret = -EINVAL; ret = PTR_ERR(lun_p);
goto out; goto out;
} }
......
...@@ -90,7 +90,7 @@ void core_tpg_wait_for_nacl_pr_ref(struct se_node_acl *); ...@@ -90,7 +90,7 @@ void core_tpg_wait_for_nacl_pr_ref(struct se_node_acl *);
struct se_lun *core_tpg_pre_addlun(struct se_portal_group *, u32); struct se_lun *core_tpg_pre_addlun(struct se_portal_group *, u32);
int core_tpg_post_addlun(struct se_portal_group *, struct se_lun *, int core_tpg_post_addlun(struct se_portal_group *, struct se_lun *,
u32, void *); u32, void *);
struct se_lun *core_tpg_pre_dellun(struct se_portal_group *, u32, int *); struct se_lun *core_tpg_pre_dellun(struct se_portal_group *, u32 unpacked_lun);
int core_tpg_post_dellun(struct se_portal_group *, struct se_lun *); int core_tpg_post_dellun(struct se_portal_group *, struct se_lun *);
/* target_core_transport.c */ /* target_core_transport.c */
......
...@@ -807,8 +807,7 @@ static void core_tpg_shutdown_lun( ...@@ -807,8 +807,7 @@ static void core_tpg_shutdown_lun(
struct se_lun *core_tpg_pre_dellun( struct se_lun *core_tpg_pre_dellun(
struct se_portal_group *tpg, struct se_portal_group *tpg,
u32 unpacked_lun, u32 unpacked_lun)
int *ret)
{ {
struct se_lun *lun; struct se_lun *lun;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment