[PATCH] sparc: pci: Fix memory leak in pci_bus_slot_names()

Salah Triki posted 1 patch 8 months, 1 week ago
arch/sparc/kernel/pci.c | 2 ++
1 file changed, 2 insertions(+)
[PATCH] sparc: pci: Fix memory leak in pci_bus_slot_names()
Posted by Salah Triki 8 months, 1 week ago
prop is a local pointer in pci_bus_slot_names(). It is initialized
by calling of_get_property() so the caller must free prop when done
using it.

Signed-off-by: Salah Triki <salah.triki@gmail.com>
---
 arch/sparc/kernel/pci.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/sparc/kernel/pci.c b/arch/sparc/kernel/pci.c
index ddac216a2aff..fa0da8f45723 100644
--- a/arch/sparc/kernel/pci.c
+++ b/arch/sparc/kernel/pci.c
@@ -971,6 +971,8 @@ static void pci_bus_slot_names(struct device_node *node, struct pci_bus *bus)
 		mask &= ~this_bit;
 		i++;
 	}
+
+	kfree(prop);
 }
 
 static int __init of_pci_slot_init(void)
-- 
2.43.0
Re: [PATCH] sparc: pci: Fix memory leak in pci_bus_slot_names()
Posted by Christophe JAILLET 8 months, 1 week ago
Le 07/04/2025 à 13:06, Salah Triki a écrit :
> prop is a local pointer in pci_bus_slot_names(). It is initialized
> by calling of_get_property() so the caller must free prop when done
> using it.

Hi,

can you elaborate why?

It does not look needed to me, and the places using of_get_property() 
that I've checked don't have such a kfree().

CJ

> 
> Signed-off-by: Salah Triki <salah.triki@gmail.com>
> ---
>   arch/sparc/kernel/pci.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/arch/sparc/kernel/pci.c b/arch/sparc/kernel/pci.c
> index ddac216a2aff..fa0da8f45723 100644
> --- a/arch/sparc/kernel/pci.c
> +++ b/arch/sparc/kernel/pci.c
> @@ -971,6 +971,8 @@ static void pci_bus_slot_names(struct device_node *node, struct pci_bus *bus)
>   		mask &= ~this_bit;
>   		i++;
>   	}
> +
> +	kfree(prop);
>   }
>   
>   static int __init of_pci_slot_init(void)

Re: [PATCH] sparc: pci: Fix memory leak in pci_bus_slot_names()
Posted by Salah Triki 8 months, 1 week ago
On Mon, Apr 07, 2025 at 09:49:08PM +0200, Christophe JAILLET wrote:
> Le 07/04/2025 à 13:06, Salah Triki a écrit :
> > prop is a local pointer in pci_bus_slot_names(). It is initialized
> > by calling of_get_property() so the caller must free prop when done
> > using it.
> 
> Hi,
> 
> can you elaborate why?
> 
> It does not look needed to me, and the places using of_get_property() that
> I've checked don't have such a kfree().
> 
> CJ

Hi, 

Sorry for disturbing, I was wrong about that.

ST
> 
> > 
> > Signed-off-by: Salah Triki <salah.triki@gmail.com>
> > ---
> >   arch/sparc/kernel/pci.c | 2 ++
> >   1 file changed, 2 insertions(+)
> > 
> > diff --git a/arch/sparc/kernel/pci.c b/arch/sparc/kernel/pci.c
> > index ddac216a2aff..fa0da8f45723 100644
> > --- a/arch/sparc/kernel/pci.c
> > +++ b/arch/sparc/kernel/pci.c
> > @@ -971,6 +971,8 @@ static void pci_bus_slot_names(struct device_node *node, struct pci_bus *bus)
> >   		mask &= ~this_bit;
> >   		i++;
> >   	}
> > +
> > +	kfree(prop);
> >   }
> >   static int __init of_pci_slot_init(void)
>