From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9CB32C4332F for ; Sat, 10 Dec 2022 02:51:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229793AbiLJCvS (ORCPT ); Fri, 9 Dec 2022 21:51:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229634AbiLJCvP (ORCPT ); Fri, 9 Dec 2022 21:51:15 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A451C80A01 for ; Fri, 9 Dec 2022 18:51:13 -0800 (PST) Received: from dggpemm500011.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NTXS92BnrzRpkv; Sat, 10 Dec 2022 10:50:17 +0800 (CST) Received: from [10.174.179.155] (10.174.179.155) by dggpemm500011.china.huawei.com (7.185.36.110) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Sat, 10 Dec 2022 10:51:11 +0800 Message-ID: <8ed91647-f429-493e-b4e1-1f6bf11c228b@huawei.com> Date: Sat, 10 Dec 2022 10:51:11 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:104.0) Gecko/20100101 Thunderbird/104.0 Subject: Re: [PATCH-next] lib: parser: optimize match_NUMER apis to use local array To: Tejun Heo CC: , , , , , , , , References: <20221209063434.1566682-1-lilingfeng3@huawei.com> From: "lilingfeng (A)" In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.179.155] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500011.china.huawei.com (7.185.36.110) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 在 2022/12/10 0:57, Tejun Heo 写道: > 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. Yes, it's my mistake, I'll send a new patch soon. >> +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. Thank you for your advice. But I think match_number() is aimed to turn the string to num, so maybe it's better to return an error code rather than using match_stlcpy() to truncate it to give a wrong num when the string is too long to store. >> +{ >> + 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. Like this: match_strdup  kmemdup_nul   if (!s) // null check has been done here    return NULL So I think null check may be necessary. Thanks. > Thanks. >