Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp3608046rwb; Mon, 16 Jan 2023 10:11:50 -0800 (PST) X-Google-Smtp-Source: AMrXdXvErzYFVbkEslJ6gyuPE3UJCovWatBuAWHfGHupr9e44lOr6zKBIGlfIQ+Va2zi+RCMqjbl X-Received: by 2002:a17:902:c948:b0:194:6414:12e1 with SMTP id i8-20020a170902c94800b00194641412e1mr875419pla.25.1673892710455; Mon, 16 Jan 2023 10:11:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673892710; cv=none; d=google.com; s=arc-20160816; b=BP3d6DH+67q+UGTZuzS3aMx47vU2PYr0vSnJ8qx37ccZWvyHBC5wnX9yd8O2RvcbCD EZ2IrAcVMPerbhwq6TmomfvY3QSO+eYD0mNIFNmFW4nIUb7pbgB1leWKl9f37aWr34ss sqPLSHxsD4sKdNkpx1kHhaXo9EcMXeFsvVxi2uo542dglwp29e0gyxr5RMbCTgTddUE7 p4ionXbX62GnFH2YLnlU2CPoOkGxk5zN3mXc5ARAmYD2Fz4BFAJ8cOSZsemNhSsRtnWk GVTq1FCyJ0KkE69vuOSOQUCQYdPKGy14Q1+YXJegk2M+YqDTTKJ3BdNg/glsfIaY9OIo WQKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=t7F9JKouL1KurTO0QVKHN8g/5zAESWUg12UOdA+LKsI=; b=OVg8vdi3xVOxzzwNqdXk0OE7U8W5/LoRABQ2gBmjbRM9HVdxvtRn9HS6D1R8ENx0zd aKDnFbnw5nv2zRqYbWW5ASqnKwgZVL59i0lOgHVE7+B4sFxdsM3SC/gMmi9nUUvwLD9a yxZYA2M6/mlTfsE3MH8zISCcSrjAKxgcWPcyqJeO35ZIlV8/4hHr1LjZHPAaOZRD7+FS U7KNq4R3ngbsoQbV+UNlJWCkZ6nVoantVCC1fyaR13xJUc20vqgvaiBOZgougati86JF WJmbx7o1RuLYFYgTGEqLi8Rl+MiWwJo5G7LNvlWZcSmukWkbMMWmbKXEQ4cXQH4kM7dx PRSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@semihalf.com header.s=google header.b=E3DYP0ep; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=semihalf.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bd9-20020a170902830900b00192a3e13b52si28720063plb.140.2023.01.16.10.11.44; Mon, 16 Jan 2023 10:11:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@semihalf.com header.s=google header.b=E3DYP0ep; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=semihalf.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234394AbjAPRxk (ORCPT + 52 others); Mon, 16 Jan 2023 12:53:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235026AbjAPRwn (ORCPT ); Mon, 16 Jan 2023 12:52:43 -0500 Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [IPv6:2a00:1450:4864:20::22b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC7C43B658 for ; Mon, 16 Jan 2023 09:35:05 -0800 (PST) Received: by mail-lj1-x22b.google.com with SMTP id s25so30712219lji.2 for ; Mon, 16 Jan 2023 09:35:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=t7F9JKouL1KurTO0QVKHN8g/5zAESWUg12UOdA+LKsI=; b=E3DYP0epTmdQaBr8PG3Lc8mLskVrmA2L1g1uosAju1bFb9Zd1/cbdiapQ5fFkaSZWK o6rwyTvWmoqnqO3GQ/PewcCOeU0+EVt2OCdA60ZsN2J+CeH1ab2BXc3aMXbO3uUsfHzx qv2fyovh8SRghPRZL80Urm0MOg9l7NaqDEA9Wj0/szZhsXkat75oRTQwgH4S2taaVfvI ye2rM+2rYjemoac3jVmVgsJM7q93qCrMpk1DijXEctb18ivK5LdNH+j1ll+sZnNopfVw p5jf7bQUsXQ7jDJbMKnRbGzaygpSujEZUXF/8g/SGPq88bZcs42LLCGQMTgOI04QcHju UK2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=t7F9JKouL1KurTO0QVKHN8g/5zAESWUg12UOdA+LKsI=; b=V3cLLIj0tmvLyjpY6efFbipplufw+Tc1QYO+lzljmb0cIkO5Rxk5MwDoON/mRbg0LT +wIHziQN41fkKeNvQ71sdYOET4B09Wb8cIllvGECGa4JN52jK6EuZLYxlKEH+H93ZO/o JNdYcvONo7ON/iVdYGuTezeuE0T2OtQjUM2MIzkmV5TbThEFAxe8fv7wnv4bojmkEFBU +acXUAa0I6+yGXwD8861LCqLtHQuqfFb87XApm8Ot1Kkl6tuDxSPDLh34WIr1fwKLziH VzTlDKBQ8mq3MPmUly6qMDhu4HX+bMdqRIpiV4QaRhcwVp/4iBg9j14G+kePDjNUebZ2 VDug== X-Gm-Message-State: AFqh2krBEohxuWAo4f3SrJN1r44W0LZhx2fdKKQ92Pf9gw5gpilbyLmj Xrobs5r1/B+RbN3IWZNq/ARDRaPILz20cXEn X-Received: by 2002:a2e:90c7:0:b0:28b:77ce:f88b with SMTP id o7-20020a2e90c7000000b0028b77cef88bmr180131ljg.8.1673890504000; Mon, 16 Jan 2023 09:35:04 -0800 (PST) Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id k20-20020a2e8894000000b0028b7f51414fsm707333lji.80.2023.01.16.09.35.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Jan 2023 09:35:03 -0800 (PST) From: Marcin Wojtas To: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, netdev@vger.kernel.org Cc: rafael@kernel.org, andriy.shevchenko@linux.intel.com, sean.wang@mediatek.com, Landen.Chao@mediatek.com, linus.walleij@linaro.org, andrew@lunn.ch, vivien.didelot@gmail.com, f.fainelli@gmail.com, olteanv@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux@armlinux.org.uk, hkallweit1@gmail.com, mw@semihalf.com, jaz@semihalf.com, tn@semihalf.com, Samer.El-Haj-Mahmoud@arm.com Subject: [net-next: PATCH v4 5/8] device property: introduce fwnode_find_parent_dev_match Date: Mon, 16 Jan 2023 18:34:17 +0100 Message-Id: <20230116173420.1278704-6-mw@semihalf.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20230116173420.1278704-1-mw@semihalf.com> References: <20230116173420.1278704-1-mw@semihalf.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a new generic routine fwnode_find_parent_dev_match that can be used e.g. as a callback for class_find_device(). It searches for the struct device corresponding to a struct fwnode_handle by iterating over device and its parents. Signed-off-by: Marcin Wojtas --- include/linux/property.h | 1 + drivers/base/property.c | 23 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/linux/property.h b/include/linux/property.h index 37179e3abad5..4ae20d7c5103 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -109,6 +109,7 @@ struct device *fwnode_get_next_parent_dev(struct fwnode_handle *fwnode); unsigned int fwnode_count_parents(const struct fwnode_handle *fwn); struct fwnode_handle *fwnode_get_nth_parent(struct fwnode_handle *fwn, unsigned int depth); +int fwnode_find_parent_dev_match(struct device *dev, const void *data); bool fwnode_is_ancestor_of(struct fwnode_handle *ancestor, struct fwnode_handle *child); struct fwnode_handle *fwnode_get_next_child_node( const struct fwnode_handle *fwnode, struct fwnode_handle *child); diff --git a/drivers/base/property.c b/drivers/base/property.c index bbb3e499ff4a..84849d4934cc 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -693,6 +693,29 @@ struct fwnode_handle *fwnode_get_nth_parent(struct fwnode_handle *fwnode, } EXPORT_SYMBOL_GPL(fwnode_get_nth_parent); +/** + * fwnode_find_parent_dev_match - look for a device matching the struct fwnode_handle + * @dev: the struct device to initiate the search + * @data: pointer passed for comparison + * + * Looks up the device structure corresponding with the fwnode by iterating + * over @dev and its parents. + * The routine can be used e.g. as a callback for class_find_device(). + * + * Returns: %1 - match is found + * %0 - match not found + */ +int fwnode_find_parent_dev_match(struct device *dev, const void *data) +{ + for (; dev; dev = dev->parent) { + if (device_match_fwnode(dev, data)) + return 1; + } + + return 0; +} +EXPORT_SYMBOL_GPL(fwnode_find_parent_dev_match); + /** * fwnode_is_ancestor_of - Test if @ancestor is ancestor of @child * @ancestor: Firmware which is tested for being an ancestor -- 2.29.0