[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Z9qgWqjVRgthJ8qX@smile.fi.intel.com>
Date: Wed, 19 Mar 2025 12:45:46 +0200
From: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
To: Miaoqian Lin <linmq006@...il.com>
Cc: Mark Brown <broonie@...nel.org>,
Geert Uytterhoeven <geert+renesas@...der.be>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
"Rafael J. Wysocki" <rafael.j.wysocki@...el.com>,
linux-spi@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] spi: Fix reference count leak in slave_show()
On Wed, Mar 19, 2025 at 12:45:03PM +0200, Andy Shevchenko wrote:
> On Wed, Mar 19, 2025 at 12:44:33PM +0200, Andy Shevchenko wrote:
> > On Wed, Mar 19, 2025 at 11:23:04AM +0800, Miaoqian Lin wrote:
...
> > > struct device *child;
> > > + int ret;
> > >
> > > child = device_find_any_child(&ctlr->dev);
> > > - return sysfs_emit(buf, "%s\n", child ? to_spi_device(child)->modalias : NULL);
> > > + ret = sysfs_emit(buf, "%s\n", child ? to_spi_device(child)->modalias : NULL);
> > > + put_device(child);
> > > +
> > > + return ret;
> >
> > Can be written better in case of NULL:
> >
> > child = device_find_any_child(&ctlr->dev);
> > if (child)
> > return sysfs_emit(buf, "%s\n", child ? to_spi_device(child)->modalias);
>
> Of course this has to be
>
> return sysfs_emit(buf, "%s\n", to_spi_device(child)->modalias);
And I mixed the conditional, but I hope you got the idea...
> >
> > put_device(child);
> > return sysfs_emit(buf, "%s\n", NULL);
> >
> > No variable needed.
--
With Best Regards,
Andy Shevchenko
Powered by blists - more mailing lists