Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp5245278pxb; Sun, 7 Nov 2021 08:10:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJwaW9tQxmpMFGsCtk0lKioBfCFNw1HQuPfKA8Q2OJJlJ7d/t6EyhLMaQGuuLRLTu2oeZ4Ja X-Received: by 2002:a05:6638:224d:: with SMTP id m13mr15259730jas.86.1636301442371; Sun, 07 Nov 2021 08:10:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636301442; cv=none; d=google.com; s=arc-20160816; b=ZhW5lXarP6ie+b566n3c3U1f2Sa+N3Zbn2LBOtsvf6Xh7AYRdLImyD3MuZXApi3e0T sVJcs6Bg+xDC4/pj/yWU2ssAomgu8oNnRJbAQ5uVpEehNTsIni8hUJIA5/e+1vVrPbvT v6Lkq37BTzYCNiXVWXRPjtsQ/Z14JScvvuLzL1LOEHPHPdwz1BHQQnzY300SwSh7XeSG eLmdqM2gHiU5xhmdDMe5nPpuQ30/DegNg2SC8DurHX1qpcFUTmWeftWJ+kaxOguCa0Yy eHUOWQsS8cj9qPtVCaYwMRBL9TBW3uOYRHIeXXVcjeezya+U3mAPdZ20vpNb9FwVzc7E q83g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=t5ZfONxbBrXdVuu0sJMzUUeO9fZLpPvWg6SZTDlSM6I=; b=bDry7BHiDzY+zyuAxbMvO1vnT2oLETTJ3d0+QA2IXhWHZScIT6CGaPK8LszgpoxXUX iiwciT5z5nEc6IvFZCvcLHlqUtMHNgIvNd1nlXxwsX5zJlsmJP2nsVcMqNmMjoEvmupa WhDyoznHBkSOnCGJWqjQGRu6N2oy5HuFuPcRuHB7FWV7DiP0SqLqnkl003ZptszUvX7g Y/YE+qojeiMXzD6Z1xkD6H0WpipgT1R8iX/QLC4C4GvXTasoy0hu+TGUI9syFRBgOzfX eXs4sVAGvcziLoxTxep1QtN/cX5q6m6NMxQnrTsNLtt2S+coA3IwuZolw5BxSCHzROPg r70w== 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 p6si22927240jag.18.2021.11.07.08.10.29; Sun, 07 Nov 2021 08:10:42 -0800 (PST) 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 S234824AbhKGGza (ORCPT + 99 others); Sun, 7 Nov 2021 01:55:30 -0500 Received: from smtp09.smtpout.orange.fr ([80.12.242.131]:64024 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229878AbhKGGz3 (ORCPT ); Sun, 7 Nov 2021 01:55:29 -0500 Received: from [192.168.1.18] ([86.243.171.122]) by smtp.orange.fr with ESMTPA id jc2mmiWjzUujjjc2nmXikG; Sun, 07 Nov 2021 07:52:46 +0100 X-ME-Helo: [192.168.1.18] X-ME-Auth: YWZlNiIxYWMyZDliZWIzOTcwYTEyYzlhMmU3ZiQ1M2U2MzfzZDfyZTMxZTBkMTYyNDBjNDJlZmQ3ZQ== X-ME-Date: Sun, 07 Nov 2021 07:52:46 +0100 X-ME-IP: 86.243.171.122 Subject: Re: [PATCH] PCI: endpoint: Use 'bitmap_zalloc()' when applicable To: =?UTF-8?Q?Krzysztof_Wilczy=c5=84ski?= Cc: kishon@ti.com, lorenzo.pieralisi@arm.com, bhelgaas@google.com, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org References: <01eba3c86137eb348f8cce69f500222bd7c72c57.1635058203.git.christophe.jaillet@wanadoo.fr> From: Christophe JAILLET Message-ID: <8123c76f-3887-09ad-17ec-a160f63b9f86@wanadoo.fr> Date: Sun, 7 Nov 2021 07:52:44 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Le 06/11/2021 à 23:01, Krzysztof Wilczyński a écrit : > Hi Christophe, > >> '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. > > Thank you! > >> Finally, while at it, axe the useless 'bitmap' variable and use >> 'mem->bitmap' directly. > > Personally, I would keep the bitmap variable - this might be what Bjorn > would also prefer, as I believe he prefers not to store what is a "failed" > state of sorts in a target variable directly, if memory serves me right. Hi, mostly a mater of taste. On another similar patch I got the answer in [1] :). 'mem' is kzalloc'ed, so in case of failure, here we are just replacing NULL by NULL. Let me know the preferred style here and if I should send a V2. CJ [1]; https://lore.kernel.org/kernel-janitors/20211028164437.GA4045120@p14s/ > > [...] >> @@ -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); > > Thank you! > > Reviewed-by: Krzysztof Wilczyński > > Krzysztof >