Re: [PATCH v3] gpiolib: fix memory leak in gpiochip_setup_dev()

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

 



On Thu, Nov 17, 2022 at 10:12:31PM +0800, Zeng Heng wrote:
> On 2022/11/17 18:49, Andy Shevchenko wrote:
> > On Thu, Nov 17, 2022 at 05:02:47PM +0800, Zeng Heng wrote:

...

> > > +	/*
> > > +	 * If gdev->dev.release has been registered by
> > > +	 * gpiochip_setup_dev(), print err msg and
> > > +	 * call put_device() to release all.
> > > +	 */
> > > +	if (gdev->dev.release)
> > > +		goto err_free_gdev;
> > (1)
> > 
> > >   err_remove_from_list:
> > >   	spin_lock_irqsave(&gpio_lock, flags);
> > >   	list_del(&gdev->list);
> > ...
> > 
> > > -	kfree(gdev);
> > > +	if (gdev->dev.release)
> > > +		put_device(&gdev->dev);
> > Why you can't do this above at (1)?
> > Is there any other hidden way to get here with release set?
> 
> As already mentioned in the mail, keep the error print info.

Can you refactor that to avoid double condition on the ->release() presence?

> > > +	else
> > > +		kfree(gdev);
> > >   	return ret;

-- 
With Best Regards,
Andy Shevchenko





[Index of Archives]     [Linux SPI]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux