From: "Paul A. Clarke" <pc@us.ibm.com>
To: linux-fbdev-devel@lists.sourceforge.net
Subject: Re: [PATCH] fb: sm501fb off-by-1 sysfs store
Date: Fri, 02 Mar 2007 08:34:22 -0600 [thread overview]
Message-ID: <45E835EE.2060901@us.ibm.com> (raw)
In-Reply-To: <20070301133528.GA6504@linux-sh.org>
Paul Mundt wrote:
> On Thu, Mar 01, 2007 at 02:25:55PM +0100, Geert Uytterhoeven wrote:
>> On Thu, 1 Mar 2007, Paul Mundt wrote:
>>> @@ -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.
>>
> I stuck with the constants since they were already referenced in the
> function, and there are enough other places in the kernel where they're
> used for these things. I didn't figure that 5 was a terribly high number
> to count to, but if there's expected difficulty, strlen() is of course an
> option.
>
> Personally I find it less visually offensive with constants, but as long
> as the end number is the same, I'm not too concerned with how we get
> there. Feel free to change it if you wish.
My personal preference is to use sizeof("string")-1:
- guaranteed to be optimized to a constant (better than strlen)
- less likely to be left alone when "string" becomes "a different string"
(better than magic numbers)
I also prefer for repeated constants, either preprocessor macros (#define
OPTION_CRT "crt") or constant char arrays (static const char Option_CRT[] =
"crt"), or something like that, to ensure one copy of the string in the object.
But having the indirection here could add confusion for somebody trying to
quickly determine what "crt" does.
--
Regards,
Paul Clarke
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
prev parent reply other threads:[~2007-03-02 14:37 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-01 8:24 [PATCH] fb: sm501fb off-by-1 sysfs store Paul Mundt
2007-03-01 8:24 ` Paul Mundt
2007-03-01 9:16 ` Ben Dooks
2007-03-01 9:16 ` Ben Dooks
2007-03-01 13:25 ` Geert Uytterhoeven
2007-03-01 13:25 ` [Linux-fbdev-devel] " Geert Uytterhoeven
2007-03-01 13:35 ` Paul Mundt
2007-03-02 14:34 ` Paul A. Clarke [this message]
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=45E835EE.2060901@us.ibm.com \
--to=pc@us.ibm.com \
--cc=linux-fbdev-devel@lists.sourceforge.net \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.