[SCSI] use dynamically allocated sense buffer
[pandora-kernel.git] / drivers / scsi / hosts.c
index 38c3a29..f5d3fbb 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.
  *
@@ -220,7 +219,7 @@ int scsi_add_host(struct Scsi_Host *shost, struct device *dev)
        get_device(&shost->shost_gendev);
 
        if (shost->transportt->host_size &&
-           (shost->shost_data = kmalloc(shost->transportt->host_size,
+           (shost->shost_data = kzalloc(shost->transportt->host_size,
                                         GFP_KERNEL)) == NULL)
                goto out_del_classdev;
 
@@ -269,6 +268,7 @@ static void scsi_host_dev_release(struct device *dev)
        }
 
        scsi_destroy_command_freelist(shost);
+       scsi_destroy_command_sense_buffer(shost);
        if (shost->bqt)
                blk_free_tags(shost->bqt);
 
@@ -342,6 +342,14 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
        shost->unchecked_isa_dma = sht->unchecked_isa_dma;
        shost->use_clustering = sht->use_clustering;
        shost->ordered_tag = sht->ordered_tag;
+       shost->active_mode = sht->supported_mode;
+       shost->use_sg_chaining = sht->use_sg_chaining;
+
+       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;
@@ -365,10 +373,14 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
        else
                shost->dma_boundary = 0xffffffff;
 
-       rval = scsi_setup_command_freelist(shost);
+       rval = scsi_setup_command_sense_buffer(shost);
        if (rval)
                goto fail_kfree;
 
+       rval = scsi_setup_command_freelist(shost);
+       if (rval)
+               goto fail_destroy_sense;
+
        device_initialize(&shost->shost_gendev);
        snprintf(shost->shost_gendev.bus_id, BUS_ID_SIZE, "host%d",
                shost->host_no);
@@ -392,6 +404,8 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
 
  fail_destroy_freelist:
        scsi_destroy_command_freelist(shost);
+ fail_destroy_sense:
+       scsi_destroy_command_sense_buffer(shost);
  fail_kfree:
        kfree(shost);
        return NULL;
@@ -423,7 +437,6 @@ EXPORT_SYMBOL(scsi_unregister);
 
 /**
  * scsi_host_lookup - get a reference to a Scsi_Host by host no
- *
  * @hostnum:   host number to locate
  *
  * Return value:
@@ -435,7 +448,7 @@ struct Scsi_Host *scsi_host_lookup(unsigned short hostnum)
        struct class_device *cdev;
        struct Scsi_Host *shost = ERR_PTR(-ENXIO), *p;
 
-       down_read(&class->subsys.rwsem);
+       down(&class->sem);
        list_for_each_entry(cdev, &class->children, node) {
                p = class_to_shost(cdev);
                if (p->host_no == hostnum) {
@@ -443,7 +456,7 @@ struct Scsi_Host *scsi_host_lookup(unsigned short hostnum)
                        break;
                }
        }
-       up_read(&class->subsys.rwsem);
+       up(&class->sem);
 
        return shost;
 }