From patchwork Thu Jan 16 03:36:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Douglas Anderson X-Patchwork-Id: 13941177 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AADD9E77188 for ; Thu, 16 Jan 2025 03:37:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=EHN8VwPtCZBq9Z4WoEOrhUz545+6IZdCnpT0dOgO/wY=; b=e7LcgBGMN2mVONvICpE8weT/NX wuHuimnHp7Ebf1AEfvoCDf3paQ6pfElR+/RidyJ/UgdSC87XPVJhypNgwFp+xbUsfjPnJJlmadnoe +XhA5UgtS4XdCwGLuA5FIKVKPA1I0KJZ3ncNhEjRfDC/eOS2wHTwKweYckZdx1wIj+z1tXfJy1lEr fH8QRuu8rjojwGawl1OfU3BwojrQvfZdSMUszvP5AkPkv/3OUIhc4f30+QJpsESGfjd1WqEDl7aEY C9OWa1gkS/H64fOrpHs6eHtkpkjgksh6MDRHkSDH4Iv2PM3//l111nbdTFQ0KwtRUKKIIfd5igyeD Fxa9uFNA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tYGhI-0000000Dk42-39bI; Thu, 16 Jan 2025 03:37:32 +0000 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tYGhG-0000000Dk2s-0blt for linux-mediatek@lists.infradead.org; Thu, 16 Jan 2025 03:37:31 +0000 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-215770613dbso4663845ad.2 for ; Wed, 15 Jan 2025 19:37:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1736998649; x=1737603449; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=EHN8VwPtCZBq9Z4WoEOrhUz545+6IZdCnpT0dOgO/wY=; b=gfrQWm7KsIzAgFihjFzOhtFo0VbRaPKKoEeWtM2DFP/Y0LPjXB81ME0ojqUw60aGbJ 0KgjF25RiZTtSNjMsny17ZJQ4vT6EvsowS8+MmlHl+Or+7vrIDXRFD4kI9aHE7DPhkGz PtsRt/NV/ZWCzNNfmEn/dBWeS+5L+w4KM3Xx8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736998649; x=1737603449; 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=EHN8VwPtCZBq9Z4WoEOrhUz545+6IZdCnpT0dOgO/wY=; b=G/Oe3JNV0yjuNOTGqpGVdFf2xI4xu1OftR3gQavJNaXpldV845W7AqcSiTsR4zhLpQ iDmjR6pA1CASQHyNF7PrEq12s0VJ3JGjjBP899Ay/tyKkSUgnND/ibVdFWSQ8pzKGh4P EmUuApWlUBmeILGqJvwlz8GZwX42YsT4Ofr+eww0CKUyrB9sSbuLBQ5Kn/bXzkBn1l2z im06rLIYDBpis8ulsy8P9lnYbFKjDuCc8T71/48z8WN+xMT3ENqQ7M6souo6oRXUeSTD lZGqd5eS7/bvpioeNsS9q1iczvROqdDYvUO8wwgBzPmItr2p5L07arVW7hYPkMfZsN4F 0Urg== X-Forwarded-Encrypted: i=1; AJvYcCVCtQzn3uu7hr9S7eZip6Tfy3uHifReEmM+53wPzB0QskoVt6jNio0FFznwJn+XHNvw/y9QpN+5O6KcI0y7wg==@lists.infradead.org X-Gm-Message-State: AOJu0YzTp1UQpaCGC6Ug3APJZ/BUPZBB3s2dekpCYHG+BsfVbcERwpcU dPtNq6td3NahJw64WfPqwU7agBG2gng07gQsfiplEDtm2DXOh8Dd788Uw7Iudw== X-Gm-Gg: ASbGncuJEV7AYlnHH8dsxevJ+0t6AiL743cZ9N+bzyAMlxxkq8ikAkwXgN8VZBL4Hy8 IiY3dwXWxAXoh39iAJRTFVkPUgBndPgu10XpSDJFc0MuZ946f7JW+wJQsbdABujcp4gvwd8qMMI 3YbDxFJSNNvEdF81YpUjiV3yYyySD3uQAUL0auG1j61Jf29Egzr76shzbjE7qwtGhX3DeYDnAxa qnc2fl31zCbqxUSZPlZpYZ90tmFTLvuQKqqK7RP884VByLCXqKEw8XHuCmasz6ej1xr3snsr/MP X-Google-Smtp-Source: AGHT+IGPHIlyquGny12YcL75NXc3XgLlu5eAhXbesmptiMTKimMfUbrOU/zhdc5d6pmMnPuAyOKk6g== X-Received: by 2002:a17:902:c951:b0:216:5b64:90f6 with SMTP id d9443c01a7336-21a83fd28e4mr487517675ad.45.1736998649039; Wed, 15 Jan 2025 19:37:29 -0800 (PST) Received: from dianders.sjc.corp.google.com ([2620:15c:9d:2:534a:ac09:3752:7758]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21a9f2339dasm87714485ad.177.2025.01.15.19.37.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jan 2025 19:37:28 -0800 (PST) From: Douglas Anderson To: Marcel Holtmann , Luiz Augusto von Dentz Cc: Douglas Anderson , AngeloGioacchino Del Regno , Chris Lu , Matthias Brugger , linux-arm-kernel@lists.infradead.org, linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org Subject: [PATCH 1/2] Bluetooth: btusb: mediatek: Add locks for usb_driver_claim_interface() Date: Wed, 15 Jan 2025 19:36:36 -0800 Message-ID: <20250115193636.1.If8b655b5c6877bd9a1136ba0f1cd61cc6a4b6e9c@changeid> X-Mailer: git-send-email 2.48.0.rc2.279.g1de40edade-goog MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250115_193730_213127_8BE3A3A0 X-CRM114-Status: GOOD ( 13.24 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org The documentation for usb_driver_claim_interface() says that "the device lock" is needed when the function is called from places other than probe(). This appears to be the lock for the USB interface device. The Mediatek btusb code gets called via this path: Workqueue: hci0 hci_power_on [bluetooth] Call trace: usb_driver_claim_interface btusb_mtk_claim_iso_intf btusb_mtk_setup hci_dev_open_sync hci_power_on process_scheduled_works worker_thread kthread With the above call trace the device lock hasn't been claimed. Claim it. Without this fix, we'd sometimes see the error "Failed to claim iso interface". Sometimes we'd even see worse errors, like a NULL pointer dereference (where `intf->dev.driver` was NULL) with a trace like: Call trace: usb_suspend_both usb_runtime_suspend __rpm_callback rpm_suspend pm_runtime_work process_scheduled_works Both errors appear to be fixed with the proper locking. Fixes: ceac1cb0259d ("Bluetooth: btusb: mediatek: add ISO data transmission functions") Signed-off-by: Douglas Anderson --- drivers/bluetooth/btusb.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index 279fe6c115fa..f69df515d668 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -2638,8 +2638,15 @@ static void btusb_mtk_claim_iso_intf(struct btusb_data *data) struct btmtk_data *btmtk_data = hci_get_priv(data->hdev); int err; + /* + * The function usb_driver_claim_interface() is documented to need + * locks held if it's not called from a probe routine. The code here + * is called from the hci_power_on workqueue, so grab the lock. + */ + device_lock(&btmtk_data->isopkt_intf->dev); err = usb_driver_claim_interface(&btusb_driver, btmtk_data->isopkt_intf, data); + device_unlock(&btmtk_data->isopkt_intf->dev); if (err < 0) { btmtk_data->isopkt_intf = NULL; bt_dev_err(data->hdev, "Failed to claim iso interface");