]> Pileus Git - ~andy/linux/blobdiff - drivers/scsi/sg.c
Merge branch 'x86-hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[~andy/linux] / drivers / scsi / sg.c
index ef752b248c4d5ef7842589299d75a2297ec8178e..2968c6b83ddba4cf34a5a2019b025f521c5683d7 100644 (file)
@@ -245,6 +245,10 @@ sg_open(struct inode *inode, struct file *filp)
        if (retval)
                goto sg_put;
 
+       retval = scsi_autopm_get_device(sdp->device);
+       if (retval)
+               goto sdp_put;
+
        if (!((flags & O_NONBLOCK) ||
              scsi_block_when_processing_errors(sdp->device))) {
                retval = -ENXIO;
@@ -302,8 +306,11 @@ sg_open(struct inode *inode, struct file *filp)
        }
        retval = 0;
 error_out:
-       if (retval)
+       if (retval) {
+               scsi_autopm_put_device(sdp->device);
+sdp_put:
                scsi_device_put(sdp->device);
+       }
 sg_put:
        if (sdp)
                sg_put_dev(sdp);
@@ -327,6 +334,7 @@ sg_release(struct inode *inode, struct file *filp)
        sdp->exclude = 0;
        wake_up_interruptible(&sdp->o_excl_wait);
 
+       scsi_autopm_put_device(sdp->device);
        kref_put(&sfp->f_ref, sg_remove_sfp);
        return 0;
 }
@@ -729,6 +737,8 @@ sg_common_write(Sg_fd * sfp, Sg_request * srp,
                return k;       /* probably out of space --> ENOMEM */
        }
        if (sdp->detached) {
+               if (srp->bio)
+                       blk_end_request_all(srp->rq, -EIO);
                sg_finish_rem_req(srp);
                return -ENODEV;
        }