[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Y75gI7HRTiNzdfM4@sol.localdomain>
Date: Tue, 10 Jan 2023 23:07:15 -0800
From: Eric Biggers <ebiggers@...nel.org>
To: Li Lingfeng <lilingfeng3@...wei.com>
Cc: linux-kernel@...r.kernel.org, tj@...nel.org,
akpm@...ux-foundation.org, jack@...e.cz, bingjingc@...ology.com,
james.smart@...adcom.com, houtao1@...wei.com, yi.zhang@...wei.com,
yangerkun@...wei.com, yukuai3@...wei.com
Subject: Re: [PATCH v2] lib: parser: optimize match_NUMER apis to use local
array
On Wed, Jan 11, 2023 at 12:22:15PM +0800, Li Lingfeng wrote:
> /**
> * match_one - Determines if a string matches a simple pattern
> * @s: the string to examine for presence of the pattern
> @@ -129,14 +138,13 @@ EXPORT_SYMBOL(match_token);
> static int match_number(substring_t *s, int *result, int base)
> {
> char *endp;
> - char *buf;
> + char buf[NUMBER_BUF_LEN];
> int ret;
> long val;
>
> - buf = match_strdup(s);
> - if (!buf)
> - return -ENOMEM;
> -
> + if ((s->to - s->from) >= NUMBER_BUF_LEN)
> + return -ERANGE;
> + match_strlcpy(buf, s, NUMBER_BUF_LEN);
Instead of doing '(s->to - s->from) >= NUMBER_BUF_LEN', it would be simpler to
check the return value of match_strlcpy():
if (match_strlcpy(buf, s, NUMBER_BUF_LEN) >= NUMBER_BUF_LEN)
return -ERANGE;
Likewise in match_u64int() and match_uint().
- Eric
Powered by blists - more mailing lists