Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp2726688pxb; Mon, 31 Jan 2022 03:02:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJyxRDsAH8iHMUSVSxY59Kh8pGOrj9EznIWy2KlFvkPImY0KiEFlvDr64DP/nbnskfuRCPB6 X-Received: by 2002:a17:907:2d8d:: with SMTP id gt13mr17108505ejc.583.1643626925269; Mon, 31 Jan 2022 03:02:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643626925; cv=none; d=google.com; s=arc-20160816; b=eRoO5FMn5cXMAEqW4bCpICDWvTCZsgzn1EMuNfpKrKNvuFw4/9iq3LQozhCizv+ooF RIxYVaMvRRKZ3w3ou982lFoWWxin9N5z0kARCP4/krrShxiSX5OU2REDf+bBy/O+/Lty I6e24MyMRddlHYla+ySytqkykQn4bi4oMiNDG0ZBsP+uayRnaJVlJoqTGmyqUF3tT8tk Z2sh5QmQLoZuvrH8oEJe5V/iKp889tRbZA4td0ukH+URAVnsCfyKgtK8sx4szgnyKDjr EYsCOzQ9s8Ba47vPhwMpyVphkaetCzYrhg8GANcZv+1FDUqEG2n61J8pblr2KMRq35gz 5F+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=Q5yXJKTEnzZkwElLBNHobqeEwIUMLTzcyEfD2p+18LA=; b=qV9omu/Uu6+oUwXLyGqXF2lu5KNsLWi889bEpkJzsO2eEXgQtvppG07RwONvpVlY/J a5C8y9Sx/Za361SY9LKDs5/znM8QkwGmU4L2RMWu0oB1elPNGDtb2/35d8IKRs/XOuSS cLyLgfTUSdF9ouWyPwCWxRy6PYPa61BvA3+vh878lTLon8UXo52E8FTpWDUxWRYxsum6 mFuzoA4SLk5Mxuz6N1+4AXfY6P33ONrlzmoEWLJ8pMg+nEEBniFJ7LM5EVYluut4EohY l0Qfa8sagTuV+GYG7KsqqpzsBisg/0ZNh0ev3nf/K8bWfgKAcOu5fUw1C5BT5ZprJUgH dPdQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v1si7989556ejd.983.2022.01.31.03.01.37; Mon, 31 Jan 2022 03:02:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240594AbiA1NEU (ORCPT + 99 others); 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; > } >