From patchwork Wed Jun 5 15:13:49 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: 165901 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp7486108ili; Wed, 5 Jun 2019 08:15:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqxLezp8qMj24uW7suQ/BUkXk8Ainf2iz9W+RtIBgfW/4pDSLzxG/8tdtseX30HUYHq4avVc X-Received: by 2002:a17:90a:20e7:: with SMTP id f94mr36197677pjg.68.1559747709425; Wed, 05 Jun 2019 08:15:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559747709; cv=none; d=google.com; s=arc-20160816; b=h0prlkXz2loeyq/t64PckvFXb+vDQjjhNumpulmLCIfXpnLb0HJBh5AhNQ9F6BIoA0 FOgNZgpw940IYF5yXiz8TMAPC/CxJTbOZRFo0sznM+qB7Wh0vNl0AQgcuCxg8HHXHHP9 KMJ1U+H8b9aEMEqVmTFQfErlYW/NmWI/3LKUoDgfpRY+u2ZFDbMzNHzK2xxSosPRQ0Ej +mJsuB2+RK6VfxzMmAdUjqEoogiogeiBQ1IxnseRwGr92Dedq+dlqvFPPjFq+JCDLO0R bOkU2kA4/Sm258+MMhjxbbFqLe6r/G8zbEXkqQWl82FKT46AJH+f3OAalQA8TCriDcif lz8w== 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=AJd084C/SspqeyfJL9z44/0SGf2RPxyn1BhZR24Y250=; b=s/mOxiYl+mcBGOUTyinx4/VtldGg71zxi6b594r2xNWIGAGzqzzJRd+XjfnHWaMSfe lyiQYlNPDFUARQ2AXuHTSnC3VHhRIVcJZ414VNDrnUiJRb1ik/VAnf+NCdwQY3yIUMt7 8IKj/iknZY7xZlf6q6FT3X51TRmJLfyKKE1GOyxWdL9eThuACZn5M52m+e3eMPlSiGDM R47HIq3jtludClpgJCHYZ1sbh35NN/Gc3DMBLeYBwtrgOxUBg6nlGsIW1squkGsJoUBR x692xoe84xw1vK40CgFM3vxX9dmlHSClcaq2gmWuCYFfTUjKkKdosdCqKwiZlwDUugD0 XxDQ== 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 i18si22473813pfr.65.2019.06.05.08.15.08; Wed, 05 Jun 2019 08:15:09 -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 S1728664AbfFEPPD (ORCPT + 30 others); Wed, 5 Jun 2019 11:15:03 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:33624 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728650AbfFEPPA (ORCPT ); Wed, 5 Jun 2019 11:15:00 -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 E2DBC15BF; Wed, 5 Jun 2019 08:14:59 -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 CA9913F246; Wed, 5 Jun 2019 08:14:57 -0700 (PDT) From: Suzuki K Poulose To: linux-kernel@vger.kernel.org Cc: gregkh@linuxfoundation.org, rafael@kernel.org, suzuki.poulose@arm.com, Arnd Bergmann , Joerg Roedel , Jonathan Hunter , Lee Jones , Robin Murphy , Thierry Reding , Thor Thayer , Will Deacon Subject: [PATCH 12/13] drivers: Introduce variants of driver_find_device() Date: Wed, 5 Jun 2019 16:13:49 +0100 Message-Id: <1559747630-28065-13-git-send-email-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1559747630-28065-1-git-send-email-suzuki.poulose@arm.com> References: <1559747630-28065-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 Similar to the other device lookup helpers, introduce variants of driver_find_device() to automatically lookup devices by their generic properties to avoid proliferation of custom match functions. We add : driver_find_device_by_name driver_find_device_by_of_node driver_find_device_by_fwnode driver_find_device_by_devt driver_find_next_device Cc: Arnd Bergmann Cc: Joerg Roedel Cc: Jonathan Hunter Cc: Lee Jones Cc: Robin Murphy Cc: Thierry Reding Cc: Thor Thayer Cc: Will Deacon Cc: Greg Kroah-Hartman Cc: "Rafael J. Wysocki" Signed-off-by: Suzuki K Poulose --- include/linux/device.h | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) -- 2.7.4 diff --git a/include/linux/device.h b/include/linux/device.h index 10de79d..2c05e60 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -404,6 +404,64 @@ struct device *driver_find_device(struct device_driver *drv, struct device *start, const void *data, int (*match)(struct device *dev, const void *data)); +/** + * driver_find_device_by_name - device iterator for locating a particular device + * of a specific name. + * @driver: the driver we're iterating + * @name: name of the device to match + */ +static inline struct device *driver_find_device_by_name(struct device_driver *drv, + const char *name) +{ + return driver_find_device(drv, NULL, name, device_match_name); +} + +/** + * driver_find_device_by_of_node- device iterator for locating a particular device + * by of_node pointer. + * @driver: the driver we're iterating + * @np: of_node pointer to match. + */ +static inline struct device * +driver_find_device_by_of_node(struct device_driver *drv, + const struct device_node *np) +{ + return driver_find_device(drv, NULL, np, device_match_of_node); +} + +/** + * driver_find_device_by_fwnode- device iterator for locating a particular device + * by fwnode pointer. + * @driver: the driver we're iterating + * @fwnode: fwnode pointer to match. + */ +static inline struct device * +driver_find_device_by_fwnode(struct device_driver *drv, + const struct fwnode_handle *fwnode) +{ + return driver_find_device(drv, NULL, fwnode, device_match_fwnode); +} + +/** + * driver_find_device_by_devt- device iterator for locating a particular device + * by devt. + * @driver: the driver we're iterating + * @start: device to start search from + * @devt: devt pointer to match. + */ +static inline struct device *driver_find_device_by_devt(struct device_driver *drv, + struct device *start, + dev_t devt) +{ + return driver_find_device(drv, start, &devt, device_match_devt); +} + +static inline struct device *driver_find_next_device(struct device_driver *drv, + struct device *start) +{ + return driver_find_device(drv, start, NULL, device_match_any); +} + void driver_deferred_probe_add(struct device *dev); int driver_deferred_probe_check_state(struct device *dev);