linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] powerpc/xive: Fix some incorrect memory allocation
@ 2022-06-25  9:49 Christophe JAILLET
  2022-06-25 11:29 ` Cédric Le Goater
  0 siblings, 1 reply; 2+ messages in thread
From: Christophe JAILLET @ 2022-06-25  9:49 UTC (permalink / raw)
  To: Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Cédric Le Goater
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET, linuxppc-dev

'xibm->count' really looks like a number of bits (see how it is used in
__xive_irq_bitmap_alloc()), so use the bitmap API to allocate and free this
bitmap.

This improves semantic and potentially avoids some over memory allocation.

Fixes: eac1e731b59e ("powerpc/xive: guest exploitation of the XIVE interrupt controller")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
I don't cross compile, so this patch is NOT compile-tested.
---
 arch/powerpc/sysdev/xive/spapr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/sysdev/xive/spapr.c b/arch/powerpc/sysdev/xive/spapr.c
index 7d5128676e83..fdbebb14b7de 100644
--- a/arch/powerpc/sysdev/xive/spapr.c
+++ b/arch/powerpc/sysdev/xive/spapr.c
@@ -57,7 +57,7 @@ static int __init xive_irq_bitmap_add(int base, int count)
 	spin_lock_init(&xibm->lock);
 	xibm->base = base;
 	xibm->count = count;
-	xibm->bitmap = kzalloc(xibm->count, GFP_KERNEL);
+	xibm->bitmap = bitmap_zalloc(xibm->count, GFP_KERNEL);
 	if (!xibm->bitmap) {
 		kfree(xibm);
 		return -ENOMEM;
@@ -75,7 +75,7 @@ static void xive_irq_bitmap_remove_all(void)
 
 	list_for_each_entry_safe(xibm, tmp, &xive_irq_bitmaps, list) {
 		list_del(&xibm->list);
-		kfree(xibm->bitmap);
+		bitmap_free(xibm->bitmap);
 		kfree(xibm);
 	}
 }
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] powerpc/xive: Fix some incorrect memory allocation
  2022-06-25  9:49 [PATCH] powerpc/xive: Fix some incorrect memory allocation Christophe JAILLET
@ 2022-06-25 11:29 ` Cédric Le Goater
  0 siblings, 0 replies; 2+ messages in thread
From: Cédric Le Goater @ 2022-06-25 11:29 UTC (permalink / raw)
  To: Christophe JAILLET, Michael Ellerman, Benjamin Herrenschmidt,
	Paul Mackerras
  Cc: linux-kernel, kernel-janitors, linuxppc-dev

Hello Christophe,

On 6/25/22 11:49, Christophe JAILLET wrote:
> 'xibm->count' really looks like a number of bits (see how it is used in
> __xive_irq_bitmap_alloc()), so use the bitmap API to allocate and free this
> bitmap.
> 
> This improves semantic and potentially avoids some over memory allocation.

This is correct and
  
> Fixes: eac1e731b59e ("powerpc/xive: guest exploitation of the XIVE interrupt controller")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> I don't cross compile, so this patch is NOT compile-tested.


Nathan provided a fix for it already :

  http://patchwork.ozlabs.org/project/linuxppc-dev/patch/20220623182509.3985625-1-nathanl@linux.ibm.com/

Thanks,

C.

> ---
>   arch/powerpc/sysdev/xive/spapr.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/powerpc/sysdev/xive/spapr.c b/arch/powerpc/sysdev/xive/spapr.c
> index 7d5128676e83..fdbebb14b7de 100644
> --- a/arch/powerpc/sysdev/xive/spapr.c
> +++ b/arch/powerpc/sysdev/xive/spapr.c
> @@ -57,7 +57,7 @@ static int __init xive_irq_bitmap_add(int base, int count)
>   	spin_lock_init(&xibm->lock);
>   	xibm->base = base;
>   	xibm->count = count;
> -	xibm->bitmap = kzalloc(xibm->count, GFP_KERNEL);
> +	xibm->bitmap = bitmap_zalloc(xibm->count, GFP_KERNEL);
>   	if (!xibm->bitmap) {
>   		kfree(xibm);
>   		return -ENOMEM;
> @@ -75,7 +75,7 @@ static void xive_irq_bitmap_remove_all(void)
>   
>   	list_for_each_entry_safe(xibm, tmp, &xive_irq_bitmaps, list) {
>   		list_del(&xibm->list);
> -		kfree(xibm->bitmap);
> +		bitmap_free(xibm->bitmap);
>   		kfree(xibm);
>   	}
>   }


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-06-25 11:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-25  9:49 [PATCH] powerpc/xive: Fix some incorrect memory allocation Christophe JAILLET
2022-06-25 11:29 ` Cédric Le Goater

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).