Received: by 2002:ab2:2441:0:b0:1f3:1f8c:d0c6 with SMTP id k1csp12865lqe; Wed, 3 Apr 2024 19:46:08 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUX0LdA/QJqnSdmXZfby9pK9jERQnwKQqiA3yav+cP/Jl3yItixeQLURIgtUkzfD/xW2McInuLEn2BiO70uFqV3Zrxf3wHbHSb06L0lAA== X-Google-Smtp-Source: AGHT+IE56ZEwxVdCNWuuBGeUYpgP7mbdj4ymxOOhG2t8K54B84R0kRDbuFFnsP9huxnJDuk9ml/D X-Received: by 2002:a17:902:c1c6:b0:1e2:a9de:43f1 with SMTP id c6-20020a170902c1c600b001e2a9de43f1mr808028plc.20.1712198768495; Wed, 03 Apr 2024 19:46:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712198768; cv=pass; d=google.com; s=arc-20160816; b=xcrJJXo7Y1hXAweHo7VbDZPYOkPyItPuxBUp/rRZEJGStVoj3CSDasG5fQ0uBq76MS VqhIrqhwbJSSqhButiij8+FTf9RhZDEFPBWc+dqLFrMvOVxcvcoXQ7yZCUl91/ozt+M0 Y0eKk5ckgIWiTbCPYtxgr3WcShtzkpw9aitcEyIwEecvZl1qx6qhrmDlkaby4nQBtSPM pqnNb5GsKHyS4hnkHTm0O/jYcI2DGdagKz34m6C5/adRqkwSyW/VeYnY6S3BzvUQaDJs 6ZPKWoXiomqIka0vzKxdFbrleRocj4MSHR9glQr4ucKu8QWQm1BfhHZ10FWaStPg+lcV JBHg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=PXeFRW6/7y6+A0LTRNjTlTWuylfSEcRX+XVrjnQMJOE=; fh=QvLe9xSQ7zlfGAr+dqnfPkt50uL0YuAdQlMdBJrVoy4=; b=fpF1/jgmcNzM3DhnHgWmP9O42IRj3N2wmOEG6KrfXIoWRTk8VLi6YEWm3qePInqO9Q gywTVQy/H2O9hwx5agm4QmtVu/XTevE8Cq5f+aqsKkhhH+oSJC64kriD4n/NVEFqF3sK kMqT4mrUNxSSNugWYx5PRtYYZv3G372B1bVtXh89UelylJ7hl/LV9flutctcREaQi7nf cZRiigbRPd6PjSy5R3VojcpxVqlgvJL1/RwSOBz7hO9+98/QdjUq4FBOJhdBS5SUvOpI /NS2Oq1Z0IqiZiFoaW3MFYw6TFH2DyyexDQNQn/SEBVhgsWg9b9/VKdQybWK2ASt+3YQ bXyw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=J2RIXBty; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-bluetooth+bounces-3185-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-3185-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id q1-20020a170902a3c100b001dda34be362si13434665plb.11.2024.04.03.19.46.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 19:46:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth+bounces-3185-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=J2RIXBty; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-bluetooth+bounces-3185-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-3185-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id A0736B210B0 for ; Thu, 4 Apr 2024 02:46:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AD0591CA9F; Thu, 4 Apr 2024 02:45:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="J2RIXBty" X-Original-To: linux-bluetooth@vger.kernel.org Received: from mail-oa1-f68.google.com (mail-oa1-f68.google.com [209.85.160.68]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A011F1C6B8 for ; Thu, 4 Apr 2024 02:45:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.68 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712198759; cv=none; b=nT62I11toJPVWRqxijlTMg4jC1TKlLhxMedJu0v2tNsLhY71KAo6E7ac8plUNnSPsTVyc8xWioz6v/U3636BGgRjkzdMAE37KphCmh2jtKUuFhWL1tUeJigk7T8KADeaPpEKJzuGCt9Bew0qWtHpDFY6F9vI3nFGXX2g7SQL80o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712198759; c=relaxed/simple; bh=6dKcgsSsKRcR2zluwdPeBCuYg1/K5k4r3QaqVHsTPK4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZasNbNp7TKEWqFuiWPoC8ANt0hSmW+EA+OOs9R1YJiGLRyMhNphSht01tOw+OGlJSBYL5OWX2+txHBOB2nSfZhXLhCU9JzMCR8JQMfO4SfSkJxowBn1jFrL5p+gK5T5w+ihqznP83NIKnywGj1YMOkR8ReWp9eaIifix/HDK3B0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=J2RIXBty; arc=none smtp.client-ip=209.85.160.68 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-oa1-f68.google.com with SMTP id 586e51a60fabf-22e7560b94aso275982fac.2 for ; Wed, 03 Apr 2024 19:45:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712198756; x=1712803556; darn=vger.kernel.org; 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=PXeFRW6/7y6+A0LTRNjTlTWuylfSEcRX+XVrjnQMJOE=; b=J2RIXBtyKVs8OZST+sr6aaOQjlvaFU33mlPStHiCvcROPgjLS287xCY7Yxif/zKK8B rCPBV0vYB8eHgS8D5pio5BzBGXSgPzA/ZbmB4HhPW9aq2eWDa7mQaCW1XkBUF/3Jb14I fhCIgyRUnenA5hbSJUg0Q7Cfe/zu0jCXvHNN9NWia/JSQiVXUFs2bUK0UoMsVku4OWkV vIXnPjxryly5w7AE6SEiqwCemSwoLRUkgjISS0GYTiPeoeQmamSXEBRF3boYbrqIlgTu hGXKPqT03PTxsOxfF5ZO9IuwaqD58rnwOL25rINj4MQSc76lxvc4boy/xqbqYzhrhOMn Zs4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712198756; x=1712803556; 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=PXeFRW6/7y6+A0LTRNjTlTWuylfSEcRX+XVrjnQMJOE=; b=EHaP1f6cXctH21/mOw9P7pEJx69SHzTvWi+0OPaAcVNgm2x5hs3M90fkzRtVQmjalO eB/bU+jBImnAXKsm4alDnonzSphkONX5v+t5vzy8BFP8CLtfVb0zZ9Gtqqq0t+yYFdWl u929cc7e3rMqCl0lDvDg5k5Yq7d6qhDAgor7dfB3PbkSbl0SAEHw+SfIO1qbmFphyjs0 V+Pzk7ZuKWhSab1VmDBOTDpnrVaFQSXs1JDhkLDLqGs6zkzwW85wVEbZHT31jmRvUOWO BKkJe5clqiEEyA2V5VySjvBZyYI2abBTtLaRUNCunxuoKxUjVJr0EN99RImte7tL5izM 7qgQ== X-Gm-Message-State: AOJu0Yw02Shaaw/suXpvyIX2ImeOx0kst4b0DBBwe3Gj0vx57VNMd0eg eR+KXChMxCAHGPnYd6fqV2Qj76NtNuS0aqlm9Z4kux9/x2vGia9gTTKekOdJMhA8qBZE X-Received: by 2002:a05:6870:1391:b0:22e:a4ab:68cc with SMTP id 17-20020a056870139100b0022ea4ab68ccmr1131651oas.25.1712198755944; Wed, 03 Apr 2024 19:45:55 -0700 (PDT) Received: from angua.lan ([2600:3c0a:e002:7f00::1001]) by smtp.gmail.com with ESMTPSA id g8-20020aa79dc8000000b006e56da42e24sm12512869pfq.158.2024.04.03.19.45.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 19:45:55 -0700 (PDT) From: Dimitris To: linux-bluetooth@vger.kernel.org Cc: Dimitris Subject: [PATCH BlueZ 1/1] Refactor btd_device_is_connected Date: Wed, 3 Apr 2024 19:45:21 -0700 Message-ID: <20240404024521.120349-2-dimitris.on.linux@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240404024521.120349-1-dimitris.on.linux@gmail.com> References: <20240403205252.71978-1-dimitris.on.linux@gmail.com> <20240404024521.120349-1-dimitris.on.linux@gmail.com> Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Splitting the service state test out of btd_device_is_connected and using the state-specific test from adapter_remove_connection. This intends to fix a busy loop that happens when BT is disabled from userspace with e.g. "rfkill block bluetooth". --- src/adapter.c | 2 +- src/device.c | 7 ++++++- src/device.h | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/adapter.c b/src/adapter.c index 4bcc464de..0b7aab4b5 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -7486,7 +7486,7 @@ static void adapter_remove_connection(struct btd_adapter *adapter, device_cancel_authentication(device, TRUE); /* If another bearer is still connected */ - if (btd_device_is_connected(device)) + if (btd_device_state_is_connected(device)) return; adapter->connections = g_slist_remove(adapter->connections, device); diff --git a/src/device.c b/src/device.c index 5e74633c6..123b1b796 100644 --- a/src/device.c +++ b/src/device.c @@ -3273,13 +3273,18 @@ uint8_t btd_device_get_bdaddr_type(struct btd_device *dev) bool btd_device_is_connected(struct btd_device *dev) { - if (dev->bredr_state.connected || dev->le_state.connected) + if (btd_device_state_is_connected(dev)) return true; return find_service_with_state(dev->services, BTD_SERVICE_STATE_CONNECTED); } +bool btd_device_state_is_connected(struct btd_device *dev) +{ + return dev->bredr_state.connected || dev->le_state.connected; +} + static void clear_temporary_timer(struct btd_device *dev) { if (dev->temporary_timer) { diff --git a/src/device.h b/src/device.h index d4e70b7ef..e3191f2a4 100644 --- a/src/device.h +++ b/src/device.h @@ -104,6 +104,7 @@ void device_set_rssi(struct btd_device *device, int8_t rssi); void device_set_tx_power(struct btd_device *device, int8_t tx_power); void device_set_flags(struct btd_device *device, uint8_t flags); bool btd_device_is_connected(struct btd_device *dev); +bool btd_device_state_is_connected(struct btd_device *dev); uint8_t btd_device_get_bdaddr_type(struct btd_device *dev); bool device_is_retrying(struct btd_device *device); void device_bonding_complete(struct btd_device *device, uint8_t bdaddr_type, -- 2.44.0