Re: [U-Boot] [PATCH] lib/string: added strndup

2012-01-05 Thread Mike Frysinger
On Thursday 05 January 2012 18:25:06 Wolfgang Denk wrote:
> Mike Frysinger wrote:
> > > + if ((s == NULL) ||
> > > + ((new = malloc (len + 1)) == NULL) ) {
> > > + return NULL;
> > > + }
> > 
> > please split this up such as:
> 
> I'm OK with the splitting, but...
> 
> > if (s == NULL)
> > return s;
> > 
> > new = malloc(len + 1);
> > if (new == NULL)
> > return new;
> 
> ... in both cases, a "return NULL" is much easier to parse for the
> human and identical for the compiler, so that should be used.

sure, np
-mike


signature.asc
Description: This is a digitally signed message part.
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH] lib/string: added strndup

2012-01-05 Thread Wolfgang Denk
Dear Mike Frysinger,

In message <201201051821.35774.vap...@gentoo.org> you wrote:
>
> > +   if ((s == NULL) ||
> > +   ((new = malloc (len + 1)) == NULL) ) {
> > +   return NULL;
> > +   }
>
> please split this up such as:

I'm OK with the splitting, but...

>   if (s == NULL)
>   return s;
>
>   new = malloc(len + 1);
>   if (new == NULL)
>   return new;

... in both cases, a "return NULL" is much easier to parse for the
human and identical for the compiler, so that should be used.

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: w...@denx.de
Good morning. This is the telephone company. Due  to  repairs,  we're
giving  you  advance notice that your service will be cut off indefi-
nitely at ten o'clock. That's two minutes from now.
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH] lib/string: added strndup

2012-01-05 Thread Mike Frysinger
On Thursday 22 December 2011 13:16:56 Grant Erickson wrote:
> +#ifndef __HAVE_ARCH_STRNDUP
> +extern char * strndup(const char *,__kernel_size_t);
> +#endif

no space after that first "*", and add a space after the ","

since your definition uses "size_t", then use that rather than __kernel_size_t

> --- a/lib/string.c
> +++ b/lib/string.c
> 
> +#ifndef __HAVE_ARCH_STRNDUP
> +char * strndup(const char *s, size_t n)

no space after that first "*"

> + if ((s == NULL) ||
> + ((new = malloc (len + 1)) == NULL) ) {
> + return NULL;
> + }

please split this up such as:
if (s == NULL)
return s;

new = malloc(len + 1);
if (new == NULL)
return new;

> + strncpy (new, s, len);

no space before that "("
-mike


signature.asc
Description: This is a digitally signed message part.
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH] lib/string: added strndup

2011-12-22 Thread Grant Erickson
On Dec 22, 2011, at 1:08 PM, Wolfgang Denk wrote:
> In message <1324577816-26198-1-git-send-email-maratho...@gmail.com> you wrote:
>> This patch adds optional support for strndup.
>> 
>> Signed-off-by: Grant Erickson 
>> ---
>> include/linux/string.h |3 +++
>> lib/string.c   |   21 +
>> 2 files changed, 24 insertions(+), 0 deletions(-)
> 
> What is this good for?  There are no users for this function (neither
> in mainline nor in any of the patches you have submitted).

Wolfgang:

I have a new board addition coming along shortly that leverages this.

Best,

Grant Erickson
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH] lib/string: added strndup

2011-12-22 Thread Wolfgang Denk
Dear Grant Erickson,

In message <1324577816-26198-1-git-send-email-maratho...@gmail.com> you wrote:
> This patch adds optional support for strndup.
> 
> Signed-off-by: Grant Erickson 
> ---
>  include/linux/string.h |3 +++
>  lib/string.c   |   21 +
>  2 files changed, 24 insertions(+), 0 deletions(-)

What is this good for?  There are no users for this function (neither
in mainline nor in any of the patches you have submitted).

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: w...@denx.de
The complexity of software is an essential property, not an  acciden-
tal  one. Hence, descriptions of a software entity that abstract away
its complexity often abstract away its essence.- Fred Brooks, Jr.
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot