Skip to content

Commit

Permalink
[SCSI] iscsi class, qla4xxx: fix sess/conn refcounting when find fns …
Browse files Browse the repository at this point in the history
…are used

This fixes a bug where the iscsi class/driver did not do a put_device
when a sess/conn device was found. This also simplifies the interface
by not having to pass in some arguments that were duplicated and did
not need to be exported.

Reported-by: Zhao Hongjiang <zhaohongjiang@huawei.com>
Signed-off-by: Mike Christie <michaelc@cs.wisc.edu>
Acked-by: Vikas Chaudhary <vikas.chaudhary@qlogic.com>
Signed-off-by: James Bottomley <JBottomley@Parallels.com>
  • Loading branch information
Mike Christie authored and James Bottomley committed May 10, 2013
1 parent aa9f832 commit 8526cb1
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 55 deletions.
6 changes: 4 additions & 2 deletions drivers/scsi/qla4xxx/ql4_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -5605,6 +5605,7 @@ static int qla4xxx_sysfs_ddb_add(struct Scsi_Host *shost, const char *buf,
ql4_printk(KERN_ERR, ha,
"%s: A non-persistent entry %s found\n",
__func__, dev->kobj.name);
put_device(dev);
goto exit_ddb_add;
}

Expand Down Expand Up @@ -6112,8 +6113,7 @@ qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session *fnode_sess,
int parent_type, parent_index = 0xffff;
int rc = 0;

dev = iscsi_find_flashnode_conn(fnode_sess, NULL,
iscsi_is_flashnode_conn_dev);
dev = iscsi_find_flashnode_conn(fnode_sess);
if (!dev)
return -EIO;

Expand Down Expand Up @@ -6347,6 +6347,8 @@ qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session *fnode_sess,
rc = -ENOSYS;
break;
}

put_device(dev);
return rc;
}

Expand Down
90 changes: 43 additions & 47 deletions drivers/scsi/scsi_transport_iscsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1019,8 +1019,7 @@ static int flashnode_match_index(struct device *dev, void *data)
/**
* iscsi_get_flashnode_by_index -finds flashnode session entry by index
* @shost: pointer to host data
* @data: pointer to data containing value to use for comparison
* @fn: function pointer that does actual comparison
* @idx: index to match
*
* Finds the flashnode session object for the passed index
*
Expand All @@ -1029,13 +1028,13 @@ static int flashnode_match_index(struct device *dev, void *data)
* %NULL on failure
*/
static struct iscsi_bus_flash_session *
iscsi_get_flashnode_by_index(struct Scsi_Host *shost, void *data,
int (*fn)(struct device *dev, void *data))
iscsi_get_flashnode_by_index(struct Scsi_Host *shost, uint32_t idx)
{
struct iscsi_bus_flash_session *fnode_sess = NULL;
struct device *dev;

dev = device_find_child(&shost->shost_gendev, data, fn);
dev = device_find_child(&shost->shost_gendev, &idx,
flashnode_match_index);
if (dev)
fnode_sess = iscsi_dev_to_flash_session(dev);

Expand All @@ -1059,18 +1058,13 @@ struct device *
iscsi_find_flashnode_sess(struct Scsi_Host *shost, void *data,
int (*fn)(struct device *dev, void *data))
{
struct device *dev;

dev = device_find_child(&shost->shost_gendev, data, fn);
return dev;
return device_find_child(&shost->shost_gendev, data, fn);
}
EXPORT_SYMBOL_GPL(iscsi_find_flashnode_sess);

/**
* iscsi_find_flashnode_conn - finds flashnode connection entry
* @fnode_sess: pointer to parent flashnode session entry
* @data: pointer to data containing value to use for comparison
* @fn: function pointer that does actual comparison
*
* Finds the flashnode connection object comparing the data passed using logic
* defined in passed function pointer
Expand All @@ -1080,14 +1074,10 @@ EXPORT_SYMBOL_GPL(iscsi_find_flashnode_sess);
* %NULL on failure
*/
struct device *
iscsi_find_flashnode_conn(struct iscsi_bus_flash_session *fnode_sess,
void *data,
int (*fn)(struct device *dev, void *data))
iscsi_find_flashnode_conn(struct iscsi_bus_flash_session *fnode_sess)
{
struct device *dev;

dev = device_find_child(&fnode_sess->dev, data, fn);
return dev;
return device_find_child(&fnode_sess->dev, NULL,
iscsi_is_flashnode_conn_dev);
}
EXPORT_SYMBOL_GPL(iscsi_find_flashnode_conn);

Expand Down Expand Up @@ -2808,7 +2798,7 @@ static int iscsi_set_flashnode_param(struct iscsi_transport *transport,
struct iscsi_bus_flash_session *fnode_sess;
struct iscsi_bus_flash_conn *fnode_conn;
struct device *dev;
uint32_t *idx;
uint32_t idx;
int err = 0;

if (!transport->set_flashnode_param) {
Expand All @@ -2824,25 +2814,27 @@ static int iscsi_set_flashnode_param(struct iscsi_transport *transport,
goto put_host;
}

idx = &ev->u.set_flashnode.flashnode_idx;
fnode_sess = iscsi_get_flashnode_by_index(shost, idx,
flashnode_match_index);
idx = ev->u.set_flashnode.flashnode_idx;
fnode_sess = iscsi_get_flashnode_by_index(shost, idx);
if (!fnode_sess) {
pr_err("%s could not find flashnode %u for host no %u\n",
__func__, *idx, ev->u.set_flashnode.host_no);
__func__, idx, ev->u.set_flashnode.host_no);
err = -ENODEV;
goto put_host;
}

dev = iscsi_find_flashnode_conn(fnode_sess, NULL,
iscsi_is_flashnode_conn_dev);
dev = iscsi_find_flashnode_conn(fnode_sess);
if (!dev) {
err = -ENODEV;
goto put_host;
goto put_sess;
}

fnode_conn = iscsi_dev_to_flash_conn(dev);
err = transport->set_flashnode_param(fnode_sess, fnode_conn, data, len);
put_device(dev);

put_sess:
put_device(&fnode_sess->dev);

put_host:
scsi_host_put(shost);
Expand Down Expand Up @@ -2891,7 +2883,7 @@ static int iscsi_del_flashnode(struct iscsi_transport *transport,
{
struct Scsi_Host *shost;
struct iscsi_bus_flash_session *fnode_sess;
uint32_t *idx;
uint32_t idx;
int err = 0;

if (!transport->del_flashnode) {
Expand All @@ -2907,17 +2899,17 @@ static int iscsi_del_flashnode(struct iscsi_transport *transport,
goto put_host;
}

idx = &ev->u.del_flashnode.flashnode_idx;
fnode_sess = iscsi_get_flashnode_by_index(shost, idx,
flashnode_match_index);
idx = ev->u.del_flashnode.flashnode_idx;
fnode_sess = iscsi_get_flashnode_by_index(shost, idx);
if (!fnode_sess) {
pr_err("%s could not find flashnode %u for host no %u\n",
__func__, *idx, ev->u.del_flashnode.host_no);
__func__, idx, ev->u.del_flashnode.host_no);
err = -ENODEV;
goto put_host;
}

err = transport->del_flashnode(fnode_sess);
put_device(&fnode_sess->dev);

put_host:
scsi_host_put(shost);
Expand All @@ -2933,7 +2925,7 @@ static int iscsi_login_flashnode(struct iscsi_transport *transport,
struct iscsi_bus_flash_session *fnode_sess;
struct iscsi_bus_flash_conn *fnode_conn;
struct device *dev;
uint32_t *idx;
uint32_t idx;
int err = 0;

if (!transport->login_flashnode) {
Expand All @@ -2949,25 +2941,27 @@ static int iscsi_login_flashnode(struct iscsi_transport *transport,
goto put_host;
}

idx = &ev->u.login_flashnode.flashnode_idx;
fnode_sess = iscsi_get_flashnode_by_index(shost, idx,
flashnode_match_index);
idx = ev->u.login_flashnode.flashnode_idx;
fnode_sess = iscsi_get_flashnode_by_index(shost, idx);
if (!fnode_sess) {
pr_err("%s could not find flashnode %u for host no %u\n",
__func__, *idx, ev->u.login_flashnode.host_no);
__func__, idx, ev->u.login_flashnode.host_no);
err = -ENODEV;
goto put_host;
}

dev = iscsi_find_flashnode_conn(fnode_sess, NULL,
iscsi_is_flashnode_conn_dev);
dev = iscsi_find_flashnode_conn(fnode_sess);
if (!dev) {
err = -ENODEV;
goto put_host;
goto put_sess;
}

fnode_conn = iscsi_dev_to_flash_conn(dev);
err = transport->login_flashnode(fnode_sess, fnode_conn);
put_device(dev);

put_sess:
put_device(&fnode_sess->dev);

put_host:
scsi_host_put(shost);
Expand All @@ -2983,7 +2977,7 @@ static int iscsi_logout_flashnode(struct iscsi_transport *transport,
struct iscsi_bus_flash_session *fnode_sess;
struct iscsi_bus_flash_conn *fnode_conn;
struct device *dev;
uint32_t *idx;
uint32_t idx;
int err = 0;

if (!transport->logout_flashnode) {
Expand All @@ -2999,26 +2993,28 @@ static int iscsi_logout_flashnode(struct iscsi_transport *transport,
goto put_host;
}

idx = &ev->u.logout_flashnode.flashnode_idx;
fnode_sess = iscsi_get_flashnode_by_index(shost, idx,
flashnode_match_index);
idx = ev->u.logout_flashnode.flashnode_idx;
fnode_sess = iscsi_get_flashnode_by_index(shost, idx);
if (!fnode_sess) {
pr_err("%s could not find flashnode %u for host no %u\n",
__func__, *idx, ev->u.logout_flashnode.host_no);
__func__, idx, ev->u.logout_flashnode.host_no);
err = -ENODEV;
goto put_host;
}

dev = iscsi_find_flashnode_conn(fnode_sess, NULL,
iscsi_is_flashnode_conn_dev);
dev = iscsi_find_flashnode_conn(fnode_sess);
if (!dev) {
err = -ENODEV;
goto put_host;
goto put_sess;
}

fnode_conn = iscsi_dev_to_flash_conn(dev);

err = transport->logout_flashnode(fnode_sess, fnode_conn);
put_device(dev);

put_sess:
put_device(&fnode_sess->dev);

put_host:
scsi_host_put(shost);
Expand Down
8 changes: 2 additions & 6 deletions include/scsi/scsi_transport_iscsi.h
Original file line number Diff line number Diff line change
Expand Up @@ -471,14 +471,10 @@ iscsi_destroy_flashnode_sess(struct iscsi_bus_flash_session *fnode_sess);
extern void iscsi_destroy_all_flashnode(struct Scsi_Host *shost);
extern int iscsi_flashnode_bus_match(struct device *dev,
struct device_driver *drv);
extern int iscsi_is_flashnode_conn_dev(struct device *dev, void *data);

extern struct device *
iscsi_find_flashnode_sess(struct Scsi_Host *shost, void *data,
int (*fn)(struct device *dev, void *data));

extern struct device *
iscsi_find_flashnode_conn(struct iscsi_bus_flash_session *fnode_sess,
void *data,
int (*fn)(struct device *dev, void *data));
iscsi_find_flashnode_conn(struct iscsi_bus_flash_session *fnode_sess);

#endif

0 comments on commit 8526cb1

Please sign in to comment.