Re: [PATCH v2 01/14] device property: Add cleanup.h based fwnode_handle_put() scope based cleanup.

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

 



Hi Jonathan,

On Mon, Feb 12, 2024 at 11:42:06AM +0000, Jonathan Cameron wrote:
> On Mon, 12 Feb 2024 08:49:23 +0000
> Sakari Ailus <sakari.ailus@xxxxxxxxxxxxxxx> wrote:
> 
> > Hi Jonathan,
> > 
> > On Sun, Feb 11, 2024 at 07:25:27PM +0000, Jonathan Cameron wrote:
> > > From: Jonathan Cameron <Jonathan.Cameron@xxxxxxxxxx>
> > > 
> > > Useful where the fwnode_handle was obtained from a call such as
> > > fwnode_find_reference() as it will safely do nothing if IS_ERR() is true
> > > and will automatically release the reference on the variable leaving
> > > scope.
> > > 
> > > Reviewed-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
> > > Signed-off-by: Jonathan Cameron <Jonathan.Cameron@xxxxxxxxxx>
> > > ---
> > >  include/linux/property.h | 3 +++
> > >  1 file changed, 3 insertions(+)
> > > 
> > > diff --git a/include/linux/property.h b/include/linux/property.h
> > > index e6516d0b7d52..bcda028f1a33 100644
> > > --- a/include/linux/property.h
> > > +++ b/include/linux/property.h
> > > @@ -12,6 +12,7 @@
> > >  
> > >  #include <linux/args.h>
> > >  #include <linux/bits.h>
> > > +#include <linux/cleanup.h>
> > >  #include <linux/fwnode.h>
> > >  #include <linux/stddef.h>
> > >  #include <linux/types.h>
> > > @@ -188,6 +189,8 @@ struct fwnode_handle *device_get_named_child_node(const struct device *dev,
> > >  
> > >  struct fwnode_handle *fwnode_handle_get(struct fwnode_handle *fwnode);
> > >  void fwnode_handle_put(struct fwnode_handle *fwnode);
> > > +DEFINE_FREE(fwnode_handle, struct fwnode_handle *,
> > > +	    if (!IS_ERR_OR_NULL(_T)) fwnode_handle_put(_T))  
> > 
> > fwnode_handle_put() can be safely called on NULL or error pointer fwnode so
> > you can remove the check.
> 
> Was discussed in the RFC thread (where i didn't have this protection)
> 
> https://lore.kernel.org/linux-iio/20240108125117.000010fb@xxxxxxxxxx/
> includes a reference to Linus Torvald's view on this.
> 
> All comes down to compiler visibility and optimization opportunities, which are improved
> if the check is in the macro definition.

Hmm. In that case I'd rather make fwnode_handle_put() and similar trivial
functions macros.

There's no need to add cruft here and about a 100-fold number of callers
will get the same benefit.

-- 
Sakari Ailus




[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux