x86: move prefill_possible_map to common file
[sfrench/cifs-2.6.git] / drivers / scsi / hosts.c
index adc9559cb6f40b20e4666d93550bc0b8b6fc8e83..ed7e0a1fc34de02d3de7ead9c4f3370928d9c530 100644 (file)
@@ -54,8 +54,7 @@ static struct class shost_class = {
 };
 
 /**
- *     scsi_host_set_state - Take the given host through the host
- *             state model.
+ *     scsi_host_set_state - Take the given host through the host state model.
  *     @shost: scsi host to change the state of.
  *     @state: state to change to.
  *
@@ -219,18 +218,24 @@ int scsi_add_host(struct Scsi_Host *shost, struct device *dev)
 
        get_device(&shost->shost_gendev);
 
-       if (shost->transportt->host_size &&
-           (shost->shost_data = kzalloc(shost->transportt->host_size,
-                                        GFP_KERNEL)) == NULL)
-               goto out_del_classdev;
+       if (shost->transportt->host_size) {
+               shost->shost_data = kzalloc(shost->transportt->host_size,
+                                        GFP_KERNEL);
+               if (shost->shost_data == NULL) {
+                       error = -ENOMEM;
+                       goto out_del_classdev;
+               }
+       }
 
        if (shost->transportt->create_work_queue) {
                snprintf(shost->work_q_name, KOBJ_NAME_LEN, "scsi_wq_%d",
                        shost->host_no);
                shost->work_q = create_singlethread_workqueue(
                                        shost->work_q_name);
-               if (!shost->work_q)
+               if (!shost->work_q) {
+                       error = -EINVAL;
                        goto out_free_shost_data;
+               }
        }
 
        error = scsi_sysfs_add_host(shost);
@@ -344,6 +349,12 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
        shost->ordered_tag = sht->ordered_tag;
        shost->active_mode = sht->supported_mode;
 
+       if (sht->supported_mode == MODE_UNKNOWN)
+               /* means we didn't set it ... default to INITIATOR */
+               shost->active_mode = MODE_INITIATOR;
+       else
+               shost->active_mode = sht->supported_mode;
+
        if (sht->max_host_blocked)
                shost->max_host_blocked = sht->max_host_blocked;
        else
@@ -422,9 +433,17 @@ void scsi_unregister(struct Scsi_Host *shost)
 }
 EXPORT_SYMBOL(scsi_unregister);
 
+static int __scsi_host_match(struct class_device *cdev, void *data)
+{
+       struct Scsi_Host *p;
+       unsigned short *hostnum = (unsigned short *)data;
+
+       p = class_to_shost(cdev);
+       return p->host_no == *hostnum;
+}
+
 /**
  * scsi_host_lookup - get a reference to a Scsi_Host by host no
- *
  * @hostnum:   host number to locate
  *
  * Return value:
@@ -432,19 +451,12 @@ EXPORT_SYMBOL(scsi_unregister);
  **/
 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 = ERR_PTR(-ENXIO);
 
-       down(&class->sem);
-       list_for_each_entry(cdev, &class->children, node) {
-               p = class_to_shost(cdev);
-               if (p->host_no == hostnum) {
-                       shost = scsi_host_get(p);
-                       break;
-               }
-       }
-       up(&class->sem);
+       cdev = class_find_child(&shost_class, &hostnum, __scsi_host_match);
+       if (cdev)
+               shost = scsi_host_get(class_to_shost(cdev));
 
        return shost;
 }