Merge tag 'scsi-misc' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi
[linux-2.6-microblaze.git] / drivers / scsi / scsi_sysfs.c
index c0d3111..8679325 100644 (file)
@@ -13,6 +13,7 @@
 #include <linux/blkdev.h>
 #include <linux/device.h>
 #include <linux/pm_runtime.h>
+#include <linux/bsg.h>
 
 #include <scsi/scsi.h>
 #include <scsi/scsi_device.h>
@@ -1333,7 +1334,6 @@ static int scsi_target_add(struct scsi_target *starget)
 int scsi_sysfs_add_sdev(struct scsi_device *sdev)
 {
        int error, i;
-       struct request_queue *rq = sdev->request_queue;
        struct scsi_target *starget = sdev->sdev_target;
 
        error = scsi_target_add(starget);
@@ -1372,12 +1372,19 @@ int scsi_sysfs_add_sdev(struct scsi_device *sdev)
        transport_add_device(&sdev->sdev_gendev);
        sdev->is_visible = 1;
 
-       error = bsg_scsi_register_queue(rq, &sdev->sdev_gendev);
-       if (error)
-               /* we're treating error on bsg register as non-fatal,
-                * so pretend nothing went wrong */
-               sdev_printk(KERN_INFO, sdev,
-                           "Failed to register bsg queue, errno=%d\n", error);
+       if (IS_ENABLED(CONFIG_BLK_DEV_BSG)) {
+               sdev->bsg_dev = scsi_bsg_register_queue(sdev);
+               if (IS_ERR(sdev->bsg_dev)) {
+                       /*
+                        * We're treating error on bsg register as non-fatal, so
+                        * pretend nothing went wrong.
+                        */
+                       sdev_printk(KERN_INFO, sdev,
+                                   "Failed to register bsg queue, errno=%d\n",
+                                   error);
+                       sdev->bsg_dev = NULL;
+               }
+       }
 
        /* add additional host specific attributes */
        if (sdev->host->hostt->sdev_attrs) {
@@ -1439,7 +1446,8 @@ void __scsi_remove_device(struct scsi_device *sdev)
                        sysfs_remove_groups(&sdev->sdev_gendev.kobj,
                                        sdev->host->hostt->sdev_groups);
 
-               bsg_unregister_queue(sdev->request_queue);
+               if (IS_ENABLED(CONFIG_BLK_DEV_BSG) && sdev->bsg_dev)
+                       bsg_unregister_queue(sdev->bsg_dev);
                device_unregister(&sdev->sdev_dev);
                transport_remove_device(dev);
                device_del(dev);