diff options
author | Paul Mundt <lethal@linux-sh.org> | 2007-03-05 03:30:31 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-03-05 10:57:51 -0500 |
commit | 1f2b69f9bdce8461341e5fb864568a2ee90079c8 (patch) | |
tree | cb773297c5e40f0e6ac3b183380140c41700521c /drivers/video | |
parent | 69f7c0a1be84b10a81b6edcce2dbee0cdec26eba (diff) |
[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: Paul Mundt <lethal@linux-sh.org>
Acked-by: Ben Dooks <ben-linux@fluff.org>
Cc: "Antonino A. Daplas" <adaplas@pol.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/video')
-rw-r--r-- | drivers/video/sm501fb.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/drivers/video/sm501fb.c b/drivers/video/sm501fb.c index 58c0ac733db9..0a44c44672c8 100644 --- a/drivers/video/sm501fb.c +++ b/drivers/video/sm501fb.c | |||
@@ -1074,9 +1074,9 @@ static ssize_t sm501fb_crtsrc_store(struct device *dev, | |||
1074 | if (len < 1) | 1074 | if (len < 1) |
1075 | return -EINVAL; | 1075 | return -EINVAL; |
1076 | 1076 | ||
1077 | if (strnicmp(buf, "crt", sizeof("crt")) == 0) | 1077 | if (strnicmp(buf, "crt", 3) == 0) |
1078 | head = HEAD_CRT; | 1078 | head = HEAD_CRT; |
1079 | else if (strnicmp(buf, "panel", sizeof("panel")) == 0) | 1079 | else if (strnicmp(buf, "panel", 5) == 0) |
1080 | head = HEAD_PANEL; | 1080 | head = HEAD_PANEL; |
1081 | else | 1081 | else |
1082 | return -EINVAL; | 1082 | return -EINVAL; |
@@ -1098,7 +1098,7 @@ static ssize_t sm501fb_crtsrc_store(struct device *dev, | |||
1098 | writel(ctrl, info->regs + SM501_DC_CRT_CONTROL); | 1098 | writel(ctrl, info->regs + SM501_DC_CRT_CONTROL); |
1099 | sm501fb_sync_regs(info); | 1099 | sm501fb_sync_regs(info); |
1100 | 1100 | ||
1101 | return (head == HEAD_CRT) ? 3 : 5; | 1101 | return len; |
1102 | } | 1102 | } |
1103 | 1103 | ||
1104 | /* Prepare the device_attr for registration with sysfs later */ | 1104 | /* Prepare the device_attr for registration with sysfs later */ |