mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: Li Lingfeng <lilingfeng3@huawei.com>
Cc: linux-kernel@vger.kernel.org, tj@kernel.org,
	akpm@linux-foundation.org, jack@suse.cz, bingjingc@synology.com,
	james.smart@broadcom.com, houtao1@huawei.com,
	yi.zhang@huawei.com, yangerkun@huawei.com, yukuai3@huawei.com
Subject: Re: [PATCH v2] lib: parser: optimize match_NUMER apis to use local array
Date: Tue, 10 Jan 2023 23:07:15 -0800	[thread overview]
Message-ID: <Y75gI7HRTiNzdfM4@sol.localdomain> (raw)
In-Reply-To: <20230111042215.4120156-1-lilingfeng3@huawei.com>

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

  reply	other threads:[~2023-01-11  7:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-11  4:22 [PATCH-next RESEND " Li Lingfeng
2023-01-11  7:07 ` Eric Biggers [this message]
2023-01-19 19:03 ` Tejun Heo

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=Y75gI7HRTiNzdfM4@sol.localdomain \
    --to=ebiggers@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=bingjingc@synology.com \
    --cc=houtao1@huawei.com \
    --cc=jack@suse.cz \
    --cc=james.smart@broadcom.com \
    --cc=lilingfeng3@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tj@kernel.org \
    --cc=yangerkun@huawei.com \
    --cc=yi.zhang@huawei.com \
    --cc=yukuai3@huawei.com \
    /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

all inboxes | Powered by JetHome®