From patchwork Sat Feb 9 16:57:57 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haojian Zhuang X-Patchwork-Id: 14710 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 89B0E23E01 for ; Sat, 9 Feb 2013 16:59:05 +0000 (UTC) Received: from mail-vc0-f171.google.com (mail-vc0-f171.google.com [209.85.220.171]) by fiordland.canonical.com (Postfix) with ESMTP id 2528FA19300 for ; Sat, 9 Feb 2013 16:59:05 +0000 (UTC) Received: by mail-vc0-f171.google.com with SMTP id p1so3016930vcq.30 for ; Sat, 09 Feb 2013 08:59:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:x-received:from:to:cc:subject:date:message-id:x-mailer :x-gm-message-state; bh=dfo0oCVH52lSQMz10fj1KsVQMooEzMw4jwFeRB04zzE=; b=gXHEDJToylziDgzoUOKhhhFrLphnwF7x3/vzGPA3n5RxLiJA4s7H0nR6rbtbCNbjFT lItjpi/f8DGCZJ1eupH5ss5Q0u+eP5+mGRDl99D39phmuekktiZ4HkwfIZ+AB3xaJ903 6DJHJouvB8cD8hqsbTisAF6K4IZMJTVbAcLrzbspamJBxpmgMAhtAFdWGkwpzNP4BrJ5 3HHRkz9ojc/RzMjpxcr9RMH1mdlL8qB3sLodZTKqhCwtY1MqrEZ32YoMmoDxyrDZQG1S ZPCQK+KbLdP0BG2jS/d9WbTFQYdwTSnPV+VHHffx4wNEA4us//m6vQTB2ozpAsHs4c4K TkUw== X-Received: by 10.52.21.146 with SMTP id v18mr10274536vde.79.1360429144536; Sat, 09 Feb 2013 08:59:04 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.58.252.8 with SMTP id zo8csp18763vec; Sat, 9 Feb 2013 08:59:03 -0800 (PST) X-Received: by 10.68.191.103 with SMTP id gx7mr4925394pbc.109.1360429143555; Sat, 09 Feb 2013 08:59:03 -0800 (PST) Received: from mail-pb0-f54.google.com (mail-pb0-f54.google.com [209.85.160.54]) by mx.google.com with ESMTPS id af3si1703248pbd.278.2013.02.09.08.59.02 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 09 Feb 2013 08:59:03 -0800 (PST) Received-SPF: neutral (google.com: 209.85.160.54 is neither permitted nor denied by best guess record for domain of haojian.zhuang@linaro.org) client-ip=209.85.160.54; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.160.54 is neither permitted nor denied by best guess record for domain of haojian.zhuang@linaro.org) smtp.mail=haojian.zhuang@linaro.org Received: by mail-pb0-f54.google.com with SMTP id rr4so163247pbb.13 for ; Sat, 09 Feb 2013 08:59:02 -0800 (PST) X-Received: by 10.66.80.65 with SMTP id p1mr28064124pax.20.1360429142777; Sat, 09 Feb 2013 08:59:02 -0800 (PST) Received: from localhost.localdomain ([27.115.121.35]) by mx.google.com with ESMTPS id pt5sm1971336pbc.46.2013.02.09.08.58.36 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 09 Feb 2013 08:59:00 -0800 (PST) From: Haojian Zhuang To: gregkh@linuxfoundation.org, viro@zeniv.linux.org.uk, rusty@rustcorp.com.au, hpa@linux.intel.com, jim.cromie@gmail.com, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux@arm.linux.org.uk, linus.walleij@linaro.org, grant.likely@secretlab.ca, arnd@arndb.de, broonie@opensource.wolfsonmicro.com Cc: patches@linaro.org, Haojian Zhuang Subject: [PATCH] driver core: add wait event for deferred probe Date: Sun, 10 Feb 2013 00:57:57 +0800 Message-Id: <1360429077-14616-1-git-send-email-haojian.zhuang@linaro.org> X-Mailer: git-send-email 1.7.10.4 X-Gm-Message-State: ALoCoQlJyHDF58K3Qf2KUX/Y5D0ckwAEdhX2arD36ADCs1TztruNVC9Gh1dhYwmnJUlHoFVAGCwX do_initcalls() could call all driver initialization code in kernel_init thread. It means that probe() function will be also called from that time. After this, kernel could access console & release __init section in the same thread. But if device probe fails and moves into deferred probe list, a new thread is created to reinvoke probe. If the device is serial console, kernel has to open console failure & release __init section before reinvoking failure. Because there's no synchronization mechanism. Now add wait event to synchronize after do_initcalls(). Signed-off-by: Haojian Zhuang Tested-by: --- drivers/base/dd.c | 8 +++++--- init/main.c | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/base/dd.c b/drivers/base/dd.c index 65631015..23db672 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -53,6 +53,9 @@ static LIST_HEAD(deferred_probe_pending_list); static LIST_HEAD(deferred_probe_active_list); static struct workqueue_struct *deferred_wq; +static atomic_t probe_count = ATOMIC_INIT(0); +static DECLARE_WAIT_QUEUE_HEAD(probe_waitqueue); + /** * deferred_probe_work_func() - Retry probing devices in the active list. */ @@ -77,6 +80,7 @@ static void deferred_probe_work_func(struct work_struct *work) private = list_first_entry(&deferred_probe_active_list, typeof(*dev->p), deferred_probe); dev = private->device; + atomic_dec(&probe_count); list_del_init(&private->deferred_probe); get_device(dev); @@ -257,9 +261,6 @@ int device_bind_driver(struct device *dev) } EXPORT_SYMBOL_GPL(device_bind_driver); -static atomic_t probe_count = ATOMIC_INIT(0); -static DECLARE_WAIT_QUEUE_HEAD(probe_waitqueue); - static int really_probe(struct device *dev, struct device_driver *drv) { int ret = 0; @@ -308,6 +309,7 @@ probe_failed: /* Driver requested deferred probing */ dev_info(dev, "Driver %s requests probe deferral\n", drv->name); driver_deferred_probe_add(dev); + atomic_inc(&probe_count); } else if (ret != -ENODEV && ret != -ENXIO) { /* driver matched but the probe failed */ printk(KERN_WARNING diff --git a/init/main.c b/init/main.c index 63534a1..033bf5f 100644 --- a/init/main.c +++ b/init/main.c @@ -786,6 +786,7 @@ static void __init do_basic_setup(void) do_ctors(); usermodehelper_enable(); do_initcalls(); + wait_for_device_probe(); } static void __init do_pre_smp_initcalls(void)