Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965240AbbLWLCI (ORCPT ); Wed, 23 Dec 2015 06:02:08 -0500 Received: from mailout2.w1.samsung.com ([210.118.77.12]:32208 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754595AbbLWLAs (ORCPT ); Wed, 23 Dec 2015 06:00:48 -0500 X-AuditID: cbfec7f5-f79b16d000005389-4b-567a7edde259 From: Marek Szyprowski To: linux-samsung-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Marek Szyprowski , Russell King - ARM Linux , Ulf Hansson , Tomeu Vizoso , Greg Kroah-Hartman , Dan Williams , Kukjin Kim , Krzysztof Kozlowski , Bartlomiej Zolnierkiewicz Subject: [PATCH v5 3/5] driver core: handle -EPROBE_DEFER from bus_type.match() Date: Wed, 23 Dec 2015 11:59:26 +0100 Message-id: <1450868368-5650-4-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.9.2 In-reply-to: <1450868368-5650-1-git-send-email-m.szyprowski@samsung.com> References: <1450868368-5650-1-git-send-email-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrHLMWRmVeSWpSXmKPExsVy+t/xq7p366rCDM5M1LHYOGM9q8X0qRcY LZoXr2ezeP3C0KL/8Wtmi02Pr7FaXN41h81ixvl9TBa3L/NarD1yl92ib+0lNovja8MdeDxa mnvYPHbcXcLosXjPSyaPTas62TzuXNvD5rF/7hp2j81L6j36tqxi9Pi8SS6AM4rLJiU1J7Ms tUjfLoErY8vtO0wF21Qq1j9awdTAuFC2i5GTQ0LARGLd6X2sELaYxIV769m6GLk4hASWMkq0 tG5igXCamCQaV55iA6liEzCU6HrbBWaLCGRLzN/bzQ5SxCwwn1ni4ap+sFHCAv4Sxx/2M4PY LAKqEo2bljOC2LwC7hIrjn5nhlgnJ/H/5QomEJtTwEPizvJXYHEhoJq2g2+YJzDyLmBkWMUo mlqaXFCclJ5rpFecmFtcmpeul5yfu4kREqpfdzAuPWZ1iFGAg1GJh/dFc2WYEGtiWXFl7iFG CQ5mJRHe9HdAId6UxMqq1KL8+KLSnNTiQ4zSHCxK4rwzd70PERJITyxJzU5NLUgtgskycXBK NTC2XNxob3xcafGCx9fVJ7a178vcdclllWPZkw0PT/buSlms6Pr87b9j5y4uvmRQYdPQdX62 dta/GuVbr8UZrYvTKieuZdz0Wrp3m/WBGr7b6tfmLpmnsIP1sOXUzUf0rqX1JfvrdnwMCva9 /Kzh1edq+ReLV3o2Nx250udz4Z7P9WuLdy7smN+UqMRSnJFoqMVcVJwIAOQJAHNRAgAA Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4790 Lines: 122 From: Tomeu Vizoso Allow 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 [changed if-else code structure, adjusted documentation to match the code, extended comments] Signed-off-by: Marek Szyprowski Reviewed-by: Ulf Hansson --- Documentation/driver-model/porting.txt | 6 ++++-- drivers/base/dd.c | 24 ++++++++++++++++++++++-- include/linux/device.h | 7 +++++-- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/Documentation/driver-model/porting.txt b/Documentation/driver-model/porting.txt index 92d86f7..453053f 100644 --- a/Documentation/driver-model/porting.txt +++ b/Documentation/driver-model/porting.txt @@ -340,8 +340,10 @@ comparison: int (*match)(struct device * dev, struct device_driver * drv); -match should return '1' if the driver supports the device, and '0' -otherwise. +match should return positive value if the driver supports the device, +and zero otherwise. It may also return error code (for example +-EPROBE_DEFER) if determining that given driver supports the device is +not possible. When a device is registered, the bus's list of drivers is iterated over. bus->match() is called for each one until a match is found. diff --git a/drivers/base/dd.c b/drivers/base/dd.c index 7399be7..7c3f1f1 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -544,6 +544,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 @@ -554,8 +555,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 == 0) { + /* no match */ return 0; + } else if (ret == -EPROBE_DEFER) { + dev_dbg(dev, "Device match requests probe deferral\n"); + driver_deferred_probe_add(dev); + } else if (ret < 0) { + dev_dbg(dev, "Bus failed to match device: %d", ret); + return ret; + } /* ret > 0 means positive match */ async_allowed = driver_allows_async_probing(drv); @@ -675,6 +685,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 @@ -686,8 +697,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 == 0) { + /* no match */ return 0; + } else if (ret == -EPROBE_DEFER) { + dev_dbg(dev, "Device match requests probe deferral\n"); + driver_deferred_probe_add(dev); + } else if (ret < 0) { + dev_dbg(dev, "Bus failed to match device: %d", ret); + return ret; + } /* ret > 0 means positive match */ if (dev->parent) /* Needed for USB */ device_lock(dev->parent); diff --git a/include/linux/device.h b/include/linux/device.h index f627ba2..75a2cde 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -70,8 +70,11 @@ 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 - * given device can be handled by the given driver. + * is added for this bus. It should return a positive value if the + * given device can be handled by the given driver and zero + * otherwise. It may also return error code if determining that + * the driver supports the device is not possible. In case of + * -EPROBE_DEFER it will queue the device for deferred probing. * @uevent: Called when a device is added, removed, or a few other things * that generate uevents to add the environment variables. * @probe: Called when a new device or driver add to this bus, and callback -- 1.9.2 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/