Skip to contentSkip to conversation

target: unlock on error in pscsi_create_virtdevice()

PATCH In review Dan Carpenter 2 participants 3 messages Oct 1, 2011 – Oct 9, 2011

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target: unlock on error in pscsi_create_virtdevice()

This function should take the lock on success but on the error cases it doesn't.

drivers/target/target_core_pscsi.c +2 -1
index ba9e94d..b619596 100644
@@ -567,7 +567,7 @@ static struct se_device *pscsi_create_virtdevice(
 			if (IS_ERR(sh)) {
 				pr_err("pSCSI: Unable to locate"
 					" pdv_host_id: %d\n", pdv->pdv_host_id);
-				return (struct se_device *) sh;
+				return ERR_CAST(sh);
 			}
 		}
 	} else {
@@ -609,6 +609,7 @@ static struct se_device *pscsi_create_virtdevice(
 				hba->hba_flags &= ~HBA_FLAGS_PSCSI_MODE;
 			}
 			pdv->pdv_sd = NULL;
+			spin_unlock_irq(sh->host_lock);
 			return ERR_PTR(-ENODEV);
 		}
 		return dev;
#1 lore raw
Quoted 5 lines · Dan Carpenter

This function should take the lock on success but on the error cases it doesn't.

Hi Dan,

Quoted 14 lines
drivers/target/target_core_pscsi.c +1 -1
index ba9e94d..b619596 100644
@@ -567,7 +567,7 @@ static struct se_device *pscsi_create_virtdevice(
 			if (IS_ERR(sh)) {
 				pr_err("pSCSI: Unable to locate"
 					" pdv_host_id: %d\n", pdv->pdv_host_id);
-				return (struct se_device *) sh;
+				return ERR_CAST(sh);
 			}
 		}
 	} else {

drivers/target/target_core_pscsi.c static struct se_device *pscsi_create_virtdevice(

Quoted 8 lines
drivers/target/target_core_pscsi.c +1 -1
@@ -609,6 +609,7 @@ static struct se_device *pscsi_create_virtdevice(
 				hba->hba_flags &= ~HBA_FLAGS_PSCSI_MODE;
 			}
 			pdv->pdv_sd = NULL;
+			spin_unlock_irq(sh->host_lock);
 			return ERR_PTR(-ENODEV);
 		}
 		return dev;
--

So the additional of an unlock in the failure path above is actually a duplicate. pscsi_create_type_*() will already do the unlocking before returning back into pscsi_create_virtdevice().. I know this is slightly confusing, but we need to keep host_lock held before calling into scsi_device_get() for type_disk and type_rom.

So that said, i'm commiting a following revised version of your patch to add the correct ERR_CAST usage above.

Thanks,

--nab

commit 8c206dce8ccf83e2b3e121e89074d841edd43536

Author: Dan Carpenter <[email protected]>
Date:   Sun Oct 2 01:59:13 2011 +0300

target: Make pscsi_create_virtdevice use ERR_CAST

This patch changes pscsi_create_virtdevice() to properly return ERR_CAST instead of a raw pointer upon scsi_host_lookup() failure.

drivers/target/target_core_pscsi.c +1 -1
index c4509e3..e72a638 100644
@@ -567,7 +567,7 @@ static struct se_device *pscsi_create_virtdevice(
                        if (IS_ERR(sh)) {
                                pr_err("pSCSI: Unable to locate"
                                        " pdv_host_id: %d\n", pdv->pdv_host_id);
-                               return (struct se_device *) sh;
+                               return ERR_CAST(sh);
                        }
                }
        } else {
#2 lore raw

Sorry. I should have seen that. That was sloppiness on my part.

Thanks for catching that.

regards,
dan carpenter