From patchwork Fri Jun 14 17:54:13 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: 166892 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2352910ilk; Fri, 14 Jun 2019 10:55:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqwFBvlly+VarruWvbmnO15igWrmegCOz6lgPHS0xM2vGZWFu9eK+9FFUX3LQZjPiao0E3ak X-Received: by 2002:a17:90a:9a83:: with SMTP id e3mr12048633pjp.105.1560534923692; Fri, 14 Jun 2019 10:55:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560534923; cv=none; d=google.com; s=arc-20160816; b=poZhhND54mitB2niZckQVWt+FRLZOgxL4bkzY2DHPwDhN5Ta7pRXtDE62564mP6oOf ZC52D/l01d7FcnqkL+2/HDXz2AGjs7Jg2LZcm6YqPERguxgjXq/NVBGP1xwGscdHw2PM JljNwfGI9RmrgINlv6Bred/9HKhxDjjSt7rw6AFLuUHMi+81fMylG127Fcq1dIbn0lrl 32b5rpaqcJWO2RCdpQFZz9RrxwLgwuwbgNcgItqOyJI6qoM47CiqKYvrunzYJomLwdS6 TJOE3gAQbyt0THcqiiihXuI5l8zmem+FR3pba4hWBd4FFxCq50kUlmP21/DwjkzeoZYz OVkw== 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=zvCb0+Vr+zopZND2fzyVfHjYH7um2/patXC/Iy+jYqs=; b=aik1FjcqzPjg3I8JgVpcvKUNp+wcMaLEi3s5CuTWTlRrV+B/lC0wQwvb/zFqCdUkOk jPvMf1XMraL8cvGtT4eme8DZj5/EazbdUxDaQnME8z6BKXF740l+he7Wc/l8XZYSejKl hafs31xnHO4GofB3zNZYKijy37U3yAwaqDxHshRulU7PLnKP0OqRzrXNe6BCjjUzcVAZ xzvJGOc7yFACnG9BuZJpltVu5TfY4UQ4Vu7wxSQ/hCVI3m7ZV/PPiFsOQZA4g1sgOVWI vaDpbuH3zrqikOAT0pfLS8m3tl9KemuVhdk4il5vijKW7LjKdO+OeRdJHAhC/eG/qGn0 py8g== 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 h4si3050048pgs.269.2019.06.14.10.55.23; Fri, 14 Jun 2019 10:55:23 -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 S1727622AbfFNRzW (ORCPT + 17 others); Fri, 14 Jun 2019 13:55:22 -0400 Received: from foss.arm.com ([217.140.110.172]:39612 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727326AbfFNRzU (ORCPT ); Fri, 14 Jun 2019 13:55:20 -0400 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 D4175106F; Fri, 14 Jun 2019 10:55:19 -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 EC49C3F718; Fri, 14 Jun 2019 10:55:18 -0700 (PDT) From: Suzuki K Poulose To: linux-kernel@vger.kernel.org Cc: gregkh@linuxfoundation.org, rafael@kernel.org, suzuki.poulose@arm.com, "David S. Miller" , Doug Ledford Subject: [PATCH v2 18/28] drivers: Introduce bus_find_device_by_fwnode() helper Date: Fri, 14 Jun 2019 18:54:13 +0100 Message-Id: <1560534863-15115-19-git-send-email-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1560534863-15115-1-git-send-email-suzuki.poulose@arm.com> References: <1560534863-15115-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 Add a wrapper to bus_find_device() to search for a device by the fwnode pointer, reusing the generic match function. Also convert the existing users to make use of the new helper. Cc: "David S. Miller" Cc: Doug Ledford Cc: Greg Kroah-Hartman Cc: "Rafael J. Wysocki" Signed-off-by: Suzuki K Poulose --- drivers/base/devcon.c | 8 +------- drivers/infiniband/hw/hns/hns_roce_hw_v1.c | 8 +------- drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c | 8 +------- include/linux/device.h | 12 ++++++++++++ 4 files changed, 15 insertions(+), 21 deletions(-) -- 2.7.4 diff --git a/drivers/base/devcon.c b/drivers/base/devcon.c index ac026d5..5a888eaa 100644 --- a/drivers/base/devcon.c +++ b/drivers/base/devcon.c @@ -107,19 +107,13 @@ static struct bus_type *generic_match_buses[] = { NULL, }; -static int device_fwnode_match(struct device *dev, const void *fwnode) -{ - return dev_fwnode(dev) == fwnode; -} - static void *device_connection_fwnode_match(struct device_connection *con) { struct bus_type *bus; struct device *dev; for (bus = generic_match_buses[0]; bus; bus++) { - dev = bus_find_device(bus, NULL, (void *)con->fwnode, - device_fwnode_match); + dev = bus_find_device_by_fwnode(bus, con->fwnode); if (dev && !strncmp(dev_name(dev), con->id, strlen(con->id))) return dev; diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v1.c b/drivers/infiniband/hw/hns/hns_roce_hw_v1.c index 3afd3e9..6779b7d 100644 --- a/drivers/infiniband/hw/hns/hns_roce_hw_v1.c +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v1.c @@ -4498,19 +4498,13 @@ static const struct acpi_device_id hns_roce_acpi_match[] = { }; MODULE_DEVICE_TABLE(acpi, hns_roce_acpi_match); -static int hns_roce_node_match(struct device *dev, const void *fwnode) -{ - return dev->fwnode == fwnode; -} - static struct platform_device *hns_roce_find_pdev(struct fwnode_handle *fwnode) { struct device *dev; /* get the 'device' corresponding to the matching 'fwnode' */ - dev = bus_find_device(&platform_bus_type, NULL, - fwnode, hns_roce_node_match); + dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode); /* get the platform device */ return dev ? to_platform_device(dev) : NULL; } diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c index bb6586d..ed3829a 100644 --- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c +++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c @@ -754,17 +754,11 @@ struct dsaf_misc_op *hns_misc_op_get(struct dsaf_device *dsaf_dev) return (void *)misc_op; } -static int hns_dsaf_dev_match(struct device *dev, const void *fwnode) -{ - return dev->fwnode == fwnode; -} - struct platform_device *hns_dsaf_find_platform_device(struct fwnode_handle *fwnode) { struct device *dev; - dev = bus_find_device(&platform_bus_type, NULL, - fwnode, hns_dsaf_dev_match); + dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode); return dev ? to_platform_device(dev) : NULL; } diff --git a/include/linux/device.h b/include/linux/device.h index 35f51d6..576d84f 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -201,6 +201,18 @@ bus_find_device_by_of_node(struct bus_type *bus, const struct device_node *np) return bus_find_device(bus, NULL, np, device_match_of_node); } +/** + * bus_find_device_by_fwnode : device iterator for locating a particular device + * matching the fwnode. + * @bus: bus type + * @fwnode: fwnode of the device to match. + */ +static inline struct device * +bus_find_device_by_fwnode(struct bus_type *bus, const struct fwnode_handle *fwnode) +{ + return bus_find_device(bus, NULL, fwnode, device_match_fwnode); +} + 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,