Re: [PATCH] spi: Fix reference count leak in slave_show()
From: Andy Shevchenko
Date: Wed Mar 19 2025 - 06:45:18 EST
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);
>
> put_device(child);
> return sysfs_emit(buf, "%s\n", NULL);
>
> No variable needed.
--
With Best Regards,
Andy Shevchenko