lkml.org 
[lkml]   [2023]   [Jan]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH-next v3] lib: parser: optimize match_NUMER apis to use local array
On Fri, Jan 20, 2023 at 10:13:04AM +0800, Li Lingfeng wrote:
> [PATCH-next v3] lib: parser: optimize match_NUMER apis to use

NUMER => NUMBER

> Memory will be allocated to store substring_t in match_strdup(), which means
> the caller of match_strdup() may need to be scheduled out to wait for reclaiming
> memory.

Text in commit messages should be wrapped at 72 columns.

> @@ -163,18 +169,16 @@ static int match_number(substring_t *s, int *result, int base)
> */
> static int match_u64int(substring_t *s, u64 *result, int base)
> {
> - char *buf;
> + char buf[NUMBER_BUF_LEN];
> int ret;
> u64 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);

As I requested on v2, the return value of match_strlcpy() should be used instead
of checking '((s->to - s->from) >= NUMBER_BUF_LEN'.

- Eric

\
 
 \ /
  Last update: 2023-03-26 23:48    [W:0.048 / U:0.200 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site