From: Stefan Althoefer <stefan.althoefer@web.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] common: nvedit to protect additional ethernet addresses Part 1/1
Date: Sun, 07 Dec 2008 19:54:14 +0100 [thread overview]
Message-ID: <ghh632$ims$1@ger.gmane.org> (raw)
In-Reply-To: <20081207162658.62FC1834B020@gemini.denx.de>
Wolfgang Denk schrieb:
> Dear Stefan Althoefer,
>
> In message <ghgj6n$sen$1@ger.gmane.org> you wrote:
>> From fdeee62f0902b25be1a2a6bf52fb714b0f4f9e59 Mon Sep 17 00:00:00 2001
>> From: Stefan Althoefer <stefan.althoefer@web.de>
>> Date: Sun, 7 Dec 2008 14:17:08 +0100
>> Subject: [PATCH] common: nvedit to protect additional ethernet addresses
>>
>> This adds "eth[0-9]+addr" to the protected
>> environment variables that can only be written once.
>>
>> Code for detecting protected variables was restructured.
>>
>> Signed-off-by: Stefan Althoefer <stefan.althoefer@web.de>
> ...
>> @@ -181,18 +186,31 @@ int _do_setenv (int flag, int argc, char *argv[])
>> * Ethernet Address and serial# can be set only once,
>> * ver is readonly.
>> */
>> - if (
>> + protected = 0;
>> #ifdef CONFIG_HAS_UID
>> /* Allow serial# forced overwrite with 0xdeaf4add flag */
>> - ((strcmp (name, "serial#") == 0) && (flag != 0xdeaf4add)) ||
>> + if ((strcmp (name, "serial#") == 0) && (flag != 0xdeaf4add))
>> #else
>> - (strcmp (name, "serial#") == 0) ||
>> + if (strcmp (name, "serial#") == 0)
>> #endif
>> - ((strcmp (name, "ethaddr") == 0)
>> + protected = 1;
>
> Here we already know that the variable is "serial#", so it cannot be
> any of the "eth*addr" variables.
>
>> + if (strcmp (name, "ethaddr") == 0)
>> #if defined(CONFIG_OVERWRITE_ETHADDR_ONCE) && defined(CONFIG_ETHADDR)
>> - && (strcmp ((char *)env_get_addr(oldval),MK_STR(CONFIG_ETHADDR)) != 0)
>> + /* Allow "ethaddr" overwrite to change pre-configured address */
>> + if (strcmp ((char *)env_get_addr(oldval),MK_STR(CONFIG_ETHADDR)) != 0)
>> #endif /* CONFIG_OVERWRITE_ETHADDR_ONCE && CONFIG_ETHADDR */
>> - ) ) {
>> + protected = 1;
>> +
>> + /* "eth[0-9]+addr" is always protected */
>> + if (strncmp (name, "eth", 3) == 0) {
>> + ethnum = simple_strtoul (name+3, &s, 10);
>> + if (s != name + 3)
>> + if (strcmp (s, "addr") == 0)
>> + protected = 1;
>> + }
>
> Then why do we continue to test for these impossible cases? It's just
> wasting CPU cycles.
>
> Best regards,
>
> Wolfgang Denk
>
You argue that the code should have a couple of hard to read else cases?
--- Stefan
next prev parent reply other threads:[~2008-12-07 18:54 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-12-04 12:28 [U-Boot] [PATCH] common: nvedit to protect additional ethernet addresses Part 1/1 stefan.althoefer at web.de
2008-12-04 12:46 ` Jerry Van Baren
2008-12-04 17:57 ` Ben Warren
2008-12-04 20:48 ` Jerry Van Baren
2008-12-05 21:22 ` Stefan Althoefer
2008-12-07 0:43 ` Wolfgang Denk
2008-12-07 2:53 ` Jerry Van Baren
2008-12-07 5:47 ` Ben Warren
2008-12-07 9:33 ` Wolfgang Denk
2008-12-07 13:31 ` Stefan Althoefer
2008-12-07 16:26 ` Wolfgang Denk
2008-12-07 18:54 ` Stefan Althoefer [this message]
2008-12-07 21:25 ` Wolfgang Denk
2008-12-07 23:52 ` Stefan Althoefer
2008-12-15 22:55 ` Wolfgang Denk
2008-12-16 21:34 ` Stefan Althoefer
2008-12-08 20:14 ` Jerry Van Baren
-- strict thread matches above, loose matches on Subject: below --
2008-12-04 20:06 Stefan Althöfer
2008-12-04 21:06 ` Ben Warren
2008-12-15 22:56 ` Wolfgang Denk
2008-12-16 19:15 ` Stefan Althoefer
2008-12-16 19:22 ` Ben Warren
2008-12-16 20:55 ` Wolfgang Denk
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='ghh632$ims$1@ger.gmane.org' \
--to=stefan.althoefer@web.de \
--cc=u-boot@lists.denx.de \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox