Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > fc11cd6e1c513a17304da94a5390f3cd > files > 3639

kernel-2.6.18-194.11.1.el5.src.rpm

From: Tom Coughlan <coughlan@redhat.com>
Date: Mon, 8 Sep 2008 18:38:22 -0400
Subject: [scsi] scsi_host_lookup: error returns and NULL pointers
Message-id: 1220913502.29024.21.camel@p670.boston.redhat.com
O-Subject: [RHEL5.3 PATCH 2/2] scsi_host_lookup: error returns and NULL pointers
Bugzilla: 460195
RH-Acked-by: Mike Christie <mchristi@redhat.com>

This patch cleans up the behavior of scsi_host_lookup().

The original implementation attempted to use the dual role of
either returning a pointer value, or a negative error code.
User's needed to use IS_ERR() to check the result. Additionally,
the IS_ERR() macro never checks for when a NULL pointer was
returned, so a NULL pointer actually passes with a success case.
Note: scsi_host_get(), used by scsi_host_lookup(), can return
a NULL pointer.

Talk about a mudhole for the unitiated to step into....

This patch converts scsi_host_lookup() to return either NULL
or a valid pointer. The consumers were updated for the change.

-- james s

 Signed-off-by: James Smart <james.smart@emulex.com>

 ---

 hosts.c                |    2 +-
 qla4xxx/ql4_os.c       |    2 +-
 scsi_proc.c            |    8 ++++----
 scsi_transport_iscsi.c |    2 +-
 4 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
index 53e107a..260835d 100644
--- a/drivers/scsi/hosts.c
+++ b/drivers/scsi/hosts.c
@@ -429,7 +429,7 @@ struct Scsi_Host *scsi_host_lookup(unsigned short hostnum)
 {
 	struct class *class = &shost_class;
 	struct class_device *cdev;
-	struct Scsi_Host *shost = ERR_PTR(-ENXIO), *p;
+	struct Scsi_Host *shost = NULL, *p;
 
 	down_read(&class->subsys.rwsem);
 	list_for_each_entry(cdev, &class->children, node) {
diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
index 169b7b4..14b3fa3 100644
--- a/drivers/scsi/qla4xxx/ql4_os.c
+++ b/drivers/scsi/qla4xxx/ql4_os.c
@@ -228,7 +228,7 @@ static int qla4xxx_tgt_dscvr(enum iscsi_tgt_dscvr type, uint32_t host_no,
 	int ret = 0;
 
 	shost = scsi_host_lookup(host_no);
-	if (IS_ERR(shost)) {
+	if (!shost) {
 		printk(KERN_ERR "Could not find host no %u\n", host_no);
 		return -ENODEV;
 	}
diff --git a/drivers/scsi/scsi_proc.c b/drivers/scsi/scsi_proc.c
index 98494c7..88d08a0 100644
--- a/drivers/scsi/scsi_proc.c
+++ b/drivers/scsi/scsi_proc.c
@@ -200,8 +200,8 @@ static int scsi_add_single_device(uint host, uint channel, uint id, uint lun)
 	int error = -ENXIO;
 
 	shost = scsi_host_lookup(host);
-	if (IS_ERR(shost))
-		return PTR_ERR(shost);
+	if (!shost)
+		return error;
 
 	if (shost->transportt->user_scan)
 		error = shost->transportt->user_scan(shost, channel, id, lun);
@@ -218,8 +218,8 @@ static int scsi_remove_single_device(uint host, uint channel, uint id, uint lun)
 	int error = -ENXIO;
 
 	shost = scsi_host_lookup(host);
-	if (IS_ERR(shost))
-		return PTR_ERR(shost);
+	if (!shost)
+		return error;
 	sdev = scsi_device_lookup(shost, channel, id, lun);
 	if (sdev) {
 		scsi_remove_device(sdev);
diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
index 6c97a46..2cd2396 100644
--- a/drivers/scsi/scsi_transport_iscsi.c
+++ b/drivers/scsi/scsi_transport_iscsi.c
@@ -974,7 +974,7 @@ iscsi_set_host_param(struct iscsi_transport *transport,
 		return -ENOSYS;
 
 	shost = scsi_host_lookup(ev->u.set_host_param.host_no);
-	if (IS_ERR(shost)) {
+	if (!shost) {
 		printk(KERN_ERR "set_host_param could not find host no %u\n",
 		       ev->u.set_host_param.host_no);
 		return -ENODEV;