From patchwork Mon Jun 3 15:49:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 165659 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp4648076ili; Mon, 3 Jun 2019 08:55:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqye8YGpM7SNmZBSdqT/G50UojEOkD4hAclDD95A98Z5e+YbsHizr+29aNfW69NRTMuqAI8P X-Received: by 2002:a17:90a:9291:: with SMTP id n17mr30440419pjo.66.1559577308872; Mon, 03 Jun 2019 08:55:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559577308; cv=none; d=google.com; s=arc-20160816; b=y5SkQfbCJbxka8P+TV7MyYZtKCZH/ZeZsFjCdb3rwCwyjQb4VykcpOfJr3fV6M8qr7 Jm3wPgh9hg0HOCa7jRBt6H1bYPDc6l1PBhQ/MDpr27H+vATqXW4UGpmMiX89wxull777 atg79VuHFdWcUpP915Vgtm2MYObrV9f1J0+qJ9VqaPv4IoCK6wHiZ09SFx2q8R52kD11 ByeUcofBk87y9Mj27ow01Mk1cI9PO2LbchSfxt+hXtGPHCstmtEaGs1L/qI8IVkjQ+sW qGh1OAVyyEFRPeMCxE2Gx0a1U8IfSGfLnXoSKmNIfnyyC0hSDLrWgvu3sZwcXGsM4dEP ngvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=ejWPrHbvUkKeqGL1OR1Rhnryt3c3itUcJJAQiRGOvs8=; b=XeTdvrYJVLtuQhEE4hLCv6nJpm/a8VHtY/vd9FHo7/oLtrAZTXHBd0G51Fl36YMTOJ bH4I2IoArEYEtT31ODaXUxFakdg8bWA1RsGNWpOIJfZMp2rq7eeq3Ju9VSaEGuGZ3WBK rCiWV29mZRN6JagInMBHs2i9fcoYqw23LjeImqeGGQUapoECQRiJtB853KFuM83eb8a8 OCyZ9X4z4OFe43q7+vo+Rpl/vV5vW4TlPoowI10rYAaZm+9oAj+k5o7bSZvL132ObgEy UW2t9vb7EdfOuwX8ZyFWsrPAwprNnVCqkd+rEFJqjjLkRW832V9eTK1QKn9IO5tDTsEt z/fg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d197si17414434pga.110.2019.06.03.08.55.08; Mon, 03 Jun 2019 08:55:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729532AbfFCPzH (ORCPT + 30 others); Mon, 3 Jun 2019 11:55:07 -0400 Received: from foss.arm.com ([217.140.101.70]:53542 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728296AbfFCPvE (ORCPT ); Mon, 3 Jun 2019 11:51:04 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4F58D169E; Mon, 3 Jun 2019 08:51:04 -0700 (PDT) Received: from en101.cambridge.arm.com (en101.cambridge.arm.com [10.1.196.93]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 1C7283F246; Mon, 3 Jun 2019 08:51:02 -0700 (PDT) From: Suzuki K Poulose To: linux-kernel@vger.kernel.org Cc: gregkh@linuxfoundation.org, rafael@kernel.org, suzuki.poulose@arm.com, Ulf Hansson , Joe Perches Subject: [RFC PATCH 04/57] drivers: Add generic match helper to match the device of_node Date: Mon, 3 Jun 2019 16:49:30 +0100 Message-Id: <1559577023-558-5-git-send-email-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1559577023-558-1-git-send-email-suzuki.poulose@arm.com> References: <1559577023-558-1-git-send-email-suzuki.poulose@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Instead of spilling the match function to check the of_node for a given value, lets add a common helper. Also add a wrapper to find device by of_node pointer for bus. Cc: "Rafael J. Wysocki" Cc: Greg Kroah-Hartman Cc: Ulf Hansson Cc: Joe Perches Signed-off-by: Suzuki K Poulose --- drivers/base/core.c | 6 ++++++ include/linux/device.h | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) -- 2.7.4 diff --git a/drivers/base/core.c b/drivers/base/core.c index fd7511e..d20699c 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -3328,3 +3328,9 @@ void device_set_of_node_from_dev(struct device *dev, const struct device *dev2) dev->of_node_reused = true; } EXPORT_SYMBOL_GPL(device_set_of_node_from_dev); + +int device_match_of_node(struct device *dev, void *np) +{ + return dev->of_node == np; +} +EXPORT_SYMBOL_GPL(device_match_of_node); diff --git a/include/linux/device.h b/include/linux/device.h index e85264f..fe16be4 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -163,6 +163,8 @@ void subsys_dev_iter_init(struct subsys_dev_iter *iter, struct device *subsys_dev_iter_next(struct subsys_dev_iter *iter); void subsys_dev_iter_exit(struct subsys_dev_iter *iter); +int device_match_of_node(struct device *dev, void *np); + int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data, int (*fn)(struct device *dev, void *data)); struct device *bus_find_device(struct bus_type *bus, struct device *start, @@ -171,6 +173,21 @@ struct device *bus_find_device(struct bus_type *bus, struct device *start, struct device *bus_find_device_by_name(struct bus_type *bus, struct device *start, const char *name); + +/** + * bus_find_device_by_of_node : device iterator for locating a particular device + * matching the of_node. + * @bus: bus type + * @start: Device to begin with + * @np: of_node of the device to match. + */ +static inline struct device *bus_find_device_by_of_node(struct bus_type *bus, + struct device *start, + struct device_node *np) +{ + return bus_find_device(bus, start, np, device_match_of_node); +} + struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id, struct device *hint); int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,