From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 42F37C433F5 for ; Fri, 28 Jan 2022 13:04:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240739AbiA1NEU (ORCPT ); Fri, 28 Jan 2022 08:04:20 -0500 Received: from foss.arm.com ([217.140.110.172]:42862 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238248AbiA1NET (ORCPT ); Fri, 28 Jan 2022 08:04:19 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id DE9DA11D4; Fri, 28 Jan 2022 05:04:18 -0800 (PST) Received: from [10.57.68.47] (unknown [10.57.68.47]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7E4173F766; Fri, 28 Jan 2022 05:04:13 -0800 (PST) Message-ID: <29deffd6-aac4-f085-bcd5-f5a2d02784a8@arm.com> Date: Fri, 28 Jan 2022 13:04:07 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Thunderbird/91.5.1 Subject: Re: [RFC PATCH] component: Add common helpers for compare/release functions Content-Language: en-GB To: Yong Wu , dri-devel@lists.freedesktop.org Cc: David Airlie , Daniel Vetter , James Wang , Liviu Dudau , iommu@lists.linux-foundation.org, Matthias Brugger , Krzysztof Kozlowski , linux-kernel@vger.kernel.org, Joerg Roedel , Will Deacon , Arnd Bergmann , Laurent Pinchart , linux-mediatek@lists.infradead.org, Chun-Kuang Hu , linux-arm-kernel@lists.infradead.org, Stephen Boyd , AngeloGioacchino Del Regno , Hsin-Yi Wang , Tomasz Figa , srv_heupstream@mediatek.com, Rob Clark , Srinivas Kandagatla , Sebastian Reichel References: <20220128081101.27837-1-yong.wu@mediatek.com> From: Robin Murphy In-Reply-To: <20220128081101.27837-1-yong.wu@mediatek.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2022-01-28 08:11, Yong Wu wrote: [...] > diff --git a/include/linux/component.h b/include/linux/component.h > index 16de18f473d7..5a7468ea827c 100644 > --- a/include/linux/component.h > +++ b/include/linux/component.h > @@ -2,6 +2,8 @@ > #ifndef COMPONENT_H > #define COMPONENT_H > > +#include > +#include > #include > > > @@ -82,6 +84,22 @@ struct component_master_ops { > void (*unbind)(struct device *master); > }; > > +/* A set common helpers for compare/release functions */ > +static inline int compare_of(struct device *dev, void *data) > +{ > + return dev->of_node == data; > +} Note that this is effectively just device_match_of_node(), although I guess there is an argument that having a nice consistent set of component_match API helpers might be worth more than a tiny code saving by borrowing one from a different API. Either way, however, I don't think there's any good argument for instantiating separate copies of these functions in every driver that uses them. If they're used as callbacks then they can't actually be inlined anyway, so they may as well be exported from component.c as normal so that the code really is shared (plus then there's nice symmetry with the aforementioned device_match API helpers too). Thanks, Robin. > +static inline void release_of(struct device *dev, void *data) > +{ > + of_node_put(data); > +} > + > +static inline int compare_dev(struct device *dev, void *data) > +{ > + return dev == data; > +} > + > void component_master_del(struct device *, > const struct component_master_ops *); > > diff --git a/sound/soc/codecs/wcd938x.c b/sound/soc/codecs/wcd938x.c > index eff200a07d9f..992132cbfb9f 100644 > --- a/sound/soc/codecs/wcd938x.c > +++ b/sound/soc/codecs/wcd938x.c > @@ -4417,16 +4417,6 @@ static const struct component_master_ops wcd938x_comp_ops = { > .unbind = wcd938x_unbind, > }; > > -static int wcd938x_compare_of(struct device *dev, void *data) > -{ > - return dev->of_node == data; > -} > - > -static void wcd938x_release_of(struct device *dev, void *data) > -{ > - of_node_put(data); > -} > - > static int wcd938x_add_slave_components(struct wcd938x_priv *wcd938x, > struct device *dev, > struct component_match **matchptr) > @@ -4442,8 +4432,7 @@ static int wcd938x_add_slave_components(struct wcd938x_priv *wcd938x, > } > > of_node_get(wcd938x->rxnode); > - component_match_add_release(dev, matchptr, wcd938x_release_of, > - wcd938x_compare_of, wcd938x->rxnode); > + component_match_add_release(dev, matchptr, release_of, compare_of, wcd938x->rxnode); > > wcd938x->txnode = of_parse_phandle(np, "qcom,tx-device", 0); > if (!wcd938x->txnode) { > @@ -4451,8 +4440,7 @@ static int wcd938x_add_slave_components(struct wcd938x_priv *wcd938x, > return -ENODEV; > } > of_node_get(wcd938x->txnode); > - component_match_add_release(dev, matchptr, wcd938x_release_of, > - wcd938x_compare_of, wcd938x->txnode); > + component_match_add_release(dev, matchptr, release_of, compare_of, wcd938x->txnode); > return 0; > } >