Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3364504pxb; Sat, 23 Oct 2021 23:55:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5Pe93PJYCCrWRTQYm+avBshsBKnrHoImzz9Vtg8rsYEuBnLz5Y1GjSB8i6YuiHi9GH6Qw X-Received: by 2002:a50:be81:: with SMTP id b1mr15608597edk.59.1635058546894; Sat, 23 Oct 2021 23:55:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635058546; cv=none; d=google.com; s=arc-20160816; b=kyDOFL59Re99Drus4iqbeJ5R3hoBdh0b1VK5zqXbjXi6HT3tj7U3O4i0Muwu62EOy5 dN474awsWnwrPN0yDKWx/gGbERYtc0N6A9cUe0nZsU60+UeuUrClKtlMG00W5vviB6n3 OduwxlYh9QWYZPP5AUr7RBVlUlwU1geD+04sF6fpjMoiN+aUEv/lNSXx5NYS3jQCF+ka G43BeI9jKYJz7YhVIGAY1iLpollasAQnGy1bUvFJyeDIyHucaKSqbUM9DSOEGhBkz7zL VnUPPXMnPfSLhzRAxcxVHsXDi7S8Q8N5ivupmrFDqtWiEp7SqsBdlw8BNrM/dM8Ah8DN kNnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=wCtlEfgvTxPLFt5fv0hFrSxhFCYx6lRUL4Ww0p20DSI=; b=ebwqi/eRVpV6Jdy+famOIRX1YRbCXqNHlEYbe5O+Rcy2d3vHWF6vvqK/oDxFf3yRpU I54lQlK7JsTETig2iGRU5Mowq6vQcfr5KdOfzkaDJDbrPzA3MPfY12pjZxpXY/jmUtul 15MVFTX0fE2m7M1WcLnNm6P4z53wLJ6tGIHnMYABcfYV1j43sNm12EIu7KXZgwBYIJIk O9qfAubRLio4wJFOEZHKRaH9FAJ+9PmNTFYwmz74Qg5h5qDv6/XeP20R/xEbdfpY6iMm ggIrzal0fJCpQpDO+mATiZJ675Ht3qhvrSgSoolSkpRWiaPMGZnPnl/CGbmzcD6XSJ3u Ocqg== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id fh20si3702021ejc.295.2021.10.23.23.55.23; Sat, 23 Oct 2021 23:55:46 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230021AbhJXGyB (ORCPT + 99 others); Sun, 24 Oct 2021 02:54:01 -0400 Received: from smtp07.smtpout.orange.fr ([80.12.242.129]:53809 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229463AbhJXGyB (ORCPT ); Sun, 24 Oct 2021 02:54:01 -0400 Received: from pop-os.home ([92.140.161.106]) by smtp.orange.fr with ESMTPA id eXM2m8BUn65jHeXM2m5OFT; Sun, 24 Oct 2021 08:51:39 +0200 X-ME-Helo: pop-os.home X-ME-Auth: YWZlNiIxYWMyZDliZWIzOTcwYTEyYzlhMmU3ZiQ1M2U2MzfzZDfyZTMxZTBkMTYyNDBjNDJlZmQ3ZQ== X-ME-Date: Sun, 24 Oct 2021 08:51:39 +0200 X-ME-IP: 92.140.161.106 From: Christophe JAILLET To: kishon@ti.com, lorenzo.pieralisi@arm.com, kw@linux.com, bhelgaas@google.com Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET Subject: [PATCH] PCI: endpoint: Use 'bitmap_zalloc()' when applicable Date: Sun, 24 Oct 2021 08:51:36 +0200 Message-Id: <01eba3c86137eb348f8cce69f500222bd7c72c57.1635058203.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 'mem->bitmap' is a bitmap. So 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. Finally, while at it, axe the useless 'bitmap' variable and use 'mem->bitmap' directly. Signed-off-by: Christophe JAILLET --- drivers/pci/endpoint/pci-epc-mem.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/drivers/pci/endpoint/pci-epc-mem.c b/drivers/pci/endpoint/pci-epc-mem.c index a97b56a6d2db..b15a264f19af 100644 --- a/drivers/pci/endpoint/pci-epc-mem.c +++ b/drivers/pci/endpoint/pci-epc-mem.c @@ -49,10 +49,8 @@ int pci_epc_multi_mem_init(struct pci_epc *epc, unsigned int num_windows) { struct pci_epc_mem *mem = NULL; - unsigned long *bitmap = NULL; unsigned int page_shift; size_t page_size; - int bitmap_size; int pages; int ret; int i; @@ -72,7 +70,6 @@ int pci_epc_multi_mem_init(struct pci_epc *epc, page_size = PAGE_SIZE; page_shift = ilog2(page_size); pages = windows[i].size >> page_shift; - bitmap_size = BITS_TO_LONGS(pages) * sizeof(long); mem = kzalloc(sizeof(*mem), GFP_KERNEL); if (!mem) { @@ -81,8 +78,8 @@ int pci_epc_multi_mem_init(struct pci_epc *epc, goto err_mem; } - bitmap = kzalloc(bitmap_size, GFP_KERNEL); - if (!bitmap) { + mem->bitmap = bitmap_zalloc(pages, GFP_KERNEL); + if (!mem->bitmap) { ret = -ENOMEM; kfree(mem); i--; @@ -92,7 +89,6 @@ int pci_epc_multi_mem_init(struct pci_epc *epc, mem->window.phys_base = windows[i].phys_base; mem->window.size = windows[i].size; mem->window.page_size = page_size; - mem->bitmap = bitmap; mem->pages = pages; mutex_init(&mem->lock); epc->windows[i] = mem; @@ -106,7 +102,7 @@ int pci_epc_multi_mem_init(struct pci_epc *epc, err_mem: for (; i >= 0; i--) { mem = epc->windows[i]; - kfree(mem->bitmap); + bitmap_free(mem->bitmap); kfree(mem); } kfree(epc->windows); @@ -145,7 +141,7 @@ void pci_epc_mem_exit(struct pci_epc *epc) for (i = 0; i < epc->num_windows; i++) { mem = epc->windows[i]; - kfree(mem->bitmap); + bitmap_free(mem->bitmap); kfree(mem); } kfree(epc->windows); -- 2.30.2