From nobody Sun May 5 19:12:40 2024 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 C06D0C433F5 for ; Thu, 2 Dec 2021 20:16:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348742AbhLBUTm (ORCPT ); Thu, 2 Dec 2021 15:19:42 -0500 Received: from smtp08.smtpout.orange.fr ([80.12.242.130]:62491 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348698AbhLBUTb (ORCPT ); Thu, 2 Dec 2021 15:19:31 -0500 Received: from pop-os.home ([86.243.171.122]) by smtp.orange.fr with ESMTPA id ssUvmqRgBozlissUvmqm80; Thu, 02 Dec 2021 21:16:07 +0100 X-ME-Helo: pop-os.home X-ME-Auth: YWZlNiIxYWMyZDliZWIzOTcwYTEyYzlhMmU3ZiQ1M2U2MzfzZDfyZTMxZTBkMTYyNDBjNDJlZmQ3ZQ== X-ME-Date: Thu, 02 Dec 2021 21:16:07 +0100 X-ME-IP: 86.243.171.122 From: Christophe JAILLET To: boris.ostrovsky@oracle.com, jgross@suse.com, sstabellini@kernel.org, roger.pau@citrix.com, axboe@kernel.dk Cc: xen-devel@lists.xenproject.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET Subject: [PATCH v2] xen-blkfront: Use the bitmap API when applicable Date: Thu, 2 Dec 2021 21:16:04 +0100 Message-Id: X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Use 'bitmap_zalloc()' to simplify code, improve the semantic and avoid some open-coded arithmetic in allocator arguments. Also change the corresponding 'kfree()' into 'bitmap_free()' to keep consistency. Use 'bitmap_copy()' to avoid an explicit 'memcpy()' Signed-off-by: Christophe JAILLET Acked-by: Roger Pau Monn=C3=A9 --- v1 --> v2: change another kfree into bitmap_free --- drivers/block/xen-blkfront.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index 700c765a759a..69cf13608ce0 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c @@ -442,22 +442,20 @@ static int xlbd_reserve_minors(unsigned int minor, un= signed int nr) if (end > nr_minors) { unsigned long *bitmap, *old; =20 - bitmap =3D kcalloc(BITS_TO_LONGS(end), sizeof(*bitmap), - GFP_KERNEL); + bitmap =3D bitmap_zalloc(end, GFP_KERNEL); if (bitmap =3D=3D NULL) return -ENOMEM; =20 spin_lock(&minor_lock); if (end > nr_minors) { old =3D minors; - memcpy(bitmap, minors, - BITS_TO_LONGS(nr_minors) * sizeof(*bitmap)); + bitmap_copy(bitmap, minors, nr_minors); minors =3D bitmap; nr_minors =3D BITS_TO_LONGS(end) * BITS_PER_LONG; } else old =3D bitmap; spin_unlock(&minor_lock); - kfree(old); + bitmap_free(old); } =20 spin_lock(&minor_lock); @@ -2610,7 +2608,7 @@ static void __exit xlblk_exit(void) =20 xenbus_unregister_driver(&blkfront_driver); unregister_blkdev(XENVBD_MAJOR, DEV_NAME); - kfree(minors); + bitmap_free(minors); } module_exit(xlblk_exit); =20 --=20 2.30.2