[SCSI] scsi_host_lookup: error returns and NULL pointers
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. Signed-off-by: James Smart <james.smart@emulex.com> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
This commit is contained in:
parent
6f92a6a7dd
commit
315cb0ad12
@ -464,7 +464,7 @@ static int __scsi_host_match(struct device *dev, void *data)
|
|||||||
struct Scsi_Host *scsi_host_lookup(unsigned short hostnum)
|
struct Scsi_Host *scsi_host_lookup(unsigned short hostnum)
|
||||||
{
|
{
|
||||||
struct device *cdev;
|
struct device *cdev;
|
||||||
struct Scsi_Host *shost = ERR_PTR(-ENXIO);
|
struct Scsi_Host *shost = NULL;
|
||||||
|
|
||||||
cdev = class_find_device(&shost_class, NULL, &hostnum,
|
cdev = class_find_device(&shost_class, NULL, &hostnum,
|
||||||
__scsi_host_match);
|
__scsi_host_match);
|
||||||
|
@ -259,8 +259,8 @@ static int scsi_add_single_device(uint host, uint channel, uint id, uint lun)
|
|||||||
int error = -ENXIO;
|
int error = -ENXIO;
|
||||||
|
|
||||||
shost = scsi_host_lookup(host);
|
shost = scsi_host_lookup(host);
|
||||||
if (IS_ERR(shost))
|
if (!shost)
|
||||||
return PTR_ERR(shost);
|
return error;
|
||||||
|
|
||||||
if (shost->transportt->user_scan)
|
if (shost->transportt->user_scan)
|
||||||
error = shost->transportt->user_scan(shost, channel, id, lun);
|
error = shost->transportt->user_scan(shost, channel, id, lun);
|
||||||
@ -287,8 +287,8 @@ static int scsi_remove_single_device(uint host, uint channel, uint id, uint lun)
|
|||||||
int error = -ENXIO;
|
int error = -ENXIO;
|
||||||
|
|
||||||
shost = scsi_host_lookup(host);
|
shost = scsi_host_lookup(host);
|
||||||
if (IS_ERR(shost))
|
if (!shost)
|
||||||
return PTR_ERR(shost);
|
return error;
|
||||||
sdev = scsi_device_lookup(shost, channel, id, lun);
|
sdev = scsi_device_lookup(shost, channel, id, lun);
|
||||||
if (sdev) {
|
if (sdev) {
|
||||||
scsi_remove_device(sdev);
|
scsi_remove_device(sdev);
|
||||||
|
@ -460,7 +460,7 @@ int scsi_tgt_kspace_exec(int host_no, u64 itn_id, int result, u64 tag,
|
|||||||
|
|
||||||
/* TODO: replace with a O(1) alg */
|
/* TODO: replace with a O(1) alg */
|
||||||
shost = scsi_host_lookup(host_no);
|
shost = scsi_host_lookup(host_no);
|
||||||
if (IS_ERR(shost)) {
|
if (!shost) {
|
||||||
printk(KERN_ERR "Could not find host no %d\n", host_no);
|
printk(KERN_ERR "Could not find host no %d\n", host_no);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
@ -550,7 +550,7 @@ int scsi_tgt_kspace_tsk_mgmt(int host_no, u64 itn_id, u64 mid, int result)
|
|||||||
dprintk("%d %d %llx\n", host_no, result, (unsigned long long) mid);
|
dprintk("%d %d %llx\n", host_no, result, (unsigned long long) mid);
|
||||||
|
|
||||||
shost = scsi_host_lookup(host_no);
|
shost = scsi_host_lookup(host_no);
|
||||||
if (IS_ERR(shost)) {
|
if (!shost) {
|
||||||
printk(KERN_ERR "Could not find host no %d\n", host_no);
|
printk(KERN_ERR "Could not find host no %d\n", host_no);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@ -603,7 +603,7 @@ int scsi_tgt_kspace_it_nexus_rsp(int host_no, u64 itn_id, int result)
|
|||||||
dprintk("%d %d%llx\n", host_no, result, (unsigned long long)itn_id);
|
dprintk("%d %d%llx\n", host_no, result, (unsigned long long)itn_id);
|
||||||
|
|
||||||
shost = scsi_host_lookup(host_no);
|
shost = scsi_host_lookup(host_no);
|
||||||
if (IS_ERR(shost)) {
|
if (!shost) {
|
||||||
printk(KERN_ERR "Could not find host no %d\n", host_no);
|
printk(KERN_ERR "Could not find host no %d\n", host_no);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -1361,7 +1361,7 @@ iscsi_tgt_dscvr(struct iscsi_transport *transport,
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
shost = scsi_host_lookup(ev->u.tgt_dscvr.host_no);
|
shost = scsi_host_lookup(ev->u.tgt_dscvr.host_no);
|
||||||
if (IS_ERR(shost)) {
|
if (!shost) {
|
||||||
printk(KERN_ERR "target discovery could not find host no %u\n",
|
printk(KERN_ERR "target discovery could not find host no %u\n",
|
||||||
ev->u.tgt_dscvr.host_no);
|
ev->u.tgt_dscvr.host_no);
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
@ -1387,7 +1387,7 @@ iscsi_set_host_param(struct iscsi_transport *transport,
|
|||||||
return -ENOSYS;
|
return -ENOSYS;
|
||||||
|
|
||||||
shost = scsi_host_lookup(ev->u.set_host_param.host_no);
|
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",
|
printk(KERN_ERR "set_host_param could not find host no %u\n",
|
||||||
ev->u.set_host_param.host_no);
|
ev->u.set_host_param.host_no);
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
Loading…
Reference in New Issue
Block a user