All of lore.kernel.org
 help / color / mirror / Atom feed
From: Igor Grinberg <grinberg@compulab.co.il>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 4/4] dm: simplify the loop in lists_driver_lookup_name()
Date: Sun, 28 Sep 2014 21:49:00 +0300	[thread overview]
Message-ID: <5428581C.6070903@compulab.co.il> (raw)
In-Reply-To: <CAPnjgZ3ejXiGYrQgNZafF5K=Mp1sXLXMm_SEoo1g21MfL=4uvQ@mail.gmail.com>

Hi Masahiro, Simon,

On 09/28/14 18:22, Simon Glass wrote:
> Hi Masahiro,
> 
> On 28 September 2014 07:52, Masahiro Yamada <yamada.m@jp.panasonic.com> wrote:
>>         if (strncmp(name, entry->name, len))
>>                 continue;
>>
>>         /* Full match */
>>         if (len == strlen(entry->name))
>>                 return entry;
>>
>> is equivalent to:
>>
>>         if (!strcmp(name, entry->name))
>>                 return entry;
>>
>> The latter is simpler.
>>
>> Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
>> ---
>>
>>  drivers/core/lists.c | 9 +--------
>>  1 file changed, 1 insertion(+), 8 deletions(-)
>>
>> diff --git a/drivers/core/lists.c b/drivers/core/lists.c
>> index 699f94b..3a1ea85 100644
>> --- a/drivers/core/lists.c
>> +++ b/drivers/core/lists.c
>> @@ -24,19 +24,12 @@ struct driver *lists_driver_lookup_name(const char *name)
>>                 ll_entry_start(struct driver, driver);
>>         const int n_ents = ll_entry_count(struct driver, driver);
>>         struct driver *entry;
>> -       int len;
>>
>>         if (!drv || !n_ents)
>>                 return NULL;
>>
>> -       len = strlen(name);
>> -
>>         for (entry = drv; entry != drv + n_ents; entry++) {
>> -               if (strncmp(name, entry->name, len))
>> -                       continue;
>> -
>> -               /* Full match */
>> -               if (len == strlen(entry->name))
>> +               if (!strcmp(name, entry->name))
>>                         return entry;
>>         }
> 
> The discussion on this was here:
> 
> http://lists.denx.de/pipermail/u-boot/2014-September/189336.html
> 
> I don't see a lot of value in the extra code, so I think we should
> take this patch. If it is found to be a problem, we can go back to the
> defensive code and add a test case so it is clear what exactly we are
> defending against.
> 
> Acked-by: Simon Glass <sjg@chromium.org>
> 

Following the discussion referenced above, we have here a classic
case of C language strings problem.
One can dig about it all over the Internet (for example here [1]).
I don't think we will invent a solution for that problem here.
Also we are not about to abandon the C language...
So, unless someone comes out with a real case to solve, I think
we should merge this.

Acked-by: Igor Grinberg <grinberg@compulab.co.il>

[1] http://www.sei.cmu.edu/library/abstracts/news-at-sei/feature120061.cfm



-- 
Regards,
Igor.

  reply	other threads:[~2014-09-28 18:49 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-28 13:52 [U-Boot] [PATCH 0/4] dm: a collection of minor fixes in Driver-Model Masahiro Yamada
2014-09-28 13:52 ` [U-Boot] [PATCH 1/4] dm: fix comments Masahiro Yamada
2014-09-28 15:13   ` Simon Glass
2014-10-10  2:40     ` Simon Glass
2014-09-28 13:52 ` [U-Boot] [PATCH 2/4] dm: do not check the existence of uclass operation Masahiro Yamada
2014-09-28 15:15   ` Simon Glass
2014-10-10  2:41     ` Simon Glass
2014-09-28 13:52 ` [U-Boot] [PATCH 3/4] dm: do not check dm_root before searching in uclass_root Masahiro Yamada
2014-09-28 15:17   ` Simon Glass
2014-09-28 15:54     ` Masahiro YAMADA
2014-09-28 16:18       ` Simon Glass
2014-09-29  2:39         ` Masahiro Yamada
2014-10-05 18:22           ` Simon Glass
2014-09-28 13:52 ` [U-Boot] [PATCH 4/4] dm: simplify the loop in lists_driver_lookup_name() Masahiro Yamada
2014-09-28 15:20   ` Simon Glass
2014-09-28 15:22   ` Simon Glass
2014-09-28 18:49     ` Igor Grinberg [this message]
2014-10-10  2:42       ` Simon Glass

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=5428581C.6070903@compulab.co.il \
    --to=grinberg@compulab.co.il \
    --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.