Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp3696304rwb; Fri, 9 Dec 2022 19:14:12 -0800 (PST) X-Google-Smtp-Source: AA0mqf4yNs3IeVkSE4ewNvv7khnNQ73Zd6kWAlu7foB0E21GpmuFdTiF9Dp85u7giDJ2xCmO1rPY X-Received: by 2002:a17:906:a410:b0:7c0:e5ca:411c with SMTP id l16-20020a170906a41000b007c0e5ca411cmr6667567ejz.17.1670642052085; Fri, 09 Dec 2022 19:14:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670642052; cv=none; d=google.com; s=arc-20160816; b=nOhH5IAGH2LJ3S+DxvsJn49+h5puwJhuIIvwfnxlnV+LA9DTS+8NP5X9AzHXQ2Kdf/ mqD1h95IrT2pVOjKaztMzNACDDojILI14a5naQ3vVM9gujpJRZt1uIOYgOgVwAjZUBXL 8xJvz7n6begGTpnS0++qotRyD8+V23mJm4Bx8HDbOTW5Q4xi90IyVtG0e8MRBWyN7jp6 ctayjvP7gcCj8CsfIEd9zK10dfbv9dMfujcOZI183bDWmCtWzgufpMmpLlxlr1L4irGo /YHE4K8XzWQheSvrAIEyGW+3uXq5TD/vbi+eTqiXFfmw5ITx5+3mNZaxFXFhx3wqzM5+ v7KA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id; bh=k56HUPx3pWFVuk6z6RWMNgTrEkY5QNqLHGKe4+Sl8YI=; b=LhFAbBGahbOGqvOqcgMblTv45+/6FCgqdDnsCULHQz6RLQHyP3FLRtBfOX8pIx2JXV 7JwUZDo5h1PYy+q3+P9iJI8PCH6GutGWerVeybjFytHuntqCfvWSmws4XTKOCrSz9t/f dWRzoJB7x6j7u15JOC92W8wGQUW+E25mtZvat8+XzIrNLdXUrXBB6nqNd557dz0/kLhV 8UL8WZ3/9Cv/YRc47xmeTeuPv5MHOC4M0LC7+k/hgDYe+HxHD3zYzhzxNJYt0+maG9o8 XP+c+wRkzbXEfmjKN66aZtKCZr+Z3ITB/KqnFyScIbNX9udsOjIIWlx0TjTBPhgrwA/t NG/Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ne42-20020a1709077baa00b007c0a6535f67si1449416ejc.736.2022.12.09.19.13.54; Fri, 09 Dec 2022 19:14:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229784AbiLJCvR (ORCPT + 75 others); Fri, 9 Dec 2022 21:51:17 -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 X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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. >