提交 1f2b69f9 编写于 作者: P Paul Mundt 提交者: Linus Torvalds

[PATCH] fb: sm501fb off-by-1 sysfs store

Currently sm501fb_crtsrc_store() won't allow the routing to be changed via
echos from userspace in to the sysfs file.  The reason for this is that the
strnicmp() for both heads uses a sizeof() for the string length, which ends
up being strlen() + 1 (\0 in the normal case, but the echo gives a newline,
which is where the issue occurs), this then causes a mismatch and
subsequently bails with the -EINVAL.

In addition to this, the hardcoded lengths were then used for the store
length that was returned, which ended up being erroneous and resulting in a
write error.  There's also no point in returning anything but the full
length since it will -EINVAL out on a mismatch well before then anyways.

sizeof("string") is great for making sure you have space in your buffer,
but rather less so for string comparisons :-)
Signed-off-by: NPaul Mundt <lethal@linux-sh.org>
Acked-by: NBen Dooks <ben-linux@fluff.org>
Cc: "Antonino A. Daplas" <adaplas@pol.net>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 69f7c0a1
...@@ -1074,9 +1074,9 @@ static ssize_t sm501fb_crtsrc_store(struct device *dev, ...@@ -1074,9 +1074,9 @@ static ssize_t sm501fb_crtsrc_store(struct device *dev,
if (len < 1) if (len < 1)
return -EINVAL; return -EINVAL;
if (strnicmp(buf, "crt", sizeof("crt")) == 0) if (strnicmp(buf, "crt", 3) == 0)
head = HEAD_CRT; head = HEAD_CRT;
else if (strnicmp(buf, "panel", sizeof("panel")) == 0) else if (strnicmp(buf, "panel", 5) == 0)
head = HEAD_PANEL; head = HEAD_PANEL;
else else
return -EINVAL; return -EINVAL;
...@@ -1098,7 +1098,7 @@ static ssize_t sm501fb_crtsrc_store(struct device *dev, ...@@ -1098,7 +1098,7 @@ static ssize_t sm501fb_crtsrc_store(struct device *dev,
writel(ctrl, info->regs + SM501_DC_CRT_CONTROL); writel(ctrl, info->regs + SM501_DC_CRT_CONTROL);
sm501fb_sync_regs(info); sm501fb_sync_regs(info);
return (head == HEAD_CRT) ? 3 : 5; return len;
} }
/* Prepare the device_attr for registration with sysfs later */ /* Prepare the device_attr for registration with sysfs later */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册