Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp35608pxj; Thu, 10 Jun 2021 14:03:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz2pjJ0t42Zrqf8M9kptgRgNWTJ82HrHsz8ihAXNE8sEJV4AiArFPW3CD0tfa3/HTrxDkUm X-Received: by 2002:a17:906:6d51:: with SMTP id a17mr410861ejt.543.1623358981337; Thu, 10 Jun 2021 14:03:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623358981; cv=none; d=google.com; s=arc-20160816; b=tyJH/FQclemXpNiW1iZ9vOV3DFUJZv0vgBI2zeLNJhY/o2zQN/XVbislkIiFl65f8l GoIDhvogPEmVwRfJIJSvgrsWK5zMIDy9iWuGQ+UHUf+fCCCtdplrA4d5+EWY1TKc4EEs 6UA/818xWjgNYV35yWoUuArB58xpXsMSA4NZv8WsQsN1Av2x995jW94LorB3bHoKbJxg fbEnPKT/RoN/ES2emeFI+Q7GqW2X7g9AEi+BRDZyGSwXoUjB0PyVPdGyXeJODgigHasF Is4mMp1/vp3PLTD3Tk/f7SsZU0haz289seL76sW1655+4qJT7uhgZmxrETK7kXaY3KBt SSKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=tEtPAjN/p7tQnsWWPwq6v9EFpRJ/fuc+yJotb4YTAjc=; b=lMoghjB9aWcxmopZASgB9vhkSQ2Wj8lJ0sHP1zJ4xhpwQJtiOqEIQ21/sKukUISCdM x0vCueIg8AxxjCXUxTx8uvzvTs/91xmy6pZD8b52pUhYwMM61kqkxlk4QMQHJFYpyB7F /7rLQSyP5Zo14rZVH7VRyRT7aTNNqgEIO78I6PkmuX5N+E2QxsGCmvJoF4U/8ZR/S3fk 6sZuJEG7y4bsxf84dn2w4KUULOUU63ENzCGdoHsNNM973aZaonoa3zGSLHY2fZEDiwxe NXncHlS0Gy5Roy+cCwu3Bit5dPbcbn2mmhaiupiTvoUBp4IzKhUe58USeTYGLS5Z/hLG 7lLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=qomFJvx9; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g3si3227922edv.12.2021.06.10.14.02.08; Thu, 10 Jun 2021 14:03:01 -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=@gmail.com header.s=20161025 header.b=qomFJvx9; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230001AbhFJVBx (ORCPT + 99 others); Thu, 10 Jun 2021 17:01:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229941AbhFJVBx (ORCPT ); Thu, 10 Jun 2021 17:01:53 -0400 Received: from mail-yb1-xb2b.google.com (mail-yb1-xb2b.google.com [IPv6:2607:f8b0:4864:20::b2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84F29C061574 for ; Thu, 10 Jun 2021 13:59:48 -0700 (PDT) Received: by mail-yb1-xb2b.google.com with SMTP id f84so1326899ybg.0 for ; Thu, 10 Jun 2021 13:59:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=tEtPAjN/p7tQnsWWPwq6v9EFpRJ/fuc+yJotb4YTAjc=; b=qomFJvx9UJC0xu27Ul3KQTbJEOwKFdgyjoW0cdXomo+d/e270zxj0EgBoZQfOndoQI ka8lNCAjmirgvDi/s1LjB5JZLVehEP04w8qWw0+U1eokppKzA0JX4j23ukKi65c7YEyB GMMgMH6PMhTniGk8oDkeYl3xL1oVa1xo4f7MB1VKh7si8P/DweN6hEiZDrW8yD0b31Ts Z1Ue9FdG+2MQrWEf++HuNyQoLZ2SJMw8CbAW5hWAg2IwLmanO3Hq5zt7474QtSPqrKZH orowwUgp0uhlYZYj98zn0UUfNxg+KpBP0eotrDOeXk9AFG7sRO+hTzLslOKuDyb5DkMV GZPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=tEtPAjN/p7tQnsWWPwq6v9EFpRJ/fuc+yJotb4YTAjc=; b=a3xJ8o96q/aBUszF2QP1myQgKfmCNtw0umqIfIFlTcV3kfI//EKnMwsm5WXuFp42Zc 8Ih+O9AOXspaf5hcjabGmVK29gxvE+0RqPT/PQJNwpYQ2y1jFqUfrVb6Cf8Z/vxWD3qu URY1uR5C+0aGRiSBvQBF/hc6lh2/p0KnT+j83zgJjn6kAqpyHagp0rNIPDHS9m2lRkGX 8636LNCaqRI9ocUAOIpjl+BM4H90jOSN3NmAgvE1jNwNaQ4YlxhBHv349yMhVoKlXk1a LvlM4mAe/QzygblPDnNkhtFTnQqRNSZQG6Uw7fzQA1vvtxsUH/9MHkmbL7Kd1yGk9neH dr5w== X-Gm-Message-State: AOAM531pLEHR13z61bxrAraWUKKyLiNxTlg4P7Xw2ODDi7kHAaNW/+AI 4qRtThZ4iGWtaApsfBNv9hjpUQ28R43gwV+pagA= X-Received: by 2002:a05:6902:114c:: with SMTP id p12mr1148905ybu.282.1623358787511; Thu, 10 Jun 2021 13:59:47 -0700 (PDT) MIME-Version: 1.0 References: <20210610181756.430-1-sonnysasaka@chromium.org> In-Reply-To: <20210610181756.430-1-sonnysasaka@chromium.org> From: Luiz Augusto von Dentz Date: Thu, 10 Jun 2021 13:59:36 -0700 Message-ID: Subject: Re: [PATCH BlueZ] Check whether device is connected before attaching EATT To: Sonny Sasaka Cc: "linux-bluetooth@vger.kernel.org" , Abhishek Pandit-Subedi Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Sonny, On Thu, Jun 10, 2021 at 11:20 AM Sonny Sasaka wrote: > > 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; Perhaps we should have this check earlier, also there seems to be something wrong with att_io then, if the device is no longer connected att_io shall have been unrefed as well. > -- > 2.31.0 > -- Luiz Augusto von Dentz