* [PATCH] dma-mapping: Use 'bitmap_zalloc()' when applicable
@ 2021-10-24 17:40 Christophe JAILLET
2021-10-24 17:54 ` Joe Perches
2021-10-27 6:20 ` Christoph Hellwig
0 siblings, 2 replies; 4+ messages in thread
From: Christophe JAILLET @ 2021-10-24 17:40 UTC (permalink / raw)
To: hch, m.szyprowski, robin.murphy
Cc: iommu, linux-kernel, kernel-janitors, Christophe JAILLET
'dma_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.
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
kernel/dma/coherent.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/kernel/dma/coherent.c b/kernel/dma/coherent.c
index 25fc85a7aebe..375fb3c9538d 100644
--- a/kernel/dma/coherent.c
+++ b/kernel/dma/coherent.c
@@ -40,7 +40,6 @@ static struct dma_coherent_mem *dma_init_coherent_memory(phys_addr_t phys_addr,
{
struct dma_coherent_mem *dma_mem;
int pages = size >> PAGE_SHIFT;
- int bitmap_size = BITS_TO_LONGS(pages) * sizeof(long);
void *mem_base;
if (!size)
@@ -53,7 +52,7 @@ static struct dma_coherent_mem *dma_init_coherent_memory(phys_addr_t phys_addr,
dma_mem = kzalloc(sizeof(struct dma_coherent_mem), GFP_KERNEL);
if (!dma_mem)
goto out_unmap_membase;
- dma_mem->bitmap = kzalloc(bitmap_size, GFP_KERNEL);
+ dma_mem->bitmap = bitmap_zalloc(pages, GFP_KERNEL);
if (!dma_mem->bitmap)
goto out_free_dma_mem;
@@ -81,7 +80,7 @@ static void dma_release_coherent_memory(struct dma_coherent_mem *mem)
return;
memunmap(mem->virt_base);
- kfree(mem->bitmap);
+ bitmap_free(mem->bitmap);
kfree(mem);
}
--
2.30.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] dma-mapping: Use 'bitmap_zalloc()' when applicable
2021-10-24 17:40 [PATCH] dma-mapping: Use 'bitmap_zalloc()' when applicable Christophe JAILLET
@ 2021-10-24 17:54 ` Joe Perches
2021-10-24 18:18 ` Christophe JAILLET
2021-10-27 6:20 ` Christoph Hellwig
1 sibling, 1 reply; 4+ messages in thread
From: Joe Perches @ 2021-10-24 17:54 UTC (permalink / raw)
To: Christophe JAILLET, hch, m.szyprowski, robin.murphy
Cc: iommu, linux-kernel, kernel-janitors
On Sun, 2021-10-24 at 19:40 +0200, Christophe JAILLET wrote:
> 'dma_mem->bitmap' is a bitmap. So use 'bitmap_zalloc()' to simplify code,
> improve the semantic and avoid some open-coded arithmetic in allocator
> arguments.
There is a cocci script for some of these.
https://lore.kernel.org/all/08b89608cfb1280624d1a89ead6547069f9a4c31.camel@perches.com/
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] dma-mapping: Use 'bitmap_zalloc()' when applicable
2021-10-24 17:54 ` Joe Perches
@ 2021-10-24 18:18 ` Christophe JAILLET
0 siblings, 0 replies; 4+ messages in thread
From: Christophe JAILLET @ 2021-10-24 18:18 UTC (permalink / raw)
To: Joe Perches, hch, m.szyprowski, robin.murphy
Cc: iommu, linux-kernel, kernel-janitors
Le 24/10/2021 à 19:54, Joe Perches a écrit :
> On Sun, 2021-10-24 at 19:40 +0200, Christophe JAILLET wrote:
>> 'dma_mem->bitmap' is a bitmap. So use 'bitmap_zalloc()' to simplify code,
>> improve the semantic and avoid some open-coded arithmetic in allocator
>> arguments.
>
> There is a cocci script for some of these.
>
> https://lore.kernel.org/all/08b89608cfb1280624d1a89ead6547069f9a4c31.camel@perches.com/
>
Hi Joe,
yes I know.
As it is public, I guess that new comers may have seen it and want to
propose patches based on your cocci script.
So, for now, I'm more focused on things that are not spotted by your
script. I look for places where the size computation is not done within
the kmalloc() or eq. function.
CJ
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] dma-mapping: Use 'bitmap_zalloc()' when applicable
2021-10-24 17:40 [PATCH] dma-mapping: Use 'bitmap_zalloc()' when applicable Christophe JAILLET
2021-10-24 17:54 ` Joe Perches
@ 2021-10-27 6:20 ` Christoph Hellwig
1 sibling, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2021-10-27 6:20 UTC (permalink / raw)
To: Christophe JAILLET
Cc: hch, m.szyprowski, robin.murphy, iommu, linux-kernel, kernel-janitors
Thanks, applied.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-10-27 6:20 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-24 17:40 [PATCH] dma-mapping: Use 'bitmap_zalloc()' when applicable Christophe JAILLET
2021-10-24 17:54 ` Joe Perches
2021-10-24 18:18 ` Christophe JAILLET
2021-10-27 6:20 ` Christoph Hellwig
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).