Skip to content

Commit

Permalink
sg: cdev lock_kernel() pushdown
Browse files Browse the repository at this point in the history
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
  • Loading branch information
Jonathan Corbet committed Jun 20, 2008
1 parent 04f4ac9 commit eb09d3d
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions drivers/scsi/sg.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ static int sg_version_num = 30534; /* 2 digits for each component */
#include <linux/delay.h>
#include <linux/scatterlist.h>
#include <linux/blktrace_api.h>
#include <linux/smp_lock.h>

#include "scsi.h"
#include <scsi/scsi_dbg.h>
Expand Down Expand Up @@ -227,19 +228,26 @@ sg_open(struct inode *inode, struct file *filp)
int res;
int retval;

lock_kernel();
nonseekable_open(inode, filp);
SCSI_LOG_TIMEOUT(3, printk("sg_open: dev=%d, flags=0x%x\n", dev, flags));
sdp = sg_get_dev(dev);
if ((!sdp) || (!sdp->device))
if ((!sdp) || (!sdp->device)) {
unlock_kernel();
return -ENXIO;
if (sdp->detached)
}
if (sdp->detached) {
unlock_kernel();
return -ENODEV;
}

/* This driver's module count bumped by fops_get in <linux/fs.h> */
/* Prevent the device driver from vanishing while we sleep */
retval = scsi_device_get(sdp->device);
if (retval)
if (retval) {
unlock_kernel();
return retval;
}

if (!((flags & O_NONBLOCK) ||
scsi_block_when_processing_errors(sdp->device))) {
Expand Down Expand Up @@ -295,10 +303,12 @@ sg_open(struct inode *inode, struct file *filp)
retval = -ENOMEM;
goto error_out;
}
unlock_kernel();
return 0;

error_out:
scsi_device_put(sdp->device);
unlock_kernel();
return retval;
}

Expand Down

0 comments on commit eb09d3d

Please sign in to comment.