Received: by 2002:a05:7412:9c07:b0:fa:6e18:a558 with SMTP id lr7csp675714rdb; Sun, 28 Jan 2024 04:18:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IGEItN9oLe7iU+p24ST/Wmi8KfWSi6Zzi+zzIdVFBuk8rJapRPIeKEWZxUrjDbbksOFgOYO X-Received: by 2002:a05:6a20:a12:b0:19c:520c:c172 with SMTP id c18-20020a056a200a1200b0019c520cc172mr3960959pzb.26.1706444290517; Sun, 28 Jan 2024 04:18:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706444290; cv=pass; d=google.com; s=arc-20160816; b=FgykuihZCX+n6xIHNMfu0I9kUvM0nJPlnPYE+fnUs3UibVz/7njN5e41i3OxsXKU+A SzD9Zz5VCBADR39xFu63AGP9apzaY1O+cWf73Raws1QmpmYlscxtRVfF7S2Z+bh/pDOF 8mefafgplQb98C7TDyFo//NHf2N4OL2wNb5YlrrTXxFMIbmjFLqPSy3zMQ0JKvLJeRl+ EXiLvK9Y3bUg7uqrGU7QOjimfXBuASB6vOHe7w0heYMaUkkQ0uNSHVoYzL2EW2h2jvil wR2tCyfem0n3WvoHNBeMQ+lClnXNdTz1ichvNdVh0U3yPPEZtB+3BVBCtNLwO9/hcpRl 2OMw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=kbN1jMuq8FzYNa4x/7jBDwDdnxNxzVTrCOU+MQEUobw=; fh=YBH9Scr6+R73hd6ACeq63eDcEM8jCDH0X8+24AnAdH0=; b=ePe6JLAOUHO6mSdmnLGfPJx6jpUo7rF+AMvvM120Ss9r1P7z6AybgLb9HE3v8LYOW0 GwCp5o4zBGrtl3+VBplilsAPIDm/OirtlCkaT8RlsNwAiC9UwJxM2Cho5zD+NuFZEL+i DujYhnNwysMKKl/zxhfmpwmW6lC4l6venttk+xO1QiQRA73cvign7LFEHPy0X8sEAVXI Uogvm9+zffFJgMq4QhRvBQXglL55o/GW1oMih2P/2JYRAUwJryve0dNNEE7wh58WCGdT bS6QRDnTxKVktODE6Q8emXa5B9EHF+gYD0rH/zhwznCStPETZt/dAfN2usyu54AKizpj sZnA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=seo3Fbmi; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-bluetooth+bounces-1415-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-1415-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id z22-20020a637e16000000b005d8b59b8da3si2400368pgc.839.2024.01.28.04.18.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jan 2024 04:18:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-bluetooth+bounces-1415-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=seo3Fbmi; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-bluetooth+bounces-1415-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-1415-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id AEFA7281FA6 for ; Sun, 28 Jan 2024 12:18:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7C2B7208B4; Sun, 28 Jan 2024 12:18:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="seo3Fbmi" X-Original-To: linux-bluetooth@vger.kernel.org Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (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 2B67F20DC1 for ; Sun, 28 Jan 2024 12:18:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706444284; cv=none; b=qxf+gIyqI1X8W87uGXE1sdErmZ0O9CghBzGNc7EqsKOzSu/s2V/6ad1+ibtBgAQdga0WVjNiAJ00XWiRy/DzvDYsjN8ney0h1iFbHO7ddbaPqZ9TFU4lGheN5I4eyuyVdTDiyr+PAsP2l/8Du2oWA0DoFdxkX8M2UcKm/6AhaR0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706444284; c=relaxed/simple; bh=o+gnhH9bKTbZcPKWHQwzRTnm1rex1mIjSZu7lcAa7FM=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=Y4HW5IgppdgCvf1ATf18W4ycHPlBCZ5sB9wWtBynQaixQsLYjx3+F0D07zmz3s+AW0dZ7kQC+BDhhIJbyNnwIbrQPHpCqTbH2tc6L2cegH3TNJz6e7zcVuJ7Eke3F2eHX0PdeHrw9ebmVyx4InRMgNaa6vgLSfg1fQSy9eIal+M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=seo3Fbmi; arc=none smtp.client-ip=209.85.128.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-40ef0d6e5c2so13985e9.0 for ; Sun, 28 Jan 2024 04:18:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706444281; x=1707049081; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=kbN1jMuq8FzYNa4x/7jBDwDdnxNxzVTrCOU+MQEUobw=; b=seo3FbmifiEsIzAh4pozASPtjA4yonKnlEO7puWoO+veIis/MPeJKtSY/Zq016d37k WJJSE0Q+Y+V8DoctdkX5EvyzsQO78XcJ6uw770PAXnuT7ZouzTp9Cwi1H/BzTShHuGHR UGEDPjNGrRP9TfQOBYtZC0axz5vWf8VFeWqd2wF3k7mV0hDXiOA5tYrdcvTKTeYmZUkl lxesTUtKIVr/aed6sWKGyQAkahULze7JGii1vBsOlLz1ipxTCE6nqDKGDncrVpTRAeHy IKow4uwDVMlp4jI2qWwobwRxwwNz3zPqesKMFfbLexqh840MXZCYl7siDTn7WkA4Us2V caqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706444281; x=1707049081; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kbN1jMuq8FzYNa4x/7jBDwDdnxNxzVTrCOU+MQEUobw=; b=Oz9+SXFiPWKiemawptwNsCbirkgEOplx0t14p1TnQTWXFE5+kVcQV+aPtabIONu+RI G+z2ZR6OX1a+/PTsIZaP7hjn28tR/A6W9pHKoNGWZMHTURgmKj4FKJxwKr3BzYzk9Fli qD2lToEldl5jzaNQ2mfNrIlsepJffMhxool3n1ToJsNIXx1sWwQcOeYgBDcJnZ30iDpd FtxYueCwCFU7y/JOZwHtndjhWvoUY+el2r52cEZgc35QZA25vz4wkGMqUHphDK926jvF KzvWruCu8GHwUzq9vNPZDUWtQJ8mB3Eb+i1TVxMLFu6AdMxPKiSBMfhieJbZZ4YVtY4g MYNA== X-Gm-Message-State: AOJu0YwLHiG734q7GSq/lbnh79pM9moSiXVTJczMKIGTGKrbgc78EltC 60rgrO1dr2vDeISqnPdqZRYscrQ9b1cMRjGR3g0ok7K1nUa/z2trbrEpcv8FtqTg6Hp/wVmygEi +9z7rZG5bENcxmj5dq24JU20UkUBJxC0HkU/u X-Received: by 2002:a05:600c:510f:b0:40d:87df:92ca with SMTP id o15-20020a05600c510f00b0040d87df92camr393651wms.3.1706444281067; Sun, 28 Jan 2024 04:18:01 -0800 (PST) Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240126144120.Bluez.1.If74ccbca4d541c5f576765a3a78cb8923b5f85b1@changeid> In-Reply-To: From: Archie Pusaka Date: Sun, 28 Jan 2024 20:17:50 +0800 Message-ID: Subject: Re: [Bluez PATCH] Monitor: Remove handle before assigning To: Luiz Augusto von Dentz Cc: linux-bluetooth , Johan Hedberg , Marcel Holtmann , CrosBT Upstreaming , Archie Pusaka , Zhengping Jiang Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Luiz, On Sat, 27 Jan 2024 at 03:01, Luiz Augusto von Dentz wrote: > > Hi Archie, > > On Fri, Jan 26, 2024 at 1:42=E2=80=AFAM Archie Pusaka wrote: > > > > From: Archie Pusaka > > > > It is possible to have some handles not removed, for example the host > > may decide not to wait for disconnection complete event when it is > > suspending. In this case, when the peer device reconnected, we might > > have two of the same handle assigned and create problem down the road. > > > > This patch solves the issue by always removing any previous handles > > when assigning a new handle if they are the same. > > > > Reviewed-by: Zhengping Jiang > > > > --- > > > > monitor/packet.c | 50 +++++++++++++++++++++++++----------------------- > > 1 file changed, 26 insertions(+), 24 deletions(-) > > > > diff --git a/monitor/packet.c b/monitor/packet.c > > index 42e711cafa..b5dea6384a 100644 > > --- a/monitor/packet.c > > +++ b/monitor/packet.c > > @@ -189,11 +189,33 @@ static struct packet_conn_data *lookup_parent(uin= t16_t handle) > > return NULL; > > } > > > > +static void release_handle(uint16_t handle) > > +{ > > + int i; > > + > > + for (i =3D 0; i < MAX_CONN; i++) { > > + struct packet_conn_data *conn =3D &conn_list[i]; > > + > > + if (conn->handle =3D=3D handle) { > > + if (conn->destroy) > > + conn->destroy(conn->data); > > + > > + queue_destroy(conn->tx_q, free); > > + queue_destroy(conn->chan_q, free); > > + memset(conn, 0, sizeof(*conn)); > > + conn->handle =3D 0xffff; > > + break; > > + } > > + } > > +} > > We might as well return if we find out there is a packet_conn_data, > that way we don't need to do 2 lookups in a row. Do you mean to return the index, so we can immediately use the index in the assign_handle function? > > > static void assign_handle(uint16_t index, uint16_t handle, uint8_t typ= e, > > uint8_t *dst, uint8_t dst_type) > > { > > int i; > > > > + release_handle(handle); > > + > > for (i =3D 0; i < MAX_CONN; i++) { > > if (conn_list[i].handle =3D=3D 0xffff) { > > hci_devba(index, (bdaddr_t *)conn_list[i].src); > > @@ -225,26 +247,6 @@ static void assign_handle(uint16_t index, uint16_t= handle, uint8_t type, > > } > > } > > > > -static void release_handle(uint16_t handle) > > -{ > > - int i; > > - > > - for (i =3D 0; i < MAX_CONN; i++) { > > - struct packet_conn_data *conn =3D &conn_list[i]; > > - > > - if (conn->handle =3D=3D handle) { > > - if (conn->destroy) > > - conn->destroy(conn->data); > > - > > - queue_destroy(conn->tx_q, free); > > - queue_destroy(conn->chan_q, free); > > - memset(conn, 0, sizeof(*conn)); > > - conn->handle =3D 0xffff; > > - break; > > - } > > - } > > -} > > - > > struct packet_conn_data *packet_get_conn_data(uint16_t handle) > > { > > int i; > > @@ -10076,7 +10078,7 @@ static void conn_complete_evt(struct timeval *t= v, uint16_t index, > > const struct bt_hci_evt_conn_complete *evt =3D data; > > > > print_status(evt->status); > > - print_handle(evt->handle); > > + print_field("Handle: %d", le16_to_cpu(evt->handle)); > > print_bdaddr(evt->bdaddr); > > print_link_type(evt->link_type); > > print_enable("Encryption", evt->encr_mode); > > @@ -10648,7 +10650,7 @@ static void sync_conn_complete_evt(struct timev= al *tv, uint16_t index, > > const struct bt_hci_evt_sync_conn_complete *evt =3D data; > > > > print_status(evt->status); > > - print_handle(evt->handle); > > + print_field("Handle: %d", le16_to_cpu(evt->handle)); > > print_bdaddr(evt->bdaddr); > > print_link_type(evt->link_type); > > print_field("Transmission interval: 0x%2.2x", evt->tx_interval)= ; > > @@ -11077,7 +11079,7 @@ static void le_conn_complete_evt(struct timeval= *tv, uint16_t index, > > const struct bt_hci_evt_le_conn_complete *evt =3D data; > > > > print_status(evt->status); > > - print_handle(evt->handle); > > + print_field("Handle: %d", le16_to_cpu(evt->handle)); > > print_role(evt->role); > > print_peer_addr_type("Peer address type", evt->peer_addr_type); > > print_addr("Peer address", evt->peer_addr, evt->peer_addr_type)= ; > > @@ -11206,7 +11208,7 @@ static void le_enhanced_conn_complete_evt(struc= t timeval *tv, uint16_t index, > > const struct bt_hci_evt_le_enhanced_conn_complete *evt =3D data= ; > > > > print_status(evt->status); > > - print_handle(evt->handle); > > + print_field("Handle: %d", le16_to_cpu(evt->handle)); > > print_role(evt->role); > > print_peer_addr_type("Peer address type", evt->peer_addr_type); > > print_addr("Peer address", evt->peer_addr, evt->peer_addr_type)= ; > > Are these changes really intentional? Or perhaps we don't want to > attempt to resolve the address since these are the event that would > assign them in the first place? In that case I had these fixed > separately with a proper patch description. Yes, these are intentional. Otherwise, we would still print the previous (faulty) address as the printing happens before we release the handle. Also, we print the (correct) address anyway immediately on the next line. Do you still want this to be in a separate patch? > > > -- > > 2.43.0.429.g432eaa2c6b-goog > > > > > -- > Luiz Augusto von Dentz Thanks, Archie