public inbox for linux-omap@vger.kernel.org
 help / color / mirror / Atom feed
From: Omar Ramirez Luna <omar.ramirez@ti.com>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: linux-omap <linux-omap@vger.kernel.org>,
	Andy Shevchenko <ext-andriy.shevchenko@nokia.com>
Subject: Re: [PATCH] dspbridge: Simplify Atoi() method
Date: Tue, 9 Feb 2010 20:02:41 -0600	[thread overview]
Message-ID: <4B7213C1.1040300@ti.com> (raw)
In-Reply-To: <1265192086-15633-1-git-send-email-andy.shevchenko@gmail.com>

Hi,

On 2/3/2010 4:14 AM, Andy Shevchenko wrote:
> From: Andy Shevchenko<ext-andriy.shevchenko@nokia.com>
>
> Try to use simple_strtol() kernel native method instead.

strtol or strtoul?

>
> However, there are opened questions:
>   - why type of Atoi() is s32 if the sign is used only to detect base?
>   - should we really to check hex integers like DEAD0123h?
>   - how many spaces could lead token?
>
> Signed-off-by: Andy Shevchenko<ext-andriy.shevchenko@nokia.com>
> ---
>   drivers/dsp/bridge/rmgr/dbdcd.c |   42 +++++---------------------------------
>   1 files changed, 6 insertions(+), 36 deletions(-)
>
> diff --git a/drivers/dsp/bridge/rmgr/dbdcd.c b/drivers/dsp/bridge/rmgr/dbdcd.c
> index caa57f1..fe2ed57 100644
> --- a/drivers/dsp/bridge/rmgr/dbdcd.c
> +++ b/drivers/dsp/bridge/rmgr/dbdcd.c
> @@ -1002,50 +1002,20 @@ DSP_STATUS DCD_UnregisterObject(IN struct DSP_UUID *pUuid,
>    */
>   static s32 Atoi(char *pszBuf)
>   {
> -	s32 result = 0;
>   	char *pch = pszBuf;
> -	char c;
> -	char first;
> -	s32 base = 10;
> -	s32 len;
> +	s32 base = 0;
>
>   	while (isspace(*pch))
>   		pch++;
>
> -	first = *pch;
> -	if (first == '-' || first == '+') {
> +	if (*pch == '-' || *pch == '+') {
> +		base = 10;
>   		pch++;
> -	} else {
> -		/* Determine if base 10 or base 16 */
> -		len = strlen(pch);
> -		if (len>  1) {
> -			c = pch[1];
> -			if ((*pch == '0'&&  (c == 'x' || c == 'X'))) {
> -				base = 16;
> -				pch += 2;
> -			}
> -			c = pch[len - 1];
> -			if (c == 'h' || c == 'H')
> -				base = 16;
> -
> -		}
> -	}
> -
> -	while (isdigit(c = *pch) || ((base == 16)&&  isxdigit(c))) {
> -		result *= base;
> -		if ('A'<= c&&  c<= 'F') {
> -			c = c - 'A' + 10;
> -		} else {
> -			if ('a'<= c&&  c<= 'f')
> -				c = c - 'a' + 10;
> -			else
> -				c -= '0';
> -		}
> -		result += c;
> -		++pch;
> +	} else if (*pch&&  (pch[strlen(pch) - 1] | 0x20 == 'h')) {

perhaps tolower(x)

otherwise: (pch[strlen(pch) - 1] | 0x20 == 'h')
should be ((pch[strlen(pch) - 1] | 0x20) == 'h')

> +		base = 16;
>   	}
>
> -	return result;
> +	return simple_strtoul(pch, NULL, base);
>   }
>
>   /*

- omar

  reply	other threads:[~2010-02-10  2:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-03 10:14 [PATCH] dspbridge: Simplify Atoi() method Andy Shevchenko
2010-02-10  2:02 ` Omar Ramirez Luna [this message]
2010-02-10  7:58   ` [PATCH] dspbridge: Simplify Atoi() method (v2) Andy Shevchenko
2010-02-16 23:49     ` Omar Ramirez Luna
2010-02-10  7:59   ` [PATCH] dspbridge: Simplify Atoi() method Andy Shevchenko
2010-02-10 15:55     ` Omar Ramirez Luna

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=4B7213C1.1040300@ti.com \
    --to=omar.ramirez@ti.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=ext-andriy.shevchenko@nokia.com \
    --cc=linux-omap@vger.kernel.org \
    /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