From patchwork Mon Sep 21 14:02:41 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomeu Vizoso X-Patchwork-Id: 7231351 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 4FBBEBEEC1 for ; Mon, 21 Sep 2015 14:06:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5BECB20793 for ; Mon, 21 Sep 2015 14:06:31 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 711BC2076F for ; Mon, 21 Sep 2015 14:06:30 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Ze1hT-0002G7-9D; Mon, 21 Sep 2015 14:04:11 +0000 Received: from mail-wi0-x22b.google.com ([2a00:1450:400c:c05::22b]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Ze1hD-00020x-BE for linux-arm-kernel@lists.infradead.org; Mon, 21 Sep 2015 14:03:59 +0000 Received: by wicgb1 with SMTP id gb1so116318239wic.1 for ; Mon, 21 Sep 2015 07:03:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=gHexCavtMdIwGX9SRwOeufi85Mycj3AEl4t3hWoi080=; b=T50o6xkNZ5lFj1WTYGdtQdw0ciMcqcKkH9td9LKI7xeKNSDT4lrNGV/rybl1h7omfQ 1NzRvGqzDDOEOBi6HYktiZLTv/co2avCFuq29WBB1i09fSr+kdRK4M90iuiflI+x2dxV +J7GEvrz0OFedjGvqsZqar/cnovNBp7SnDd/CO34EeKAgH7/jO4IqmWDOOmaIs9HGI0z 3zxSA+1L1TZAKNAOouoo0sGaj+HhCmGq7wcHnwqNo9wFoLgBFslemdg3Bj9c1WxHH7Nb 5Ow2YODiGScwjQE2WIDtMJwDWqyHt3t+/ULeg4Pp3Kgconfh0LN2XuTqwvblBCf6YrzO 490w== X-Received: by 10.194.239.167 with SMTP id vt7mr26156463wjc.5.1442844211457; Mon, 21 Sep 2015 07:03:31 -0700 (PDT) Received: from cizrna.lan ([109.72.12.69]) by smtp.gmail.com with ESMTPSA id gk9sm13687031wib.9.2015.09.21.07.03.29 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Sep 2015 07:03:30 -0700 (PDT) From: Tomeu Vizoso To: linux-kernel@vger.kernel.org Subject: [PATCH v6 01/22] driver core: handle -EPROBE_DEFER from bus_type.match() Date: Mon, 21 Sep 2015 16:02:41 +0200 Message-Id: <1442844182-27787-2-git-send-email-tomeu.vizoso@collabora.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1442844182-27787-1-git-send-email-tomeu.vizoso@collabora.com> References: <1442844182-27787-1-git-send-email-tomeu.vizoso@collabora.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150921_070355_545987_5519C231 X-CRM114-Status: GOOD ( 20.43 ) X-Spam-Score: -2.6 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tomeu Vizoso , devicetree@vger.kernel.org, linux-acpi@vger.kernel.org, Arnd Bergmann , Stephen Warren , Greg Kroah-Hartman , Linus Walleij , Dmitry Torokhov , "Rafael J. Wysocki" , Rob Herring , Javier Martinez Canillas , Mark Brown , Thierry Reding , Alan Stern , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Lets implementations of the match() callback in struct bus_type to return errors and if it's -EPROBE_DEFER then queue the device for deferred probing. This is useful to buses such as AMBA in which devices are registered before their matching information can be retrieved from the HW (typically because a clock driver hasn't probed yet). Signed-off-by: Tomeu Vizoso --- drivers/base/dd.c | 24 ++++++++++++++++++++++-- include/linux/device.h | 2 +- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/drivers/base/dd.c b/drivers/base/dd.c index be0eb4639128..7dc04ee81c8b 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -488,6 +488,7 @@ static int __device_attach_driver(struct device_driver *drv, void *_data) struct device_attach_data *data = _data; struct device *dev = data->dev; bool async_allowed; + int ret; /* * Check if device has already been claimed. This may @@ -498,8 +499,17 @@ static int __device_attach_driver(struct device_driver *drv, void *_data) if (dev->driver) return -EBUSY; - if (!driver_match_device(drv, dev)) + ret = driver_match_device(drv, dev); + if (!ret) return 0; + else if (ret < 0) { + if (ret == -EPROBE_DEFER) { + dev_dbg(dev, "Device match requests probe deferral\n"); + driver_deferred_probe_add(dev); + } else + dev_warn(dev, "Bus failed to match device: %d", ret); + return ret; + } async_allowed = driver_allows_async_probing(drv); @@ -619,6 +629,7 @@ void device_initial_probe(struct device *dev) static int __driver_attach(struct device *dev, void *data) { struct device_driver *drv = data; + int ret; /* * Lock device and try to bind to it. We drop the error @@ -630,8 +641,17 @@ static int __driver_attach(struct device *dev, void *data) * is an error. */ - if (!driver_match_device(drv, dev)) + ret = driver_match_device(drv, dev); + if (!ret) + return 0; + else if (ret < 0) { + if (ret == -EPROBE_DEFER) { + dev_dbg(dev, "Device match requests probe deferral\n"); + driver_deferred_probe_add(dev); + } else + dev_warn(dev, "Bus failed to match device: %d", ret); return 0; + } if (dev->parent) /* Needed for USB */ device_lock(dev->parent); diff --git a/include/linux/device.h b/include/linux/device.h index 5d7bc6349930..8e7b806f0744 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -70,7 +70,7 @@ extern void bus_remove_file(struct bus_type *, struct bus_attribute *); * @dev_groups: Default attributes of the devices on the bus. * @drv_groups: Default attributes of the device drivers on the bus. * @match: Called, perhaps multiple times, whenever a new device or driver - * is added for this bus. It should return a nonzero value if the + * is added for this bus. It should return a positive value if the * given device can be handled by the given driver. * @uevent: Called when a device is added, removed, or a few other things * that generate uevents to add the environment variables.