Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp160338pxj; Thu, 3 Jun 2021 03:34:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx2NGs4VUGIYOPbZWnCeYOFGbElsnEWe19Ts89afREKeL3/OteV3p1CWLIUGYMynu9ps6td X-Received: by 2002:a05:6402:693:: with SMTP id f19mr16429575edy.185.1622716488273; Thu, 03 Jun 2021 03:34:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622716488; cv=none; d=google.com; s=arc-20160816; b=kxDaAQfmMfJluAFf1CxAkX90W4dZ4rrRCgBHd8lH34MF4ffRjoSYZR/yyT56saaG/4 FmG7csnhRo7Wa2nIAXx6d89jv2Vjc4MoauqP7P5+qH5SbOnUAAdfGpVUB66j9xmEflXe mvwGSBh6vnhBVrkUKW78h2Cy9E7bQ41BXzhROFNaWJDqUeUrqfCHZ9TSZ7j/zGVzSRTo /ByMqFvfaaKJ131o+z0jSEepz+D1BVVxe2AOJL/fAaAaW9ixRFlk1NzcMto8YQ/SKYw7 xNmdM9YdhHGx8U+zHu7vR1gEKe4i5VP7HoNuCD3qoxhxs//oHjA4BmdJ66fqX5dHfA9N VXVg== 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 :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=zR7WSktB8JI4AC85KLdBlwovlCqDPN9Utefxgb2M8c0=; b=inP4xb6ChnaadIZAirRrW1pmliQMySqq0zd1XLaBZX8LHS+SfDAvQNtmcu3fcaTsdo 7b3YW6iKtZS+8rkJf9HPEYEQyssIpG0bOEUh7FGm+/7mbd3ZuQQyxcMOsos6htR+nZeT 6+WHzEkYTFia2mJggCUm82lIQUKSp6wKM21o5wMgSnixLTi70uzV5oMxiGgSaFJfdBzm sYFVDr75yvFXjIhCUOhooGBVx9pnEAY437lflHPwUJcT02OnqG1UuvOY0NKvsAzO0quo r7b2326YWAaHyoHQemrxLNVpP3jhgjH/KshXRanPD0HIcqNQNdtdZ3ZbwIkknNxdRYj6 gWWA== 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=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o15si1986063eju.373.2021.06.03.03.34.24; Thu, 03 Jun 2021 03:34:48 -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=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229754AbhFCKfM (ORCPT + 99 others); Thu, 3 Jun 2021 06:35:12 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:3530 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229629AbhFCKfM (ORCPT ); Thu, 3 Jun 2021 06:35:12 -0400 Received: from dggeme759-chm.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4FwhxY0g7yzZcDb; Thu, 3 Jun 2021 18:30:41 +0800 (CST) Received: from [127.0.0.1] (10.40.188.144) by dggeme759-chm.china.huawei.com (10.3.19.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Thu, 3 Jun 2021 18:33:26 +0800 Subject: Re: [PATCH v3 1/3] lib: bitmap: introduce bitmap_print_to_buf To: Andy Shevchenko , Tian Tao CC: , , , , , , Randy Dunlap , Stefano Brivio , Alexander Gordeev , "Ma, Jianpeng" , Yury Norov , Valentin Schneider , Peter Zijlstra , Daniel Bristot de Oliveira References: <1622712162-7028-1-git-send-email-tiantao6@hisilicon.com> <1622712162-7028-2-git-send-email-tiantao6@hisilicon.com> From: "tiantao (H)" Message-ID: <95f5e01d-79c1-28f3-f27b-bee4398308de@huawei.com> Date: Thu, 3 Jun 2021 18:33:25 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.40.188.144] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggeme759-chm.china.huawei.com (10.3.19.105) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 在 2021/6/3 17:50, Andy Shevchenko 写道: > On Thu, Jun 03, 2021 at 05:22:40PM +0800, Tian Tao wrote: >> New API bitmap_print_to_buf() with bin_attribute to avoid maskp >> exceeding PAGE_SIZE. bitmap_print_to_pagebuf() is a special case >> of bitmap_print_to_buf(), so in bitmap_print_to_pagebuf() call >> bitmap_print_to_buf(). > ... > >> /** >> + * bitmap_print_to_buf - convert bitmap to list or hex format ASCII string >> + * @list: indicates whether the bitmap must be list >> + * @buf: the kernel space buffer to read to >> + * @maskp: pointer to bitmap to convert >> + * @nmaskbits: size of bitmap, in bits >> + * @off: offset in data buffer below >> + * @count: the maximum number of bytes to print >> + * >> + * The role of bitmap_print_to_buf() and bitmap_print_to_pagebuf() is >> + * the same, the difference is that buf of bitmap_print_to_buf() >> + * can be more than one pagesize. >> + */ >> +int bitmap_print_to_buf(bool list, char *buf, const unsigned long *maskp, >> + int nmaskbits, loff_t off, size_t count) >> +{ >> + const char *fmt = list ? "%*pbl\n" : "%*pb\n"; >> + ssize_t size; >> + void *data; >> + >> + if (off == LLONG_MAX && count == PAGE_SIZE - offset_in_page(buf)) >> + return scnprintf(buf, count, fmt, nmaskbits, maskp); >> + >> + data = kasprintf(GFP_KERNEL, fmt, nmaskbits, maskp); >> + if (!data) >> + return -ENOMEM; >> + >> + size = memory_read_from_buffer(buf, count, &off, data, strlen(data) + 1); > Are you sure you have put parameters in the correct order? yes, I already test it. ssize_t memory_read_from_buffer(void *to, size_t count, loff_t *ppos,                                 const void *from, size_t available) > >> + kfree(data); >> + >> + return size; >> +} > I guess you have to provide the test case(s). >