mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
To: Li Lingfeng <lilingfeng3@huawei.com>
Cc: linux-kernel@vger.kernel.org, jack@suse.cz,
	bingjingc@synology.com, ebiggers@google.com,
	james.smart@broadcom.com, houtao1@huawei.com,
	yi.zhang@huawei.com, yangerkun@huawei.com, yukuai3@huawei.com
Subject: Re: [PATCH-next] lib: parser: optimize match_NUMER apis to use local array
Date: Fri, 9 Dec 2022 06:57:10 -1000	[thread overview]
Message-ID: <Y5No5kMNGGJkmcPn@slm.duckdns.org> (raw)
In-Reply-To: <20221209063434.1566682-1-lilingfeng3@huawei.com>

Hello,

In general, I think this is a great idea. Some nits below:

On Fri, Dec 09, 2022 at 02:34:34PM +0800, Li Lingfeng wrote:
> +/*
> + * max size needed by diffrent bases to express U64
> + * HEX: "0xFFFFFFFFFFFFFFFF" --> 18
> + * DEC: "18446744073709551615" --> 20
> + * OCT: "01777777777777777777777" --> 23
> + * pick the max one to define U64_MAX_SIZE
> + */
> +#define U64_MAX_SIZE 23

Bikeshedding but how about naming it like NUMBER_BUF_LEN and including the
space for '\0'? Or just give it some extra space and make it 32 bytes.

> +static int match_strdup_local(const substring_t *s, char *buf)

I find it weird to name this as generic as match_strdup_local() and make it
assume that the buffer length is U64_MAX_SIZE + 1. Maybe just let the caller
pass in the buffer length as a parameter? Then, it's just strcpy and there
already is match_strlcpy() so we don't need this at all.

> +{
> +	size_t len = s->to - s->from;
> +
> +	if (!s->from)
> +		return -EINVAL;

If we use match_strlcpy() we lose the above null check but given that other
match_*() functions aren't doing it, this likely shouldn't matter.

Thanks.

-- 
tejun

  reply	other threads:[~2022-12-09 16:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-09  6:34 Li Lingfeng
2022-12-09 16:57 ` Tejun Heo [this message]
2022-12-10  2:51   ` lilingfeng (A)
2022-12-10 18:37     ` 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=Y5No5kMNGGJkmcPn@slm.duckdns.org \
    --to=tj@kernel.org \
    --cc=bingjingc@synology.com \
    --cc=ebiggers@google.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=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®