From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 834C33984A; Mon, 12 Feb 2024 11:42:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.176.79.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707738133; cv=none; b=ucuRMRaYfU4y6lj07kdL0LduLdGVcSrouJYGPIKXBnvrZnArtoIpxPN4sa5Ku9sZ4qHhAiLddMh83twrenFdY5fmJ1R8Rf2mA2lAPTp9J2KyRM+b8EL0VUzmlPMzApaV3v00L3pKj9E6hSVm/SImo3VKuOS++o443C4EAnSBWFo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707738133; c=relaxed/simple; bh=px08+1SkCrrmTZqG/uxsxxzAgxGCz+kRRq4ti0TxZsQ=; h=Date:From:To:CC:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nqQbdWua3gAR5k0HvCsuftwlk0Jrqlp39Z7SQEOdY48IodZHTf77uhuf0KtIb0zLY/TU5HoLYSTk+igQBruOtzQm+GMe9V17P/7A36ZxjgsfgxHI8+JpUkbhvgfzR2y+TGSgwmMRDBYDfiHCH4zBRKYSFmAliVcTIVFf7RJzgzU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=Huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=185.176.79.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=Huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.18.186.231]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4TYMsL3lBgz6J9fy; Mon, 12 Feb 2024 19:38:14 +0800 (CST) Received: from lhrpeml500005.china.huawei.com (unknown [7.191.163.240]) by mail.maildlp.com (Postfix) with ESMTPS id 3AD6E140136; Mon, 12 Feb 2024 19:42:08 +0800 (CST) Received: from localhost (10.202.227.76) by lhrpeml500005.china.huawei.com (7.191.163.240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Mon, 12 Feb 2024 11:42:07 +0000 Date: Mon, 12 Feb 2024 11:42:06 +0000 From: Jonathan Cameron To: Sakari Ailus CC: Jonathan Cameron , , "Rafael J . Wysocki" , Len Brown , , Andy Shevchenko , Greg Kroah-Hartman , Daniel Scally , "Heikki Krogerus" , Julia Lawall , Nuno =?ISO-8859-1?Q?S=E1?= , Cosmin Tanislav , Mihail Chindris , Rasmus Villemoes , Tomislav Denis , Marek Vasut , Olivier Moysan , Fabrice Gasnier , Lad Prabhakar , Dmitry Baryshkov , Marijn Suijten , Marius Cristea , Ibrahim Tilki , Peter Zijlstra Subject: Re: [PATCH v2 01/14] device property: Add cleanup.h based fwnode_handle_put() scope based cleanup. Message-ID: <20240212114206.00005b9f@Huawei.com> In-Reply-To: References: <20240211192540.340682-1-jic23@kernel.org> <20240211192540.340682-2-jic23@kernel.org> Organization: Huawei Technologies Research and Development (UK) Ltd. X-Mailer: Claws Mail 4.1.0 (GTK 3.24.33; x86_64-w64-mingw32) Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-ClientProxiedBy: lhrpeml100003.china.huawei.com (7.191.160.210) To lhrpeml500005.china.huawei.com (7.191.163.240) On Mon, 12 Feb 2024 08:49:23 +0000 Sakari Ailus wrote: > Hi Jonathan, > > On Sun, Feb 11, 2024 at 07:25:27PM +0000, Jonathan Cameron wrote: > > From: Jonathan Cameron > > > > 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 > > Signed-off-by: Jonathan Cameron > > --- > > 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 > > #include > > +#include > > #include > > #include > > #include > > @@ -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@Huawei.com/ 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. Jonathan > > > > > int fwnode_irq_get(const struct fwnode_handle *fwnode, unsigned int index); > > int fwnode_irq_get_byname(const struct fwnode_handle *fwnode, const char *name); >