Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp3285880pxb; Thu, 10 Feb 2022 17:27:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJx057g7D+C0DVWUnRZORfpvyr9fRKsYUN+ZXi4I9dpBcdvGRAal3aAAI4NLOhNdmI9HN1sc X-Received: by 2002:a05:6a00:2349:: with SMTP id j9mr9004242pfj.34.1644542834081; Thu, 10 Feb 2022 17:27:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644542834; cv=none; d=google.com; s=arc-20160816; b=EuizfWjPvuxILbVEwnZfwOmQumjfGVnE0g0Zq8ztZzAIbH6q0rLGuyYtGi7cIp3yxE nF67YLUtsLs3k/b4FkYJfiyImpHfTe4nYwDZtvn71U44Z1u0++ewsIk084eA7zjX1o5N mcLhP3p9gYcIeYWemp81SAeyxI5Rf8FoCjQXtp/ml0vokjpNyNrqcMI4pwIcSV+vDaH9 h2Fv7N3CrlWonYCHDk2WwTxYY0nw7AmnSaiT5mvZmFssly1aHP+f0wlIvJffMa2/MMjl 8ZFYpJLwxUmWJ1CtqLid5Mc40bUhdYy/dw7hQN1c9fQJ0p8N9p7/QkNQGZWOoeCNIEX1 sRFA== 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:to:from :dkim-signature; bh=n36R9yD2ssxZU4+7XWpdBp0aWbFHEPEK1qICocMBxhw=; b=J/U3FTHG3hY/5XXWNjKJZaNb66tV8NU/Gpo0pmfZC1wRkoVDAjpmp6aGenkNw6rQ2d d2Erf553vnrmOni/8FQKXO6Ayf7tNRJmNiQ2yX1+amXMEV7GtUyDAwuVHKWLnPyStIMP +04/ZW9nc9I33rmyFA7DB5t7rxd3sLLY40n+Di8NpLDLpaApSQkg2VS3w6+cQimtyHgk 5nlc5mYX4oQKciKGNAAYEymDr42EylxMbIuZd1Zsiw2EgHhviNnqSAHjuu71N1tqBXun UlfN1+GADy/0xqp9R5euIOAh5kvPt9WOsQ0f3dG3FVswHypJFnTA7yRs2dY7tj8Xg3MN BeHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="pTRm/Jrj"; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k10si21765208pff.336.2022.02.10.17.26.45; Thu, 10 Feb 2022 17:27:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-bluetooth-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=@gmail.com header.s=20210112 header.b="pTRm/Jrj"; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346276AbiBKASp (ORCPT + 99 others); Thu, 10 Feb 2022 19:18:45 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:51876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242748AbiBKASo (ORCPT ); Thu, 10 Feb 2022 19:18:44 -0500 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E451558E for ; Thu, 10 Feb 2022 16:18:45 -0800 (PST) Received: by mail-pf1-x435.google.com with SMTP id u16so7532554pfg.3 for ; Thu, 10 Feb 2022 16:18:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=n36R9yD2ssxZU4+7XWpdBp0aWbFHEPEK1qICocMBxhw=; b=pTRm/JrjyDxk9PGHI+TSJ3+uaOfMFSbsdrvv+VByu4fMDfVgr/jS0sw5E3lc6INGye SrFCatTfXfv0iNzCSJjjAWgMYtrEuy5RBWPl5HfNF/3jFSiF9R7ntrRwOFoQ9K3H8fpU jrXeuPajgJJQqr+wU/ARKOzpJI7kVswD9uCifdkleFrZ/i0fLzGAKX8mKAkhe26b20Rf GZ7ddL4Q9Im/KwmnNFJPvYaPLO7ZwNp+wOkcNqKpzRBqVhmbKxG2GDhfOE/WJZaxvhVy 8Rky0tMWU9EO3EtIQAZfXmQ2YkZQdldTP9fMJ9WHhB9Tgg0cEDlFmSeNAxyEq5j+NEr7 ShIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=n36R9yD2ssxZU4+7XWpdBp0aWbFHEPEK1qICocMBxhw=; b=m4z5h/cnkazSDFSCm7sWSw6Gmhufg4nZX374qXToNM4k3+FX8DPt88qHUEJnuDYZT9 BrfTmv48VFhHrP1AYWfIPEmxZwxEuZ+7ekzPrnXyqhzQANLRstxCcyG2d8TzaqwHiQTs X7tFaT85WC/rzqxNgkEBChG/apKeBmvDTYxsr+nakvjF5NVU01GjAspzb8KSFoRSM8cy TftU5Tsgbdf3ybXHw+e1q1iVwZqwc2UUhf+dqhkJXaUXIArNQ1SKRevMJAlpzvPRf1Nx pqoxQdfvG6Zz13BE5Vz5ipHRKtPnybS/yymqtVr/Mz1RDQAU2Sctjk+AzvnOa0QlVHF4 pXig== X-Gm-Message-State: AOAM5319M+l1pg3ejOZgVQR9fhkbwd8cYpdflfCpGnQdizVhdKGT6S4u Cfnq00mS35FI2dACBuJRf+LPQVuwPpY= X-Received: by 2002:a63:8a43:: with SMTP id y64mr1565903pgd.350.1644538724621; Thu, 10 Feb 2022 16:18:44 -0800 (PST) Received: from han1-NUC8i7BEH.hsd1.or.comcast.net ([2601:1c0:6a01:d830::169b]) by smtp.gmail.com with ESMTPSA id n37sm8328321pgl.48.2022.02.10.16.18.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 16:18:44 -0800 (PST) From: Tedd Ho-Jeong An To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH 4/4] device: Fix crash when removing device Date: Thu, 10 Feb 2022 16:18:40 -0800 Message-Id: <20220211001840.22566-4-hj.tedd.an@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220211001840.22566-1-hj.tedd.an@gmail.com> References: <20220211001840.22566-1-hj.tedd.an@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz Calling btd_adapter_remove_device from device_remove_connection can cause a crash, so instead of removing it immediatelly this set a the temporary timeout to 0. Fixes: https://github.com/bluez/bluez/issues/290 --- src/device.c | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/device.c b/src/device.c index 6a7bdd207..52e2399dd 100644 --- a/src/device.c +++ b/src/device.c @@ -3200,6 +3200,28 @@ void device_add_connection(struct btd_device *dev, uint8_t bdaddr_type) "Connected"); } +static bool device_disappeared(gpointer user_data) +{ + struct btd_device *dev = user_data; + + dev->temporary_timer = 0; + + btd_adapter_remove_device(dev->adapter, dev); + + return FALSE; +} + +static void set_temporary_timer(struct btd_device *dev, unsigned int timeout) +{ + clear_temporary_timer(dev); + + if (!timeout) + return; + + dev->temporary_timer = timeout_add_seconds(timeout, device_disappeared, + dev, NULL); +} + void device_remove_connection(struct btd_device *device, uint8_t bdaddr_type) { struct bearer_state *state = get_state(device, bdaddr_type); @@ -3285,7 +3307,7 @@ void device_remove_connection(struct btd_device *device, uint8_t bdaddr_type) DEVICE_INTERFACE, "Connected"); if (remove_device) - btd_adapter_remove_device(device->adapter, device); + set_temporary_timer(device, 0); } guint device_add_disconnect_watch(struct btd_device *device, @@ -4590,28 +4612,6 @@ void device_set_le_support(struct btd_device *device, uint8_t bdaddr_type) store_device_info(device); } -static bool device_disappeared(gpointer user_data) -{ - struct btd_device *dev = user_data; - - dev->temporary_timer = 0; - - btd_adapter_remove_device(dev->adapter, dev); - - return FALSE; -} - -static void set_temporary_timer(struct btd_device *dev, unsigned int timeout) -{ - clear_temporary_timer(dev); - - if (!timeout) - return; - - dev->temporary_timer = timeout_add_seconds(timeout, device_disappeared, - dev, NULL); -} - void device_update_last_seen(struct btd_device *device, uint8_t bdaddr_type) { if (bdaddr_type == BDADDR_BREDR) -- 2.25.1