Commit dda8c33a authored by Jeremy Higdon's avatar Jeremy Higdon Committed by Dave Jones

[PATCH] sg.c to warn about ambiguous data direction

On Sat, Aug 28, 2004 at 02:39:45AM -0700, Jeremy Higdon wrote:
> > Jeremy,
> > You could use a (block scope) static and only print out
> > the warning the first time it is detected.
> >
> > Doug Gilbert
>
> Yes, that's a good idea -- I'll add a rate limiter and also print
> out the process name like James does in his recent deprecated
> ioctl warning patch.  I'll send a new patch out later this weekend.
> Sorry for the churn.
>
> thanks
>
> jeremy

Okay, I'm pretty happy with this.  I get this kind of output:

sg_write: data in/out 512/512 bytes for SCSI command 0x8--guessing data in;
   program java not setting count and/or reply_len properly
printk: 11 messages suppressed.
sg_write: data in/out 512/512 bytes for SCSI command 0x8--guessing data in;
   program java not setting count and/or reply_len properly
printk: 4 messages suppressed.


signed-off-by: jeremy@sgi.com
Signed-off-by: default avatarJames Bottomley <James.Bottomley@SteelEye.com>
parent f4eeee8e
...@@ -563,6 +563,19 @@ sg_write(struct file *filp, const char __user *buf, size_t count, loff_t * ppos) ...@@ -563,6 +563,19 @@ sg_write(struct file *filp, const char __user *buf, size_t count, loff_t * ppos)
hp->usr_ptr = NULL; hp->usr_ptr = NULL;
if (__copy_from_user(cmnd, buf, cmd_size)) if (__copy_from_user(cmnd, buf, cmd_size))
return -EFAULT; return -EFAULT;
/*
* SG_DXFER_TO_FROM_DEV is functionally equivalent to SG_DXFER_FROM_DEV,
* but is is possible that the app intended SG_DXFER_TO_DEV, because there
* is a non-zero input_size, so emit a warning.
*/
if (hp->dxfer_direction == SG_DXFER_TO_FROM_DEV)
if (printk_ratelimit())
printk(KERN_WARNING
"sg_write: data in/out %d/%d bytes for SCSI command 0x%x--"
"guessing data in;\n" KERN_WARNING " "
"program %s not setting count and/or reply_len properly\n",
old_hdr.reply_len - SZ_SG_HEADER, input_size,
(unsigned int) cmnd[0], current->comm);
k = sg_common_write(sfp, srp, cmnd, sfp->timeout, blocking); k = sg_common_write(sfp, srp, cmnd, sfp->timeout, blocking);
return (k < 0) ? k : count; return (k < 0) ? k : count;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment