[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Z9qgENjcGFF-rDJe@smile.fi.intel.com>
Date: Wed, 19 Mar 2025 12:44:32 +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 11:23:04AM +0800, Miaoqian Lin wrote:
> Fix a reference count leak in slave_show() by properly putting the device
> reference obtained from device_find_any_child().
...
> 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);
put_device(child);
return sysfs_emit(buf, "%s\n", NULL);
No variable needed.
--
With Best Regards,
Andy Shevchenko
Powered by blists - more mailing lists