From patchwork Thu Jan 5 23:03:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Kaehlcke X-Patchwork-Id: 39832 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp535342wrt; Thu, 5 Jan 2023 15:06:28 -0800 (PST) X-Google-Smtp-Source: AMrXdXsonZY1RewXt/DFk1sU5uXtN/v6UWxpfsdicefGcvpJ0iSHLdYjozfoHziTqYQ/Rbtjx1JU X-Received: by 2002:aa7:8215:0:b0:580:9151:afe5 with SMTP id k21-20020aa78215000000b005809151afe5mr45933439pfi.22.1672959987961; Thu, 05 Jan 2023 15:06:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672959987; cv=none; d=google.com; s=arc-20160816; b=I3VSPlVLGFO7hKvubmjn2elroVd0WSMBT7LGNYflIhNAzUONc4cl6f3syNS8mADVg9 3RIPOA66+FYP34eklqVc/1pMuXNdu6g/qKAwX9P7XevdrQdlLGGPtStizEXpsC6I3E63 vu/LEsZyk9EaMTZkJIHGOvQASDpYi4j74+qSPsUBTPuLSvMnCP4iCWtfaAIrt0ri9RFm 07vwK+vgAp5sDIEaKj29cD3XjiuQ03ZEycZf/O3pyIS//4N+qct/X1qAauuL/DWGWurR RV7vYQwWJ1dZJuFzmM1a6h+OrKvaFGydnlhkB3Vv4/E/CzvzMbkva67JG+eAbMyTPLKK /wpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=4PKtGdnj7K1nIf21o9CBuILUH/eT3WWN8YJ/Zsofy54=; b=ud615orMxtJAQ3IGtwLodUIvnzApWLII/2pLs+0o2gGUDU7FEgqoq5V9MF01ML91qK Rq43g/JmTvMOamGs5z5Bm8QE+81AFP07NVHqqKxUSF5T440/nkFKOqO6o5txoWDDAVOV xvWJk71JWc6aei+6Yn6+C20TNBBnPs+t6buTtkiZQwrUKU1dRMolRdWTy63PxEEX7h7Y BHPT7PBF0m4I1T2VGXYV+YlfRvr0QMA0EyoHE+x7SjdnxVRa6u0G/qJrAIVKVMuroslc 0KkKB6OS8MONpyKQrhhL9lALcwpc//oqYlEuDhJi39IxLVQcOQgNuj5bFqwyrkqWdHvp ol0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=e5xCzs9e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b7-20020a056a000cc700b00582b3c894b2si9704236pfv.341.2023.01.05.15.06.14; Thu, 05 Jan 2023 15:06:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=e5xCzs9e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236292AbjAEXDm (ORCPT + 99 others); Thu, 5 Jan 2023 18:03:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236273AbjAEXDf (ORCPT ); Thu, 5 Jan 2023 18:03:35 -0500 Received: from mail-io1-xd30.google.com (mail-io1-xd30.google.com [IPv6:2607:f8b0:4864:20::d30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A60D4671AD for ; Thu, 5 Jan 2023 15:03:34 -0800 (PST) Received: by mail-io1-xd30.google.com with SMTP id b192so20378714iof.8 for ; Thu, 05 Jan 2023 15:03:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=4PKtGdnj7K1nIf21o9CBuILUH/eT3WWN8YJ/Zsofy54=; b=e5xCzs9eHgOshb4PQlWO3g6CpcSTy9nAAbg6XfYg3NaRY9CT1M2YCGqM+0k2FbaRpp Up/kNOGwIxauumMuFVspQksn2rzRNaML5ce917OqicRwWAe5uUD8XleQAmXpRZ/+bXTB iAjBE1L+LjfhewIcoNlw8nYHwYIAfN7l4TpSE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=4PKtGdnj7K1nIf21o9CBuILUH/eT3WWN8YJ/Zsofy54=; b=G7ApB1svGQnPj19RwH08GjcgY5YcvO7bpXj91FXh1i6z8PMgWMdBR4Pz6rydj2Elr9 Ouw27UFLtrrTxL5+c6FIHK91iuOG65dPSJYXUUOvv6dGfL1M99If2i/FSUhE8BJR/7Xu lSLWhv8m2aq25L7aZ7536Grc3c4fze6eLguJtOWW3ZHzR+Gxzt6OP0qMQsLyZhwoa1Om OFUWPGDx3D6ff56bzbGoHVOVHvtjSGsyJyHEU2re2kA8DqMolralDpfI62N4YjXXSB3j OLkeqg5UFviagPsCwEhVGaBaHHYfX19Gu7KuLYL9yp97+UumhoSHvYBR+6Yy1sPg0R/6 gETQ== X-Gm-Message-State: AFqh2koG0eJas/zO+qUVmK8CwV5pK+NgWyQqBA3nyHGytXjm6chZU2Yt neRnzMENhJ1p55goVh1idue2Cw== X-Received: by 2002:a05:6602:1785:b0:6e0:3930:244a with SMTP id y5-20020a056602178500b006e03930244amr34979590iox.9.1672959814020; Thu, 05 Jan 2023 15:03:34 -0800 (PST) Received: from localhost (30.23.70.34.bc.googleusercontent.com. [34.70.23.30]) by smtp.gmail.com with UTF8SMTPSA id i7-20020a02ca47000000b003740de9fb65sm12164782jal.46.2023.01.05.15.03.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 05 Jan 2023 15:03:33 -0800 (PST) From: Matthias Kaehlcke To: Greg Kroah-Hartman Cc: Johan Hovold , linux-usb@vger.kernel.org, Stefan Wahren , Alexander Stein , Icenowy Zheng , Douglas Anderson , stable@vger.kernel.org, linux-kernel@vger.kernel.org, Matthias Kaehlcke , Ravi Chandra Sadineni Subject: [PATCH 1/2] usb: misc: onboard_hub: Invert driver registration order Date: Thu, 5 Jan 2023 23:03:28 +0000 Message-Id: <20230105230119.1.I75494ebee7027a50235ce4b1e930fa73a578fbe2@changeid> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754225692140245599?= X-GMAIL-MSGID: =?utf-8?q?1754225692140245599?= The onboard_hub 'driver' consists of two drivers, a platform driver and a USB driver. Currently when the onboard hub driver is initialized it first registers the platform driver, then the USB driver. This results in a race condition when the 'attach' work is executed, which is scheduled when the platform device is probed. The purpose of fhe 'attach' work is to bind elegible USB hub devices to the onboard_hub USB driver. This fails if the work runs before the USB driver has been registered. Register the USB driver first, then the platform driver. This increases the chances that the onboard_hub USB devices are probed before their corresponding platform device, which the USB driver tries to locate in _probe(). The driver already handles this situation and defers probing if the onboard hub platform device doesn't exist yet. Cc: stable@vger.kernel.org Fixes: 8bc063641ceb ("usb: misc: Add onboard_usb_hub driver") Link: https://lore.kernel.org/lkml/Y6W00vQm3jfLflUJ@hovoldconsulting.com/T/#m0d64295f017942fd988f7c53425db302d61952b4 Reported-by: Alexander Stein Signed-off-by: Matthias Kaehlcke --- drivers/usb/misc/onboard_usb_hub.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/usb/misc/onboard_usb_hub.c b/drivers/usb/misc/onboard_usb_hub.c index 94e7966e199d..db0844b30bbd 100644 --- a/drivers/usb/misc/onboard_usb_hub.c +++ b/drivers/usb/misc/onboard_usb_hub.c @@ -433,13 +433,13 @@ static int __init onboard_hub_init(void) { int ret; - ret = platform_driver_register(&onboard_hub_driver); + ret = usb_register_device_driver(&onboard_hub_usbdev_driver, THIS_MODULE); if (ret) return ret; - ret = usb_register_device_driver(&onboard_hub_usbdev_driver, THIS_MODULE); + ret = platform_driver_register(&onboard_hub_driver); if (ret) - platform_driver_unregister(&onboard_hub_driver); + usb_deregister_device_driver(&onboard_hub_usbdev_driver); return ret; } From patchwork Thu Jan 5 23:03:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Kaehlcke X-Patchwork-Id: 39833 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp535855wrt; Thu, 5 Jan 2023 15:07:56 -0800 (PST) X-Google-Smtp-Source: AMrXdXvPoql1ADxN/Wdak+lQbM5yFfppfrLSim5oqitltaZvZSBhypV4RR5NF19669K/Pgy8U6X2 X-Received: by 2002:a05:6a21:32a1:b0:aa:6efd:1883 with SMTP id yt33-20020a056a2132a100b000aa6efd1883mr86291366pzb.37.1672960075980; Thu, 05 Jan 2023 15:07:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672960075; cv=none; d=google.com; s=arc-20160816; b=D88hi+QXVfvXI1IMW8eOHLLqSd1uRh85hQM46C5/m341hndDlcUjIQPnM5tw5QRA7I gQHDMibF4JAJDS2zOxVIOc0n1DBrqJyUh+v38p0ebc6nFxvoNEoWJQWRI96GZxrcdXO3 LXWxMIKX7RLmO55Cz/YzZ5B2uArH9e5/51wkn51HkA0nbB77ePQeuKYzW7J0XIbxNOWx LPhSa5Tj5Ev6Zf5K/8VXO5asu1Iy23YncL6qYvK6jkxaaKeL0ixwDLtQQWAOhOhkcpjm ZKJahwgoUCM8xuF8qN6zjj1NCT6lvbOQwnPXrpNttoxppzBbsS3WCfIkvWZD1HcUxvw3 YZvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=DIcjgq7EV1t47RYy2g4kttoekM/X5riyLaeE0K4reIU=; b=YgWuif2f3XZV8tDfF5RF2Fd8OAB7BAvxeBXMxRzOHMnzT94ImY6XnRm1EMZ4N3e9Gt OSaNe82y9UOihf9/nAvdMkeNw9QiZLjjuLO6FsvmkHIcNEVy3Ui/oG0J0hzDjQCtouxB UAd75VoljshzHJsUvB/nl+kvyN3tQTAR1CKdJka+SO5e5VysAptjBHeDynk2mCuiqGoi ETO4qrt77eMdc3u8RMUhm914LSEz5j86JtDhdDBxHw8VTlpJR6qdUMTkeInC117Id9aO Nz+wzwU6mIglKJajeWzo3Z3fqAjw/tzISJt8HVLcKKn7cMsDvq+zre+wh/WtOGzsj4wM K00g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="EiZIWN3/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c10-20020a655a8a000000b004779a46d07csi39545489pgt.183.2023.01.05.15.07.41; Thu, 05 Jan 2023 15:07:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="EiZIWN3/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236273AbjAEXDp (ORCPT + 99 others); Thu, 5 Jan 2023 18:03:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236293AbjAEXDg (ORCPT ); Thu, 5 Jan 2023 18:03:36 -0500 Received: from mail-io1-xd2c.google.com (mail-io1-xd2c.google.com [IPv6:2607:f8b0:4864:20::d2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70D3D671B3 for ; Thu, 5 Jan 2023 15:03:35 -0800 (PST) Received: by mail-io1-xd2c.google.com with SMTP id y4so20414449iof.0 for ; Thu, 05 Jan 2023 15:03:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DIcjgq7EV1t47RYy2g4kttoekM/X5riyLaeE0K4reIU=; b=EiZIWN3/cZQxN8zkJGfY1CdZSallyOkhhJ7LnB6d5OXd1pFs+BjlMzijc5JFPAyDQc AdnjopK2UShOVUD+11NscnTezseDtQ0Ly8pVk+YVEcQpVAELfbXGg+BmauUKTtgc2SAh AdN9XLTCgFqBHJslPs32f9yqJ8jh+UsP/fK4U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DIcjgq7EV1t47RYy2g4kttoekM/X5riyLaeE0K4reIU=; b=OrkwOxuBWt6csiMk2inWlCSXe+dbjnS9nYkd2bMZhfKPRf+FL8eB3k/7LIHyocRNWd zck3WySW3+5jRs/SxkCDGKkEj9EmIgO9GvSHpG8DhtC+s9YOKcwoGszEdfQCQw/AFNw6 8SyaYS7CL4jKyMrNgc+U1zMmULCw4ej214MIoxYAXEc7mJbICNErma0N09VxUC7gtYri g3hCUgzCBKkRXN8Pq/9OkZfIGJrQwcnz19NqjgENA6VjpOcs0UESW0wtiUC416UAVlT6 PzrG7NQp5hSJiFPEdHI//zHF6TK5U0LhQr8iRWbPVZBZpQuQxRgq0UTbg62bYeworuG7 6c5g== X-Gm-Message-State: AFqh2krotjkk7IUWSw8SHCP+MPCAkhNaa+BwOAypZvePI2QlSgA5vb9b joQZRK/R1FHrNnWTs9QPfFpCJg== X-Received: by 2002:a6b:8f82:0:b0:6eb:da60:be0b with SMTP id r124-20020a6b8f82000000b006ebda60be0bmr35981898iod.4.1672959814789; Thu, 05 Jan 2023 15:03:34 -0800 (PST) Received: from localhost (30.23.70.34.bc.googleusercontent.com. [34.70.23.30]) by smtp.gmail.com with UTF8SMTPSA id h16-20020a056638339000b0035678e2e175sm11886577jav.50.2023.01.05.15.03.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 05 Jan 2023 15:03:34 -0800 (PST) From: Matthias Kaehlcke To: Greg Kroah-Hartman Cc: Johan Hovold , linux-usb@vger.kernel.org, Stefan Wahren , Alexander Stein , Icenowy Zheng , Douglas Anderson , stable@vger.kernel.org, linux-kernel@vger.kernel.org, Matthias Kaehlcke , Ravi Chandra Sadineni Subject: [PATCH 2/2] usb: misc: onboard_hub: Move 'attach' work to the driver Date: Thu, 5 Jan 2023 23:03:29 +0000 Message-Id: <20230105230119.2.I16b51f32db0c32f8a8532900bfe1c70c8572881a@changeid> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog In-Reply-To: <20230105230119.1.I75494ebee7027a50235ce4b1e930fa73a578fbe2@changeid> References: <20230105230119.1.I75494ebee7027a50235ce4b1e930fa73a578fbe2@changeid> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754225784451533034?= X-GMAIL-MSGID: =?utf-8?q?1754225784451533034?= Currently each onboard_hub platform device owns an 'attach' work, which is scheduled when the device probes. With this deadlocks have been reported on a Raspberry Pi 3 B+ [1], which has nested onboard hubs. The flow of the deadlock is something like this (with the onboard_hub driver built as a module) [2]: - USB root hub is instantiated - core hub driver calls onboard_hub_create_pdevs(), which creates the 'raw' platform device for the 1st level hub - 1st level hub is probed by the core hub driver - core hub driver calls onboard_hub_create_pdevs(), which creates the 'raw' platform device for the 2nd level hub - onboard_hub platform driver is registered - platform device for 1st level hub is probed - schedules 'attach' work - platform device for 2nd level hub is probed - schedules 'attach' work - onboard_hub USB driver is registered - device (and parent) lock of hub is held while the device is re-probed with the onboard_hub driver - 'attach' work (running in another thread) calls driver_attach(), which blocks on one of the hub device locks - onboard_hub_destroy_pdevs() is called by the core hub driver when one of the hubs is detached - destroying the pdevs invokes onboard_hub_remove(), which waits for the 'attach' work to complete - waits forever, since the 'attach' work can't acquire the device lock Use a single work struct for the driver instead of having a work struct per onboard hub platform driver instance. With that it isn't necessary to cancel the work in onboard_hub_remove(), which fixes the deadlock. The work is only cancelled when the driver is unloaded. [1] https://lore.kernel.org/r/d04bcc45-3471-4417-b30b-5cf9880d785d@i2se.com/ [2] https://lore.kernel.org/all/Y6OrGbqaMy2iVDWB@google.com/ Cc: stable@vger.kernel.org Fixes: 8bc063641ceb ("usb: misc: Add onboard_usb_hub driver") Link: https://lore.kernel.org/r/d04bcc45-3471-4417-b30b-5cf9880d785d@i2se.com/ Link: https://lore.kernel.org/all/Y6OrGbqaMy2iVDWB@google.com/ Reported-by: Stefan Wahren Signed-off-by: Matthias Kaehlcke --- drivers/usb/misc/onboard_usb_hub.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/drivers/usb/misc/onboard_usb_hub.c b/drivers/usb/misc/onboard_usb_hub.c index db0844b30bbd..8bc4deb465f0 100644 --- a/drivers/usb/misc/onboard_usb_hub.c +++ b/drivers/usb/misc/onboard_usb_hub.c @@ -27,7 +27,10 @@ #include "onboard_usb_hub.h" +static void onboard_hub_attach_usb_driver(struct work_struct *work); + static struct usb_device_driver onboard_hub_usbdev_driver; +static DECLARE_WORK(attach_usb_driver_work, onboard_hub_attach_usb_driver); /************************** Platform driver **************************/ @@ -45,7 +48,6 @@ struct onboard_hub { bool is_powered_on; bool going_away; struct list_head udev_list; - struct work_struct attach_usb_driver_work; struct mutex lock; }; @@ -270,9 +272,15 @@ static int onboard_hub_probe(struct platform_device *pdev) * * This needs to be done deferred to avoid self-deadlocks on systems * with nested onboard hubs. + * + * If the work is already running wait for it to complete, then + * schedule it again to ensure that the USB devices of this onboard + * hub instance are bound to the USB driver. */ - INIT_WORK(&hub->attach_usb_driver_work, onboard_hub_attach_usb_driver); - schedule_work(&hub->attach_usb_driver_work); + while (work_busy(&attach_usb_driver_work) & WORK_BUSY_RUNNING) + msleep(10); + + schedule_work(&attach_usb_driver_work); return 0; } @@ -285,9 +293,6 @@ static int onboard_hub_remove(struct platform_device *pdev) hub->going_away = true; - if (&hub->attach_usb_driver_work != current_work()) - cancel_work_sync(&hub->attach_usb_driver_work); - mutex_lock(&hub->lock); /* unbind the USB devices to avoid dangling references to this device */ @@ -449,6 +454,8 @@ static void __exit onboard_hub_exit(void) { usb_deregister_device_driver(&onboard_hub_usbdev_driver); platform_driver_unregister(&onboard_hub_driver); + + cancel_work_sync(&attach_usb_driver_work); } module_exit(onboard_hub_exit);