LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Geert Uytterhoeven <geert@linux-m68k.org>
To: Paul Mundt <lethal@linux-sh.org>
Cc: Ben Dooks <ben@fluff.org.uk>,
Linux Frame Buffer Device Development
<linux-fbdev-devel@lists.sourceforge.net>,
Linux Kernel Development <linux-kernel@vger.kernel.org>
Subject: Re: [Linux-fbdev-devel] [PATCH] fb: sm501fb off-by-1 sysfs store
Date: Thu, 1 Mar 2007 14:25:55 +0100 (CET) [thread overview]
Message-ID: <Pine.LNX.4.62.0703011423060.766@pademelon.sonytel.be> (raw)
In-Reply-To: <20070301082456.GA3701@linux-sh.org>
On Thu, 1 Mar 2007, Paul Mundt wrote:
> 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.
> sizeof("string") is great for making sure you have space in your buffer,
> but rather less so for string comparisons :-)
> diff --git a/drivers/video/sm501fb.c b/drivers/video/sm501fb.c
> index 02b290c..72b5358 100644
> --- a/drivers/video/sm501fb.c
> +++ b/drivers/video/sm501fb.c
> @@ -1074,9 +1074,9 @@ static ssize_t sm501fb_crtsrc_store(struct device *dev,
> if (len < 1)
> return -EINVAL;
>
> - if (strnicmp(buf, "crt", sizeof("crt")) == 0)
> + if (strnicmp(buf, "crt", 3) == 0)
> head = HEAD_CRT;
> - else if (strnicmp(buf, "panel", sizeof("panel")) == 0)
> + else if (strnicmp(buf, "panel", 5) == 0)
> head = HEAD_PANEL;
> else
> return -EINVAL;
What about using just `strlen("string")' instead? ISTR gcc optimizes this to a
constant. Not that it matters that much, as the actual string won't be
duplicated.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
next prev parent reply other threads:[~2007-03-01 13:25 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-01 8:24 Paul Mundt
2007-03-01 9:16 ` Ben Dooks
2007-03-01 13:25 ` Geert Uytterhoeven [this message]
2007-03-01 13:35 ` [Linux-fbdev-devel] " Paul Mundt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.4.62.0703011423060.766@pademelon.sonytel.be \
--to=geert@linux-m68k.org \
--cc=ben@fluff.org.uk \
--cc=lethal@linux-sh.org \
--cc=linux-fbdev-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
--subject='Re: [Linux-fbdev-devel] [PATCH] fb: sm501fb off-by-1 sysfs store' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).