aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/sg.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/sg.c')
-rw-r--r--drivers/scsi/sg.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 91e316fe6522..9230402c45af 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -210,13 +210,11 @@ static void sg_put_dev(Sg_device *sdp);
210static int sg_allow_access(struct file *filp, unsigned char *cmd) 210static int sg_allow_access(struct file *filp, unsigned char *cmd)
211{ 211{
212 struct sg_fd *sfp = (struct sg_fd *)filp->private_data; 212 struct sg_fd *sfp = (struct sg_fd *)filp->private_data;
213 struct request_queue *q = sfp->parentdp->device->request_queue;
214 213
215 if (sfp->parentdp->device->type == TYPE_SCANNER) 214 if (sfp->parentdp->device->type == TYPE_SCANNER)
216 return 0; 215 return 0;
217 216
218 return blk_verify_command(&q->cmd_filter, 217 return blk_verify_command(cmd, filp->f_mode & FMODE_WRITE);
219 cmd, filp->f_mode & FMODE_WRITE);
220} 218}
221 219
222static int 220static int
@@ -289,8 +287,8 @@ sg_open(struct inode *inode, struct file *filp)
289 if (list_empty(&sdp->sfds)) { /* no existing opens on this device */ 287 if (list_empty(&sdp->sfds)) { /* no existing opens on this device */
290 sdp->sgdebug = 0; 288 sdp->sgdebug = 0;
291 q = sdp->device->request_queue; 289 q = sdp->device->request_queue;
292 sdp->sg_tablesize = min(q->max_hw_segments, 290 sdp->sg_tablesize = min(queue_max_hw_segments(q),
293 q->max_phys_segments); 291 queue_max_phys_segments(q));
294 } 292 }
295 if ((sfp = sg_add_sfp(sdp, dev))) 293 if ((sfp = sg_add_sfp(sdp, dev)))
296 filp->private_data = sfp; 294 filp->private_data = sfp;
@@ -621,7 +619,7 @@ sg_write(struct file *filp, const char __user *buf, size_t count, loff_t * ppos)
621 if (strcmp(current->comm, cmd) && printk_ratelimit()) { 619 if (strcmp(current->comm, cmd) && printk_ratelimit()) {
622 printk(KERN_WARNING 620 printk(KERN_WARNING
623 "sg_write: data in/out %d/%d bytes for SCSI command 0x%x--" 621 "sg_write: data in/out %d/%d bytes for SCSI command 0x%x--"
624 "guessing data in;\n" KERN_WARNING " " 622 "guessing data in;\n "
625 "program %s not setting count and/or reply_len properly\n", 623 "program %s not setting count and/or reply_len properly\n",
626 old_hdr.reply_len - (int)SZ_SG_HEADER, 624 old_hdr.reply_len - (int)SZ_SG_HEADER,
627 input_size, (unsigned int) cmnd[0], 625 input_size, (unsigned int) cmnd[0],
@@ -909,7 +907,7 @@ sg_ioctl(struct inode *inode, struct file *filp,
909 if (val < 0) 907 if (val < 0)
910 return -EINVAL; 908 return -EINVAL;
911 val = min_t(int, val, 909 val = min_t(int, val,
912 sdp->device->request_queue->max_sectors * 512); 910 queue_max_sectors(sdp->device->request_queue) * 512);
913 if (val != sfp->reserve.bufflen) { 911 if (val != sfp->reserve.bufflen) {
914 if (sg_res_in_use(sfp) || sfp->mmap_called) 912 if (sg_res_in_use(sfp) || sfp->mmap_called)
915 return -EBUSY; 913 return -EBUSY;
@@ -919,7 +917,7 @@ sg_ioctl(struct inode *inode, struct file *filp,
919 return 0; 917 return 0;
920 case SG_GET_RESERVED_SIZE: 918 case SG_GET_RESERVED_SIZE:
921 val = min_t(int, sfp->reserve.bufflen, 919 val = min_t(int, sfp->reserve.bufflen,
922 sdp->device->request_queue->max_sectors * 512); 920 queue_max_sectors(sdp->device->request_queue) * 512);
923 return put_user(val, ip); 921 return put_user(val, ip);
924 case SG_SET_COMMAND_Q: 922 case SG_SET_COMMAND_Q:
925 result = get_user(val, ip); 923 result = get_user(val, ip);
@@ -1059,7 +1057,7 @@ sg_ioctl(struct inode *inode, struct file *filp,
1059 return -ENODEV; 1057 return -ENODEV;
1060 return scsi_ioctl(sdp->device, cmd_in, p); 1058 return scsi_ioctl(sdp->device, cmd_in, p);
1061 case BLKSECTGET: 1059 case BLKSECTGET:
1062 return put_user(sdp->device->request_queue->max_sectors * 512, 1060 return put_user(queue_max_sectors(sdp->device->request_queue) * 512,
1063 ip); 1061 ip);
1064 case BLKTRACESETUP: 1062 case BLKTRACESETUP:
1065 return blk_trace_setup(sdp->device->request_queue, 1063 return blk_trace_setup(sdp->device->request_queue,
@@ -1261,7 +1259,7 @@ static void sg_rq_end_io(struct request *rq, int uptodate)
1261 1259
1262 sense = rq->sense; 1260 sense = rq->sense;
1263 result = rq->errors; 1261 result = rq->errors;
1264 resid = rq->data_len; 1262 resid = rq->resid_len;
1265 1263
1266 SCSI_LOG_TIMEOUT(4, printk("sg_cmd_done: %s, pack_id=%d, res=0x%x\n", 1264 SCSI_LOG_TIMEOUT(4, printk("sg_cmd_done: %s, pack_id=%d, res=0x%x\n",
1267 sdp->disk->disk_name, srp->header.pack_id, result)); 1265 sdp->disk->disk_name, srp->header.pack_id, result));
@@ -1378,7 +1376,8 @@ static Sg_device *sg_alloc(struct gendisk *disk, struct scsi_device *scsidp)
1378 sdp->device = scsidp; 1376 sdp->device = scsidp;
1379 INIT_LIST_HEAD(&sdp->sfds); 1377 INIT_LIST_HEAD(&sdp->sfds);
1380 init_waitqueue_head(&sdp->o_excl_wait); 1378 init_waitqueue_head(&sdp->o_excl_wait);
1381 sdp->sg_tablesize = min(q->max_hw_segments, q->max_phys_segments); 1379 sdp->sg_tablesize = min(queue_max_hw_segments(q),
1380 queue_max_phys_segments(q));
1382 sdp->index = k; 1381 sdp->index = k;
1383 kref_init(&sdp->d_ref); 1382 kref_init(&sdp->d_ref);
1384 1383
@@ -1657,6 +1656,10 @@ static int sg_start_req(Sg_request *srp, unsigned char *cmd)
1657 md->nr_entries = req_schp->k_use_sg; 1656 md->nr_entries = req_schp->k_use_sg;
1658 md->offset = 0; 1657 md->offset = 0;
1659 md->null_mapped = hp->dxferp ? 0 : 1; 1658 md->null_mapped = hp->dxferp ? 0 : 1;
1659 if (dxfer_dir == SG_DXFER_TO_FROM_DEV)
1660 md->from_user = 1;
1661 else
1662 md->from_user = 0;
1660 } 1663 }
1661 1664
1662 if (iov_count) { 1665 if (iov_count) {
@@ -2056,7 +2059,7 @@ sg_add_sfp(Sg_device * sdp, int dev)
2056 sg_big_buff = def_reserved_size; 2059 sg_big_buff = def_reserved_size;
2057 2060
2058 bufflen = min_t(int, sg_big_buff, 2061 bufflen = min_t(int, sg_big_buff,
2059 sdp->device->request_queue->max_sectors * 512); 2062 queue_max_sectors(sdp->device->request_queue) * 512);
2060 sg_build_reserve(sfp, bufflen); 2063 sg_build_reserve(sfp, bufflen);
2061 SCSI_LOG_TIMEOUT(3, printk("sg_add_sfp: bufflen=%d, k_use_sg=%d\n", 2064 SCSI_LOG_TIMEOUT(3, printk("sg_add_sfp: bufflen=%d, k_use_sg=%d\n",
2062 sfp->reserve.bufflen, sfp->reserve.k_use_sg)); 2065 sfp->reserve.bufflen, sfp->reserve.k_use_sg));