From patchwork Fri Jun 14 17:54:14 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: 166894 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2352952ilk; Fri, 14 Jun 2019 10:55:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqzILDUILPxtO1k1/kSUInx4WNsi3ZKmeUWWL1krRFzecg4u9eqKcFQbJWMsYsODkT0mZ7y4 X-Received: by 2002:a65:408d:: with SMTP id t13mr36535208pgp.373.1560534926388; Fri, 14 Jun 2019 10:55:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560534926; cv=none; d=google.com; s=arc-20160816; b=HSocisKyQPX+aR2CzeRXRl+zjweQBaPbPahGVqdQTmmJeEvQhXMZ3R3A7amF+F31UI sGW9B13fH3nwYXamrSXoC7C0yRtWi40dhhJ4zFHs0L+IXf19tcl5NUqReszoBhHsktjl Q61Lc4OA4FJkDUXRMYoc9AqsVbNBTOI+3QkGDyFXQGGtqHkhKGAMwdWr37J5D1SKsa6o dpcS8OPaRWddNWlXSHvgNjsLZVxumwdQut/X65DqehqRgZAEf+QIgk1JSC35rZf68des MIgSLpDrwBC5qondGCel5ZcGCIZGPUVBWXtsVLF23hso0KwWej4Wl+uPpxNItwA6a1th gkOw== 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=HkRSe7byq8ac8wfHcV5q1yxa3h5hcwcUPG5gTTebTFg=; b=aC6ckCDsJV7UJnq9/dspfg6unYIgZ+a9O4Ko2LX+A2xVVtu/UJg+qIn7VQ/NVkv6Mt lqcPGv04KBFdZFCkxuyc69/pPBfr3gpFpp1JZ2fpCO+FG+ycHuislLdMnyTCSGkYQ0Q8 nR/2p7V9r7m4EY4L/+usq/vlHomb/UHrZP318Mven8ovF70qGFb+aC7O+/x222z/l4m/ sCbA3WCQqP3JPfcObtHtC8/R0YPu0Tbj3aU0EPQmMpQIQyAydq7JSes3ho4FS1sM2P9M 9gOAgeSGeBKsu4hUQ0tes5wVkwxD9aksEEsjH/SACv40o5YjJQL7FYA5gCuAdcsQHNNw kLzQ== 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 f9si3064713pfd.110.2019.06.14.10.55.26; Fri, 14 Jun 2019 10:55:26 -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 S1727662AbfFNRzY (ORCPT + 17 others); Fri, 14 Jun 2019 13:55:24 -0400 Received: from foss.arm.com ([217.140.110.172]:39624 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727611AbfFNRzW (ORCPT ); Fri, 14 Jun 2019 13:55:22 -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 3124DCFC; Fri, 14 Jun 2019 10:55:21 -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 1358C3F718; Fri, 14 Jun 2019 10:55:19 -0700 (PDT) From: Suzuki K Poulose To: linux-kernel@vger.kernel.org Cc: gregkh@linuxfoundation.org, rafael@kernel.org, suzuki.poulose@arm.com, linux-usb@vger.kernel.org, Oliver Neukum , Sebastian Andrzej Siewior , Alexander Shishkin Subject: [PATCH v2 19/28] drivers: Introduce bus_find_device_by_devt() helper Date: Fri, 14 Jun 2019 18:54:14 +0100 Message-Id: <1560534863-15115-20-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 device type, reusing the generic match function. Also convert the existing users to make use of the new helper. Cc: linux-usb@vger.kernel.org Cc: Oliver Neukum Cc: Sebastian Andrzej Siewior Cc: Alexander Shishkin Cc: Greg Kroah-Hartman Cc: "Rafael J. Wysocki" Signed-off-by: Suzuki K Poulose --- drivers/hwtracing/intel_th/core.c | 10 +--------- drivers/usb/core/devio.c | 8 +------- include/linux/device.h | 12 ++++++++++++ 3 files changed, 14 insertions(+), 16 deletions(-) -- 2.7.4 diff --git a/drivers/hwtracing/intel_th/core.c b/drivers/hwtracing/intel_th/core.c index 5592289..d5c1821 100644 --- a/drivers/hwtracing/intel_th/core.c +++ b/drivers/hwtracing/intel_th/core.c @@ -789,12 +789,6 @@ static int intel_th_populate(struct intel_th *th) return 0; } -static int match_devt(struct device *dev, const void *data) -{ - dev_t devt = (dev_t)(unsigned long)(void *)data; - return dev->devt == devt; -} - static int intel_th_output_open(struct inode *inode, struct file *file) { const struct file_operations *fops; @@ -802,9 +796,7 @@ static int intel_th_output_open(struct inode *inode, struct file *file) struct device *dev; int err; - dev = bus_find_device(&intel_th_bus, NULL, - (void *)(unsigned long)inode->i_rdev, - match_devt); + dev = bus_find_device_by_devt(&intel_th_bus, inode->i_rdev); if (!dev || !dev->driver) return -ENODEV; diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c index 7bd7de7..4e83623 100644 --- a/drivers/usb/core/devio.c +++ b/drivers/usb/core/devio.c @@ -947,17 +947,11 @@ static int parse_usbdevfs_streams(struct usb_dev_state *ps, return ret; } -static int match_devt(struct device *dev, const void *data) -{ - return dev->devt == (dev_t)(unsigned long)(void *)data; -} - static struct usb_device *usbdev_lookup_by_devt(dev_t devt) { struct device *dev; - dev = bus_find_device(&usb_bus_type, NULL, - (void *) (unsigned long) devt, match_devt); + dev = bus_find_device_by_devt(&usb_bus_type, devt); if (!dev) return NULL; return to_usb_device(dev); diff --git a/include/linux/device.h b/include/linux/device.h index 576d84f..3c244ac 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -213,6 +213,18 @@ bus_find_device_by_fwnode(struct bus_type *bus, const struct fwnode_handle *fwno return bus_find_device(bus, NULL, fwnode, device_match_fwnode); } +/** + * bus_find_device_by_devt : device iterator for locating a particular device + * matching the device type. + * @bus: bus type + * @devt: device type of the device to match. + */ +static inline struct device *bus_find_device_by_devt(struct bus_type *bus, + dev_t devt) +{ + return bus_find_device(bus, NULL, &devt, device_match_devt); +} + 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,