Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp5843466pxv; Wed, 28 Jul 2021 23:07:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzuVO/+AXFXz3MCCu9o4tvJq/cK9ULP/ibpFvmi09Am7lVfE1AHdPK8K1zTWvxGUGEqdlFG X-Received: by 2002:a05:6402:2788:: with SMTP id b8mr4153999ede.244.1627538860134; Wed, 28 Jul 2021 23:07:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627538860; cv=none; d=google.com; s=arc-20160816; b=ic17nxcTKl/xQwCZLnhnS9oOAo/gb9ntWLaNYu+KtVOmDLIDWyds9qCGb2BkjUkXjX DWna0RU9dmeb/dksxx9FlHXwLtxEs9PHR5d4OHaIhjv0MuES30ObQoiOga90n7ZhVqs/ vBfjkyf0z71hj1Isvb7eZHqHKwsgkjdodDrruf38FC1/5hFVsr+OETHRRJA1Kxlu7lDC XTOoBvE9hZ9AIOmsAhx6K/AWxdOl+27S16EV1m5y1ARNLD4zCFFewUjvNX0jMgxKfRNW v51G/cY27tRPDcvd+Bx/Rbepf1mUIrHDgFjH8AUas90TmJwGcTWU+VTjUv7mlFaa9SA6 L36w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from; bh=8QJmmyTKX+yGjhTDkvrmN/ka/qIiAyirI3Oam+PB6kQ=; b=CUrA9OPQwmLR+V9R9DrUDEaj+VWnCVAopbSNM5yCAs8wHokrb203CUrafEIAiHaZuT hZp6C37u84D8+FZwqjzNS7hB6zzng417xr1X7DqILl6dTKTnegdYj2uD2EN1crNzq0gI 1DYG7qxF4c9oZbiH60mfMylbePDSYOqXF13q0NQU62sMmUtolYDykcVjrgCS9IPxQMUe 5MjkxcaDO8Qpqov3Jh0o00pX6KlDMXAA6M8ghbekmaT/JAe3Mk5ONIVnkt/u4i3EscTk vfJoLjYER89lpOMYfEGtYCf0kiWIDJXHbrqHH8AAmlQNchHUkekn5qEhtEbADcfji/an 4KDg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=hisilicon.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dz12si1765081edb.321.2021.07.28.23.07.17; Wed, 28 Jul 2021 23:07:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=hisilicon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234303AbhG2GEQ convert rfc822-to-8bit (ORCPT + 99 others); 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