From patchwork Tue Sep 29 09:10:39 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomeu Vizoso X-Patchwork-Id: 7283871 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 77BE0BEEA4 for ; Tue, 29 Sep 2015 09:15:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 83083206BD for ; Tue, 29 Sep 2015 09:15:20 +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 91CB6206B8 for ; Tue, 29 Sep 2015 09:15:19 +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 1Zgqyu-0000Vj-UX; Tue, 29 Sep 2015 09:13:52 +0000 Received: from mail-wi0-x234.google.com ([2a00:1450:400c:c05::234]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZgqxS-0000JO-MZ for linux-arm-kernel@lists.infradead.org; Tue, 29 Sep 2015 09:12:23 +0000 Received: by wiclk2 with SMTP id lk2so5887029wic.1 for ; Tue, 29 Sep 2015 02:12:01 -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=c02KOggVGn1eovWC1c/cm1RZa6Q8UgqwAaf1526QKOQqDPE1/8x1YoS5cQeRLGDzSz CpHGDhWuMhJa2yJanmW0gFKePsbHjiUewJCxwdPJdGYR0TUqR9YMP/Q+zYG2tXuBXbrL FRLW5oRbaJoe1ABez5rmE6kg6oxsK65kyy8VxH+/Bryfw1nZP6Q11f7oswGew/uKqPMa pm+zYh3kfNkva8N8FaVEXY7A/sXp6Iw7ojLgjVBIuwYIWFbpK0aLg0aR8t2wfOXMtehK IdhTwG1PIkt76VzNLeTr+G4wTN/hoCC1TiPZKEQP0b8bdPK4FcE+vNIrEO0kzXI1FtUm POMQ== X-Received: by 10.180.74.47 with SMTP id q15mr24817519wiv.73.1443517921011; Tue, 29 Sep 2015 02:12:01 -0700 (PDT) Received: from cizrna.lan ([109.72.12.204]) by smtp.gmail.com with ESMTPSA id lj12sm22757276wic.0.2015.09.29.02.11.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Sep 2015 02:11:59 -0700 (PDT) From: Tomeu Vizoso To: linux-kernel@vger.kernel.org Subject: [PATCH v7 01/20] driver core: handle -EPROBE_DEFER from bus_type.match() Date: Tue, 29 Sep 2015 11:10:39 +0200 Message-Id: <1443517859-30376-2-git-send-email-tomeu.vizoso@collabora.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1443517859-30376-1-git-send-email-tomeu.vizoso@collabora.com> References: <1443517859-30376-1-git-send-email-tomeu.vizoso@collabora.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150929_021222_899207_4D2E25F7 X-CRM114-Status: GOOD ( 20.22 ) X-Spam-Score: -2.4 (--) 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, Ulf Hansson , 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 , Russell King , 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, T_DKIM_INVALID, T_RP_MATCHES_RCVD, 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.