On Wed, 2016-12-14 at 10:33 -0500, Alan Stern wrote: > On Wed, 14 Dec 2016, Todd Brandt wrote: > > > add debugfs support for experimenting with USB timing delay > > values on the fly. Values are read/written from debugfs at > > /sys/kernel/debug/usb/timing. > > > > Signed-off-by: Todd Brandt <todd.e.brandt@xxxxxxxxxxxxxxx> > > --- > > v2 changes: > > - moved the debug code from hub.c to usb.c > > - use debugfs instead of /sys/kernel/usb > > ... > > > +static int usb_timing_show(struct seq_file *s, void *unused) > > +{ > > + seq_printf(s, "tdrsmdn=%d\n", usb_timing.tdrsmdn); > > + seq_printf(s, "trsmrcy=%d\n", usb_timing.trsmrcy); > > + seq_printf(s, "trstrcy=%d\n", usb_timing.trstrcy); > > + return 0; > > +} > > + > > +static int usb_timing_open(struct inode *inode, struct file *file) > > +{ > > + return single_open(file, usb_timing_show, inode->i_private); > > +} > > + > > +static ssize_t usb_timing_write(struct file *file, > > + const char __user *ubuf, size_t count, loff_t *ppos) > > +{ > > + int val; > > + char buf[32]; > > + > > + if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) > > + return -EFAULT; > > + > > + if (sscanf(buf, "tdrsmdn=%u", &val) == 1) > > + usb_timing.tdrsmdn = max(val, USB_TIMING_TDRSMDN_MIN); > > + else if (sscanf(buf, "trsmrcy=%u", &val) == 1) > > + usb_timing.trsmrcy = max(val, USB_TIMING_TRSMRCY_MIN); > > + else if (sscanf(buf, "trstrcy=%u", &val) == 1) > > + usb_timing.trstrcy = max(val, USB_TIMING_TRSTRCY_MIN); > > Nit: Since the values in usb_timing are signed integers, and since val > is a signed integer, why do the sscanf calls use %u rather than %d? I just want the extra format checking for sscanf, it refuses negative integers (I prefer an -EINVAL in the event of a negative time input rather than a silient setting to VAL_MIN). I could declare val an unsigned int, but then "max(" throws a warning about a type mismatch, so I figured this was the simplest way to implement it without having to use any casts. > > Alan Stern > -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html