From patchwork Fri Jun 14 17:54:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 166898 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2353091ilk; Fri, 14 Jun 2019 10:55:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqyLELEBLlMTMkuzD1REx2T/bP8C1xOd+ni/RtJ+30/PdwiQErpq2qVeRK8+nesKqeRMUcZS X-Received: by 2002:a63:4e07:: with SMTP id c7mr37369685pgb.350.1560534936124; Fri, 14 Jun 2019 10:55:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560534936; cv=none; d=google.com; s=arc-20160816; b=D90H5R8HmqOHECxSBebGl8Fyt/KyolFTfgz7D6PH4oJH56xWCfI4z/GTLMyUVupe91 INxEwq+/KqZVH981Sz2517rTYF6C/hZ90NZnwK80DEK5E8tWCQR3ljzarI7xO4MzuOwj +927SWsF5o79E5htAtEmFQbINdFLGboq1PopwU4qjEB0mE/q5mw+t5UMOB2rKYASVMuZ j82u+kSM+KIfCJGmfWKZdRQhJXbqwcsYu1ZT2pHWRv9+SOwLatVE3IP+I31aLsVWINd/ +gCZZFh9BTCrLA8K2X6XALpNaUgAM2Y5el8S0nP1bXaFF2NazoTYyBFrIEhPBN23BHEL fBvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=0UDwGiiLdQl3rWyCFjN/Z2Bk9tuVbE3XkJtagVlWj9A=; b=RUXmcIk2bqQwPhZgUhaLdrpnuJa0r8hIhe5+hyMELlQWP+OIZWR7JxxBdM05tDyMJf 9vsGDgoG0GPUJNHJMy6q1tDKkrXNw/4O6xJ7IrVideCDL28x1gLLigncpmEZOurdjFa5 CG6b2cRQH2X5tZ5iAXGvoIgjUG+UCPxLsiU3wgBqyWxxkHn6Blec0nkw7gpYBrQrOaaO fTQQnoe692tb7kjOjWU7Q8sVmPwuDLK67ouoQcYpDySiLEnf+Y73H+9EIvYzPbP3GOC6 D/JiWn2N7dgiHSmN5zliyRt06IIutMfwKgZuGkIheKaDqSDg9ifzwmyY1b4zP7cbyFy/ J3yQ== 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 e36si2867016plb.180.2019.06.14.10.55.35; Fri, 14 Jun 2019 10:55:36 -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 S1727757AbfFNRze (ORCPT + 17 others); Fri, 14 Jun 2019 13:55:34 -0400 Received: from foss.arm.com ([217.140.110.172]:39728 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727742AbfFNRzc (ORCPT ); Fri, 14 Jun 2019 13:55:32 -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 DD59311B3; Fri, 14 Jun 2019 10:55:31 -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 A44413F718; Fri, 14 Jun 2019 10:55:30 -0700 (PDT) From: Suzuki K Poulose To: linux-kernel@vger.kernel.org Cc: gregkh@linuxfoundation.org, rafael@kernel.org, suzuki.poulose@arm.com, Eric Anholt , =?utf-8?q?Heiko_St=C3=BCbner?= , Inki Dae , Sandy Huang , Seung-Woo Kim Subject: [PATCH v2 28/28] platform: Add platform_find_device_by_driver() helper Date: Fri, 14 Jun 2019 18:54:23 +0100 Message-Id: <1560534863-15115-29-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> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Provide a helper to lookup platform devices by matching device driver in order to avoid drivers trying to use platform bus internals. Cc: Eric Anholt Cc: Greg Kroah-Hartman Cc: "Heiko Stübner" Cc: Inki Dae Cc: "Rafael J. Wysocki" Cc: Sandy Huang Cc: Seung-Woo Kim Tested-by: Heiko Stuebner Signed-off-by: Suzuki K Poulose --- drivers/base/platform.c | 14 ++++++++++++++ drivers/gpu/drm/exynos/exynos_drm_drv.c | 9 +++------ drivers/gpu/drm/rockchip/rockchip_drm_drv.c | 3 +-- drivers/gpu/drm/vc4/vc4_drv.c | 3 +-- include/linux/platform_device.h | 3 +++ 5 files changed, 22 insertions(+), 10 deletions(-) -- 2.7.4 diff --git a/drivers/base/platform.c b/drivers/base/platform.c index 4d17298..158ac24 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -1197,6 +1197,20 @@ struct bus_type platform_bus_type = { }; EXPORT_SYMBOL_GPL(platform_bus_type); +/** + * platform_find_device_by_driver - Find a platform device with a given + * driver. + * @start: The device to start the search from. + * @drv: The device driver to look for. + */ +struct device *platform_find_device_by_driver(struct device *start, + const struct device_driver *drv) +{ + return bus_find_device(&platform_bus_type, start, drv, + (void *)platform_match); +} +EXPORT_SYMBOL_GPL(platform_find_device_by_driver); + int __init platform_bus_init(void) { int error; diff --git a/drivers/gpu/drm/exynos/exynos_drm_drv.c b/drivers/gpu/drm/exynos/exynos_drm_drv.c index ba8932a..b357e0d 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_drv.c +++ b/drivers/gpu/drm/exynos/exynos_drm_drv.c @@ -244,9 +244,7 @@ static struct component_match *exynos_drm_match_add(struct device *dev) if (!info->driver || !(info->flags & DRM_COMPONENT_DRIVER)) continue; - while ((d = bus_find_device(&platform_bus_type, p, - &info->driver->driver, - (void *)platform_bus_type.match))) { + while ((d = platform_find_device_by_driver(p, &info->driver->driver))) { put_device(p); if (!(info->flags & DRM_FIMC_DEVICE) || @@ -414,9 +412,8 @@ static void exynos_drm_unregister_devices(void) if (!info->driver || !(info->flags & DRM_VIRTUAL_DEVICE)) continue; - while ((dev = bus_find_device(&platform_bus_type, NULL, - &info->driver->driver, - (void *)platform_bus_type.match))) { + while ((dev = platform_find_device_by_driver(NULL, + &info->driver->driver))) { put_device(dev); platform_device_unregister(to_platform_device(dev)); } diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c index 53d2c5b..38dc263 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c @@ -330,8 +330,7 @@ static struct component_match *rockchip_drm_match_add(struct device *dev) struct device *p = NULL, *d; do { - d = bus_find_device(&platform_bus_type, p, &drv->driver, - (void *)platform_bus_type.match); + d = platform_find_device_by_driver(p, &drv->driver); put_device(p); p = d; diff --git a/drivers/gpu/drm/vc4/vc4_drv.c b/drivers/gpu/drm/vc4/vc4_drv.c index 6d9be20..d159eb5 100644 --- a/drivers/gpu/drm/vc4/vc4_drv.c +++ b/drivers/gpu/drm/vc4/vc4_drv.c @@ -236,8 +236,7 @@ static void vc4_match_add_drivers(struct device *dev, struct device_driver *drv = &drivers[i]->driver; struct device *p = NULL, *d; - while ((d = bus_find_device(&platform_bus_type, p, drv, - (void *)platform_bus_type.match))) { + while ((d = platform_find_device_by_driver(p, drv))) { put_device(p); component_match_add(dev, match, compare_dev, d); p = d; diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h index beb25f2..c9c9d9e 100644 --- a/include/linux/platform_device.h +++ b/include/linux/platform_device.h @@ -51,6 +51,9 @@ extern struct device platform_bus; extern void arch_setup_pdev_archdata(struct platform_device *); extern struct resource *platform_get_resource(struct platform_device *, unsigned int, unsigned int); +extern struct device * +platform_find_device_by_driver(struct device *start, + const struct device_driver *drv); extern void __iomem * devm_platform_ioremap_resource(struct platform_device *pdev, unsigned int index);