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 X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 966D0C4338F for ; Thu, 29 Jul 2021 06:04:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 79D6161053 for ; Thu, 29 Jul 2021 06:04:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234137AbhG2GEQ convert rfc822-to-8bit (ORCPT ); Thu, 29 Jul 2021 02:04:16 -0400 Received: from szxga03-in.huawei.com ([45.249.212.189]:12329 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234005AbhG2GEP (ORCPT ); Thu, 29 Jul 2021 02:04:15 -0400 Received: from dggeme716-chm.china.huawei.com (unknown [172.30.72.56]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4Gb0Gj5y46z80H3; Thu, 29 Jul 2021 13:59:25 +0800 (CST) Received: from dggemi761-chm.china.huawei.com (10.1.198.147) by dggeme716-chm.china.huawei.com (10.1.199.112) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Thu, 29 Jul 2021 14:04:10 +0800 Received: from dggemi761-chm.china.huawei.com ([10.9.49.202]) by dggemi761-chm.china.huawei.com ([10.9.49.202]) with mapi id 15.01.2176.012; Thu, 29 Jul 2021 14:04:09 +0800 From: "Song Bao Hua (Barry Song)" To: Yury Norov , "linux-kernel@vger.kernel.org" , "gregkh@linuxfoundation.org" CC: "dave.hansen@intel.com" , "linux@rasmusvillemoes.dk" , "rafael@kernel.org" , "rdunlap@infradead.org" , "agordeev@linux.ibm.com" , "sbrivio@redhat.com" , "jianpeng.ma@intel.com" , "valentin.schneider@arm.com" , "peterz@infradead.org" , "bristot@redhat.com" , "guodong.xu@linaro.org" , tangchengchang , "Zengtao (B)" , yangyicong , "tim.c.chen@linux.intel.com" , Linuxarm , "akpm@linux-foundation.org" , "andriy.shevchenko@linux.intel.com" Subject: RE: [PATCH] bitmap: extend comment to bitmap_print_to_buf Thread-Topic: [PATCH] bitmap: extend comment to bitmap_print_to_buf Thread-Index: AQHXg+KZwXR9e68Y4UCjnNkvs7pIuqtZca+A Date: Thu, 29 Jul 2021 06:04:09 +0000 Message-ID: References: <20210715115856.11304-1-song.bao.hua@hisilicon.com> <20210728185831.215079-1-yury.norov@gmail.com> In-Reply-To: <20210728185831.215079-1-yury.norov@gmail.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.126.201.210] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > -----Original Message----- > From: Yury Norov [mailto:yury.norov@gmail.com] > Sent: Thursday, July 29, 2021 6:59 AM > To: linux-kernel@vger.kernel.org; gregkh@linuxfoundation.org; Song Bao Hua > (Barry Song) > Cc: Yury Norov ; dave.hansen@intel.com; > linux@rasmusvillemoes.dk; rafael@kernel.org; rdunlap@infradead.org; > agordeev@linux.ibm.com; sbrivio@redhat.com; jianpeng.ma@intel.com; > valentin.schneider@arm.com; peterz@infradead.org; bristot@redhat.com; > guodong.xu@linaro.org; tangchengchang ; Zengtao (B) > ; yangyicong ; > tim.c.chen@linux.intel.com; Linuxarm ; > akpm@linux-foundation.org; andriy.shevchenko@linux.intel.com > Subject: [PATCH] bitmap: extend comment to bitmap_print_to_buf > > Extend comment to new function to warn potential users about caveats. > > Signed-off-by: Yury Norov > --- Looks awesome. Thanks, Yury. I have integrated your patch into the latest series v8. > lib/bitmap.c | 18 ++++++++++++++++++ > 1 file changed, 18 insertions(+) > > diff --git a/lib/bitmap.c b/lib/bitmap.c > index 56bcffe2fa8c..b9f557ca668c 100644 > --- a/lib/bitmap.c > +++ b/lib/bitmap.c > @@ -545,6 +545,24 @@ EXPORT_SYMBOL(bitmap_print_to_pagebuf); > * mainly serves bin_attribute which doesn't work with exact one page, and it > * can break the size limit of converted decimal list and hexadecimal bitmask. > * > + * WARNING! > + * > + * This function is not a replacement for sprintf() or > bitmap_print_to_pagebuf(). > + * It is intended to workaround sysfs limitations discussed above and should > be > + * used carefully in general case for the following reasons: > + * - Time complexity is O(nbits^2/count), comparing to O(nbits) for snprintf(). > + * - Memory complexity is O(nbits), comparing to O(1) for snprintf(). > + * - @off and @count are NOT offset and number of bits to print. > + * - If printing part of bitmap as list, the resulting string is not a correct > + * list representation of bitmap. Particularly, some bits within or out of > + * related interval may be erroneously set or unset. The format of the string > + * may be broken, so bitmap_parselist-like parser may fail parsing it. > + * - If printing the whole bitmap as list by parts, user must ensure the order > + * of calls of the function such that the offset is incremented linearly. > + * - If printing the whole bitmap as list by parts, user must keep bitmap > + * unchanged between the very first and very last call. Otherwise concatenated > + * result may be incorrect, and format may be broken. > + * > * Returns the number of characters actually printed to @buf > */ > int bitmap_print_to_buf(bool list, char *buf, const unsigned long *maskp, > -- > 2.30.2 Thanks Barry