mirror of
https://github.com/SCST-project/scst.git
synced 2026-05-14 09:11:27 +00:00
isert: Fix case where we got disconnect before login character device was opened
We may receive disconnect before iscsi-scstd had the chance to open the character device. This would result in resource leak, since the device will not be freed. Fix this by only increasing reference once the device is actually opened. Signed-off-by: Yan Burman <yanb@mellanox.com> git-svn-id: http://svn.code.sf.net/p/scst/svn/branches/iser@6080 d57e44dd-8a1f-0410-8b47-8ef2f437770f
This commit is contained in:
@@ -356,7 +356,6 @@ wait_for_connection:
|
||||
conn_dev = list_first_entry(&dev->new_conn_list, struct isert_conn_dev,
|
||||
conn_list_entry);
|
||||
list_move(&conn_dev->conn_list_entry, &dev->curr_conn_list);
|
||||
kref_get(&conn_dev->kref);
|
||||
spin_unlock(&dev->conn_lock);
|
||||
|
||||
res = snprintf(k_buff, sizeof(k_buff), "/dev/"ISER_CONN_DEV_PREFIX"%d",
|
||||
@@ -485,6 +484,14 @@ static int isert_open(struct inode *inode, struct file *filp)
|
||||
|
||||
dev = container_of(inode->i_cdev, struct isert_conn_dev, cdev);
|
||||
|
||||
spin_lock(&isert_listen_dev.conn_lock);
|
||||
if (unlikely(dev->occupied == 0)) {
|
||||
spin_unlock(&isert_listen_dev.conn_lock);
|
||||
res = -ENODEV; /* already closed */
|
||||
goto out;
|
||||
}
|
||||
spin_unlock(&isert_listen_dev.conn_lock);
|
||||
|
||||
if (unlikely(!atomic_dec_and_test(&dev->available))) {
|
||||
atomic_inc(&dev->available);
|
||||
res = -EBUSY; /* already open */
|
||||
@@ -493,6 +500,7 @@ static int isert_open(struct inode *inode, struct file *filp)
|
||||
|
||||
spin_lock(&isert_listen_dev.conn_lock);
|
||||
list_del_init(&dev->conn_list_entry);
|
||||
kref_get(&dev->kref);
|
||||
spin_unlock(&isert_listen_dev.conn_lock);
|
||||
|
||||
filp->private_data = dev; /* for other methods */
|
||||
|
||||
Reference in New Issue
Block a user