Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp735205pxj; Thu, 10 Jun 2021 11:20:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxk3dU6feBmWl/ftFjDDBySA+r5Img+RpE1ibRwM92cID3LyVZUhuTJCIcExCrVNAbURyoX X-Received: by 2002:a17:907:2bd9:: with SMTP id gv25mr819746ejc.157.1623349217255; Thu, 10 Jun 2021 11:20:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623349217; cv=none; d=google.com; s=arc-20160816; b=UuA4iuDmCk5gAE4E2brW+fASBKAsA7/Eiaw/cFmb5FTlxn8Ju861wUdC4d6oSw9G/G ZFri+uMxuBtNEWqrAPHsSVsenlKMAAmNhdeMtNYg0pi84UXH9MgS41SRxDIpO48lxSL5 snhST3VcVDiPQrk4g0SsgXqsfXe0w8MEPKu347gShThgMJkshBW38eokpjjVI4ApOUEJ 4S8PCWpRE1KoysLahkPk0GYB9saLUTVD43boy2PkOpiGqZcjMt3UYiJFCYAFCaFW2fLi sAG6n5V1wKtKHrIxIOHrXyxIO3XGGdR4sigjILWzSml2SAPC2slV13GLNPGH6JXDn77z ac6g== 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=gZVZzLDh5iZyA6/thJaaOvhV/DsBOubkxHItoDjTK4o=; b=wHh5TpQ0ICmYuMP5dnFjhlzbIzrMEoZM2JAJMZrEQ9CRKZjUUpldXeukvypPX0LVOc A3HAA7QUFK8f8RcYwaMAlYtoTn+aU9pt9ar2Ny9vk3/SmmbTW1k+VCBnC+E/2RFzwyXL Rs/Ng6yPoo6/jPOgXYdhNLkAFpoXGBBFKglRLZ6MIUPhcmUB5Q0ZR2hZMSw9DRi/yjXC WaqljRTuBGXSXUUiSHD2QT9SwLN/K/FwPmaf3pbsLyTLQE/7/xJ52xRsvwAcgphkHBK/ P7NwG5N7/x/HMwKSD+lv3qjG64R2L6eEEEn8nFC86wCBQiYrPej9rpeJaJfqWnsuhhp7 szLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=HfSyWM1X; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f22si2843855ejb.54.2021.06.10.11.19.27; Thu, 10 Jun 2021 11:20:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=HfSyWM1X; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-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 S230001AbhFJSUC (ORCPT + 99 others); Thu, 10 Jun 2021 14:20:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229963AbhFJSUB (ORCPT ); Thu, 10 Jun 2021 14:20:01 -0400 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 461C1C061760 for ; Thu, 10 Jun 2021 11:18:05 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id pi6-20020a17090b1e46b029015cec51d7cdso4358037pjb.5 for ; Thu, 10 Jun 2021 11:18:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=gZVZzLDh5iZyA6/thJaaOvhV/DsBOubkxHItoDjTK4o=; b=HfSyWM1XHJa7MPkysmpKm1mEQ2mrGAkMXX4boU2ZeCGFLFJbiF8XtRBaX+bM/SKHiV zB/0XNNa9z43E3z2V8btrwfUp3Rrb2SG4yxBd+RTm+/ZPGMHTf0i7GjggFQ3KzHYm+yg nVcrnD4xiNu2Z7y46f/ru7NaRhHz19GURDrcI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=gZVZzLDh5iZyA6/thJaaOvhV/DsBOubkxHItoDjTK4o=; b=aYQjKgwRVQ26mob2x3tGdBmEpG7bKREvP0lEXgpNKCPzD+j0qJR99Yj5PKcUVSdAeR UXBt3+7IHMW822kmufigd+jt8lmKcBAnPLfGhXIyVUdN/qaPqrykUT/2riJpOpMFfFQC sJGGfGkNbMNWjz6CKd9d7/Jhu0HwU5n8ABJ9oxBo9+cfVwtiwaNyWxQ/rUX1wXxD7HjB jCBaGfcolqzCbe5f9RqFTvWM9Sy4h7XwkVdXJg6cJFcENArzEiPeLEczJVeCBKDdkWZM o9qBu7f6IeSRhhEWKJ/vstC/Du7ebnHZxh9eymC6dKngMxBDSMIO9hWhFac3YqpeYslx +4lw== X-Gm-Message-State: AOAM532CYheo/OuWenkBJmeOb4OI8l174qInsXRZKc7WtkTxV2gxDc9P V++ZfO94z2lWnrot9Ryk4kIJ/YHBD4tjAg== X-Received: by 2002:a17:902:8645:b029:fd:25ef:3df7 with SMTP id y5-20020a1709028645b02900fd25ef3df7mr19868plt.48.1623349084541; Thu, 10 Jun 2021 11:18:04 -0700 (PDT) Received: from sonnysasaka-chrome.mtv.corp.google.com ([2620:15c:202:201:f41d:dcc:661a:484d]) by smtp.gmail.com with ESMTPSA id 4sm8526794pji.14.2021.06.10.11.18.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Jun 2021 11:18:03 -0700 (PDT) From: Sonny Sasaka To: linux-bluetooth@vger.kernel.org Cc: Sonny Sasaka , Abhishek Pandit-Subedi Subject: [PATCH BlueZ] Check whether device is connected before attaching EATT Date: Thu, 10 Jun 2021 11:17:56 -0700 Message-Id: <20210610181756.430-1-sonnysasaka@chromium.org> X-Mailer: git-send-email 2.31.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Due to a race condition, device_attach_att() may be reached when the dev is actually already disconnected but dev->att is not yet cleaned up by att_disconnect_cb(). Therefore we should check whether the dev is connected before attaching EATT. The race condition is discovered at rare cases when there is a very quick reconnection after disconnection so that device_attach_att() is called even before att_disconnect_cb(). This case is more probable to happen when the host goes to suspend right before dev_disconnected() is invoked and when the host is woken up by a reconnection the reconnection is processed earlier than the cleanup in att_disconnect_cb(). Reviewed-by: Abhishek Pandit-Subedi --- src/device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/device.c b/src/device.c index 65838f59f..319a929ee 100644 --- a/src/device.c +++ b/src/device.c @@ -5306,7 +5306,7 @@ bool device_attach_att(struct btd_device *dev, GIOChannel *io) return false; } - if (dev->att) { + if (btd_device_is_connected(dev) && dev->att) { if (btd_opts.gatt_channels == bt_att_get_channels(dev->att)) { DBG("EATT channel limit reached"); return false; -- 2.31.0