mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Krzysztof Wilczyński" <kw@linux.com>
To: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
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
Subject: Re: [PATCH] PCI: endpoint: Use 'bitmap_zalloc()' when applicable
Date: Sat, 6 Nov 2021 23:01:27 +0100	[thread overview]
Message-ID: <YYb7NwlYcmsdw8AR@rocinante> (raw)
In-Reply-To: <01eba3c86137eb348f8cce69f500222bd7c72c57.1635058203.git.christophe.jaillet@wanadoo.fr>

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.

[...]
> @@ -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 <kw@linux.com>

	Krzysztof

  reply	other threads:[~2021-11-06 22:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-24  6:51 Christophe JAILLET
2021-11-06 22:01 ` Krzysztof Wilczyński [this message]
2021-11-07  6:52   ` Christophe JAILLET

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YYb7NwlYcmsdw8AR@rocinante \
    --to=kw@linux.com \
    --cc=bhelgaas@google.com \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=kishon@ti.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lorenzo.pieralisi@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®