Skip to content

Commit

Permalink
usb: musb: Fix a few off-by-one lengths
Browse files Browse the repository at this point in the history
!strncmp(buf, "force host", 9) is true if and only if buf starts with
"force hos". This was obviously not what was intended. The same error
exists for "force full-speed", "force high-speed" and "test
packet". Using strstarts avoids the error-prone hardcoding of the
prefix length.

For consistency, also change the other occurences of the !strncmp
idiom.

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Felipe Balbi <balbi@ti.com>
  • Loading branch information
Villemoes authored and Felipe Balbi committed Dec 22, 2014
1 parent b1d3478 commit e87c3f8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions drivers/usb/musb/musb_cppi41.c
Original file line number Diff line number Diff line change
Expand Up @@ -628,9 +628,9 @@ static int cppi41_dma_controller_start(struct cppi41_dma_controller *controller)
ret = of_property_read_string_index(np, "dma-names", i, &str);
if (ret)
goto err;
if (!strncmp(str, "tx", 2))
if (strstarts(str, "tx"))
is_tx = 1;
else if (!strncmp(str, "rx", 2))
else if (strstarts(str, "rx"))
is_tx = 0;
else {
dev_err(dev, "Wrong dmatype %s\n", str);
Expand Down
16 changes: 8 additions & 8 deletions drivers/usb/musb/musb_debugfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,30 +199,30 @@ static ssize_t musb_test_mode_write(struct file *file,
if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
return -EFAULT;

if (!strncmp(buf, "force host", 9))
if (strstarts(buf, "force host"))
test = MUSB_TEST_FORCE_HOST;

if (!strncmp(buf, "fifo access", 11))
if (strstarts(buf, "fifo access"))
test = MUSB_TEST_FIFO_ACCESS;

if (!strncmp(buf, "force full-speed", 15))
if (strstarts(buf, "force full-speed"))
test = MUSB_TEST_FORCE_FS;

if (!strncmp(buf, "force high-speed", 15))
if (strstarts(buf, "force high-speed"))
test = MUSB_TEST_FORCE_HS;

if (!strncmp(buf, "test packet", 10)) {
if (strstarts(buf, "test packet")) {
test = MUSB_TEST_PACKET;
musb_load_testpacket(musb);
}

if (!strncmp(buf, "test K", 6))
if (strstarts(buf, "test K"))
test = MUSB_TEST_K;

if (!strncmp(buf, "test J", 6))
if (strstarts(buf, "test J"))
test = MUSB_TEST_J;

if (!strncmp(buf, "test SE0 NAK", 12))
if (strstarts(buf, "test SE0 NAK"))
test = MUSB_TEST_SE0_NAK;

musb_writeb(musb->mregs, MUSB_TESTMODE, test);
Expand Down

0 comments on commit e87c3f8

Please sign in to comment.