From patchwork Tue Feb 12 02:58:35 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haojian Zhuang X-Patchwork-Id: 14755 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 30BCD23E00 for ; Tue, 12 Feb 2013 02:59:10 +0000 (UTC) Received: from mail-ve0-f179.google.com (mail-ve0-f179.google.com [209.85.128.179]) by fiordland.canonical.com (Postfix) with ESMTP id C28BFA18C11 for ; Tue, 12 Feb 2013 02:59:09 +0000 (UTC) Received: by mail-ve0-f179.google.com with SMTP id da11so5662211veb.24 for ; Mon, 11 Feb 2013 18:59:09 -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=LTPHwJWnFlglWnIxczahUa12ok86LFyUyScytmqo+NM=; b=Rqs1hqiF3mva5m+z7k3+ZHE2slv8gzG2X98hKQEYUef/0Dz6MEINw343XO6LAKkfdQ a2OJCrYetFOupfppoVgaIumgx/5XOzR9yUgAhyIE6Jy7OrhjFrZvQIQV05ZBN43oGR8p WobocNNkfghbaZlSq6NfYeMw5b6BkBENyeslJ5ZvYbS6Xiedv147KQ3ke27Td3mJkmG2 gLITXLzHSgm+br9WZP3Vw0t9bP7rlvWkFA3CjN6MBe7BgT6/b6gXU+iMcbRX7p4BbCsI PpDwD0M1xlxiXUSLrBOHLdlghtsku0DaiLgw7k489CHWLF7iyZxJT5qaANiyWCU5zRTL gCyg== X-Received: by 10.58.232.226 with SMTP id tr2mr21606576vec.48.1360637949284; Mon, 11 Feb 2013 18:59:09 -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 zo8csp130359vec; Mon, 11 Feb 2013 18:59:08 -0800 (PST) X-Received: by 10.50.163.7 with SMTP id ye7mr317699igb.18.1360637948539; Mon, 11 Feb 2013 18:59:08 -0800 (PST) Received: from mail-da0-f49.google.com (mail-da0-f49.google.com [209.85.210.49]) by mx.google.com with ESMTPS id j9si52922811pay.318.2013.02.11.18.59.08 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 11 Feb 2013 18:59:08 -0800 (PST) Received-SPF: neutral (google.com: 209.85.210.49 is neither permitted nor denied by best guess record for domain of haojian.zhuang@linaro.org) client-ip=209.85.210.49; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.210.49 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-da0-f49.google.com with SMTP id t11so2985106daj.22 for ; Mon, 11 Feb 2013 18:59:08 -0800 (PST) X-Received: by 10.66.78.100 with SMTP id a4mr47669452pax.4.1360637947767; Mon, 11 Feb 2013 18:59:07 -0800 (PST) Received: from localhost.localdomain ([27.115.121.35]) by mx.google.com with ESMTPS id t4sm29819945pax.0.2013.02.11.18.58.49 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 11 Feb 2013 18:59:06 -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, 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, akpm@linux-foundation.org Cc: patches@linaro.org, Haojian Zhuang Subject: [PATCH v2] driver core: add wait event for deferred probe Date: Tue, 12 Feb 2013 10:58:35 +0800 Message-Id: <1360637915-11212-1-git-send-email-haojian.zhuang@linaro.org> X-Mailer: git-send-email 1.7.10.4 X-Gm-Message-State: ALoCoQnTHrLvwWza9BuredZC728gpwet4ERMRYxoUokjkalg2EzWe6InyInXniTgWr6Hh9YFYgqT 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(). Changelog: v2: add comments on wait_for_device_probe(). Signed-off-by: Haojian Zhuang --- drivers/base/dd.c | 8 +++++--- init/main.c | 2 ++ 2 files changed, 7 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..141a6a4 100644 --- a/init/main.c +++ b/init/main.c @@ -786,6 +786,8 @@ static void __init do_basic_setup(void) do_ctors(); usermodehelper_enable(); do_initcalls(); + /* wait all deferred probe finished & prepare to drop __init section */ + wait_for_device_probe(); } static void __init do_pre_smp_initcalls(void)