Re: [PATCH] arm/mach: Hold reference returned by of_find_xxx APIs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



* Russell King (Oracle) <linux@xxxxxxxxxxxxxxx> [220628 16:11]:
> On Tue, Jun 28, 2022 at 06:59:45AM +0300, Tony Lindgren wrote:
> > * Liang He <windhl@xxxxxxx> [220621 12:14]:
> > > diff --git a/arch/arm/mach-omap2/pmic-cpcap.c b/arch/arm/mach-omap2/pmic-cpcap.c
> > > index 668dc84fd31e..a7368d657aa8 100644
> > > --- a/arch/arm/mach-omap2/pmic-cpcap.c
> > > +++ b/arch/arm/mach-omap2/pmic-cpcap.c
> > > @@ -238,8 +238,11 @@ static struct omap_voltdm_pmic omap4_fan_iva = {
> > >  int __init omap4_cpcap_init(void)
> > >  {
> > >  	struct voltagedomain *voltdm;
> > > +	struct device_node *np;
> > >  
> > > -	if (!of_find_compatible_node(NULL, NULL, "motorola,cpcap"))
> > > +	np = of_find_compatible_node(NULL, NULL, "motorola,cpcap");
> > > +	of_node_put(np);
> > > +	if (!np)
> > >  		return -ENODEV;
> > 
> > Hmm so here you are checking for !np after of_node_put()?
> 
> This is permissible, because the value of the _pointer_ is being
> checked without dereferencing the pointer. So the fact that the
> node may have been freed is actually immaterial.

OK yeah. This is several lines of code to check if something exists.
Maybe we should just add bool of_compatible_node_exists() to simplify
cases like this that does not keep the kfef.

Regards,

Tony



[Index of Archives]     [Linux Arm (vger)]     [ARM Kernel]     [ARM MSM]     [Linux Tegra]     [Linux WPAN Networking]     [Linux Wireless Networking]     [Maemo Users]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite Trails]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux