All of lore.kernel.org
 help / color / mirror / Atom feed
From: York Sun <yorksun@freescale.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v3 11/16] net/eth.c: Add function to validate a MAC address
Date: Mon, 10 Aug 2015 13:03:21 -0700	[thread overview]
Message-ID: <55C90389.9090804@freescale.com> (raw)
In-Reply-To: <CANr=Z=b-vH4cLEKkhExR+RKHKOYsjFy8A2+W3-xXoOqZvuv7yg@mail.gmail.com>



On 08/10/2015 12:57 PM, Joe Hershberger wrote:
> Too much top-posting.
> 
> On Mon, Aug 10, 2015 at 2:41 PM, York Sun <yorksun@freescale.com> wrote:
>> SPL doesn't use net/eth.c. You add a call in env_flags.c.
>>
>> I think you can put it in header file and use static inline, or keep it in the
>> same file where it is called.
> 
> That is probably fine.
> 
>> Another way is to undef CONFIG_CMD_NET for SPL part. It is default to 'y' in
>> Kconfig. Joe may have some good suggestion.
> 
> I don't think this is the reason. The problem is that net is *not*
> build for SPL, but env is.

Yes, env is built. The offending lines in common/env_flags.c are gated by
"#ifdef CONFIG_CMD_NET". That's why I say it could be another way.

York


> 
>> On 08/10/2015 01:44 AM, Ciubotariu Codrin Constantin-B43658 wrote:
>>> Hi York,
>>>
>>> I didn't know that SPL uses net/eth.c . Could you please suggest a place for eth_validate_ethaddr_str()?
>>>
>>> Thanks and best regards,
>>> Codrin
>>>
>>>> -----Original Message-----
>>>> From: Sun York-R58495
>>>> Sent: Saturday, August 08, 2015 3:31 AM
>>>> To: Ciubotariu Codrin Constantin-B43658; u-boot at lists.denx.de
>>>> Cc: joe.hershberger at ni.com; Kushwaha Prabhakar-B32579
>>>> Subject: Re: [PATCH v3 11/16] net/eth.c: Add function to validate a MAC address
>>>>
>>>> On 07/24/2015 06:55 AM, Codrin Ciubotariu wrote:
>>>>> The code from common/env_flags.c that checks if a string has the
>>>>> format of a MAC address has been moved in net/eth.c as a separate
>>>>> function called eth_validate_ethaddr_str().
>>>>>
>>>>> Signed-off-by: Codrin Ciubotariu <codrin.ciubotariu@freescale.com>
>>>>> ---
>>>>>
>>>>> Changes for v3:
>>>>>     - none, new patch;
>>>>>
>>>>>  common/env_flags.c | 15 ++-------------
>>>>>  include/net.h      |  1 +
>>>>>  net/eth.c          | 30 ++++++++++++++++++++++++++++++
>>>>>  3 files changed, 33 insertions(+), 13 deletions(-)
>>>>>
>>>>> diff --git a/common/env_flags.c b/common/env_flags.c index
>>>>> 5189f5b..3e39fd1 100644
>>>>> --- a/common/env_flags.c
>>>>> +++ b/common/env_flags.c
>>>>> @@ -239,19 +239,8 @@ static int _env_flags_validate_type(const char *value,
>>>>>             }
>>>>>             break;
>>>>>     case env_flags_vartype_macaddr:
>>>>> -           cur = value;
>>>>> -           for (i = 0; i < 6; i++) {
>>>>> -                   skip_num(1, cur, &end, 2);
>>>>> -                   if (cur == end)
>>>>> -                           return -1;
>>>>> -                   if (cur + 2 == end && is_hex_prefix(cur))
>>>>> -                           return -1;
>>>>> -                   if (i != 5 && *end != ':')
>>>>> -                           return -1;
>>>>> -                   if (i == 5 && *end != '\0')
>>>>> -                           return -1;
>>>>> -                   cur = end + 1;
>>>>> -           }
>>>>> +           if (eth_validate_ethaddr_str(value))
>>>>> +                   return -1;
>>>>>             break;
>>>>>  #endif
>>>>>     case env_flags_vartype_end:
>>>>> diff --git a/include/net.h b/include/net.h index d17173d..c487aa7
>>>>> 100644
>>>>> --- a/include/net.h
>>>>> +++ b/include/net.h
>>>>> @@ -218,6 +218,7 @@ void eth_try_another(int first_restart);        /* Change the
>>>> device */
>>>>>  void eth_set_current(void);                /* set nterface to ethcur var */
>>>>>
>>>>>  int eth_get_dev_index(void);               /* get the device index */
>>>>> +int eth_validate_ethaddr_str(const char *addr);
>>>>>  void eth_parse_enetaddr(const char *addr, uchar *enetaddr);  int
>>>>> eth_getenv_enetaddr(char *name, uchar *enetaddr);  int
>>>>> eth_setenv_enetaddr(char *name, const uchar *enetaddr); diff --git
>>>>> a/net/eth.c b/net/eth.c index 953b731..a6fdf1b 100644
>>>>> --- a/net/eth.c
>>>>> +++ b/net/eth.c
>>>>> @@ -7,6 +7,7 @@
>>>>>   */
>>>>>
>>>>>  #include <common.h>
>>>>> +#include <linux/ctype.h>
>>>>>  #include <command.h>
>>>>>  #include <dm.h>
>>>>>  #include <environment.h>
>>>>> @@ -19,6 +20,35 @@
>>>>>
>>>>>  DECLARE_GLOBAL_DATA_PTR;
>>>>>
>>>>> +int eth_validate_ethaddr_str(const char *addr) {
>>>>> +   unsigned long val;
>>>>> +   int i;
>>>>> +   const char *cur;
>>>>> +   char *end;
>>>>> +
>>>>> +   if (!addr)
>>>>> +           return -1;
>>>>> +
>>>>> +   cur = addr;
>>>>> +   for (i = 0; i < 6; i++) {
>>>>> +           val = simple_strtoul(cur, &end, 16);
>>>>> +           if (cur + 1 != end && cur + 2 != end)
>>>>> +                   return -1;
>>>>> +           if (val > 0xff)
>>>>> +                   return -1;
>>>>> +           if (cur + 2 >= end && tolower(*(cur + 1)) == 'x')
>>>>> +                   return -1;
>>>>> +           if (i != 5 && *end != ':')
>>>>> +                   return -1;
>>>>> +           if (i == 5 && *end != '\0')
>>>>> +                   return -1;
>>>>> +           cur = end + 1;
>>>>> +   }
>>>>> +
>>>>> +   return 0;
>>>>> +}
>>>>> +
>>>>>  void eth_parse_enetaddr(const char *addr, uchar *enetaddr)  {
>>>>>     char *end;
>>>>>
>>>>
>>>> Codrin,
>>>>
>>>> This patch breaks most SPL targets. Please reconsider the location of
>>>> eth_validate_ethaddr_str().
>>>>
>>>> York
>> _______________________________________________
>> U-Boot mailing list
>> U-Boot at lists.denx.de
>> http://lists.denx.de/mailman/listinfo/u-boot

  reply	other threads:[~2015-08-10 20:03 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-24 13:55 [U-Boot] [PATCH v3 04/16] drivers/net/vsc9953: Fix missing reserved register Codrin Ciubotariu
2015-07-24 13:55 ` [U-Boot] [PATCH v3 05/16] include/bitfield: Add new bitfield operations Codrin Ciubotariu
2015-08-07 20:17   ` Joe Hershberger
2015-07-24 13:55 ` [U-Boot] [PATCH v3 06/16] drivers/net/vsc9953: Add default configuration for VSC9953 L2 Switch Codrin Ciubotariu
2015-08-07 20:17   ` Joe Hershberger
2015-07-24 13:55 ` [U-Boot] [PATCH v3 07/16] common/cmd_ethsw: Add generic commands for Ethernet Switches Codrin Ciubotariu
2015-08-07 20:18   ` Joe Hershberger
2015-08-07 22:58     ` York Sun
2015-08-10  5:47       ` Joe Hershberger
2015-07-24 13:55 ` [U-Boot] [PATCH v3 08/16] drivers/net/vsc9953: Use the generic Ethernet Switch parser Codrin Ciubotariu
2015-08-07 20:18   ` Joe Hershberger
2015-07-24 13:55 ` [U-Boot] [PATCH v3 09/16] drivers/net/vsc9953: Add command to show/clear port counters Codrin Ciubotariu
2015-08-07 20:18   ` Joe Hershberger
2015-07-24 13:55 ` [U-Boot] [PATCH v3 10/16] drivers/net/vsc9953: Add commands to enable/disable HW learning Codrin Ciubotariu
2015-08-07 20:18   ` Joe Hershberger
2015-07-24 13:55 ` [U-Boot] [PATCH v3 11/16] net/eth.c: Add function to validate a MAC address Codrin Ciubotariu
2015-08-07 20:18   ` Joe Hershberger
2015-08-08  0:30   ` York Sun
2015-08-10  8:44     ` Codrin Constantin Ciubotariu
2015-08-10 19:41       ` York Sun
2015-08-10 19:57         ` Joe Hershberger
2015-08-10 20:03           ` York Sun [this message]
2015-08-10 20:05             ` Joe Hershberger
2015-08-10 20:45               ` York Sun
2015-08-12 19:58                 ` York Sun
2015-08-13  7:33                   ` Codrin Constantin Ciubotariu
2015-08-13 15:42                   ` Codrin Constantin Ciubotariu
2015-08-13 15:54                     ` York Sun
2015-08-14  8:28                       ` Codrin Constantin Ciubotariu
2015-08-14 17:59                         ` York Sun
2015-08-17 14:37                           ` Joe Hershberger
2015-08-17 15:17                             ` York Sun
2015-08-19  7:21                             ` Codrin Constantin Ciubotariu
2015-07-24 13:55 ` [U-Boot] [PATCH v3 12/16] drivers/net/vsc9953: Add commands to manipulate the FDB for VSC9953 Codrin Ciubotariu
2015-08-07 20:18   ` Joe Hershberger
2015-07-24 13:55 ` [U-Boot] [PATCH v3 13/16] drivers/net/vsc9953: Add VLAN commands " Codrin Ciubotariu
2015-08-07 20:18   ` Joe Hershberger
2015-07-24 13:55 ` [U-Boot] [PATCH v3 14/16] drivers/net/vsc9953: Add command for shared/private VLAN learning Codrin Ciubotariu
2015-08-07 20:18   ` Joe Hershberger
2015-07-24 13:55 ` [U-Boot] [PATCH v3 15/16] drivers/net/vsc9953: Add commands for VLAN ingress filtering Codrin Ciubotariu
2015-08-07 20:18   ` Joe Hershberger
2015-07-24 13:55 ` [U-Boot] [PATCH v3 16/16] drivers/net/vsc9953: Add GPL-2.0+ SPDX-License-Identifier Codrin Ciubotariu
2015-08-07 20:19   ` Joe Hershberger
2015-08-07 20:17 ` [U-Boot] [PATCH v3 04/16] drivers/net/vsc9953: Fix missing reserved register Joe Hershberger

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=55C90389.9090804@freescale.com \
    --to=yorksun@freescale.com \
    --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 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.