Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2532383ybt; Mon, 22 Jun 2020 00:14:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwr/y0UiprKL13I0iihrL3W9GzE7L42lS/MN5/i8E7lY0BEN4SYeFQnwKXyykuPHOg0/mtQ X-Received: by 2002:a17:906:8294:: with SMTP id h20mr13961617ejx.17.1592810079792; Mon, 22 Jun 2020 00:14:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592810079; cv=none; d=google.com; s=arc-20160816; b=VoDaVfiqACXOrbyt3DVYE7In0vOqqip3iQuNZYl5dOYVAWm15WN8H9gc6YSvNA6XSm TD7xjFs2BwB/arbc1bUY2LCbFKvAw4/MseLjc8hEm80oK3eyZK8XhITPUkBT+pN0HsOW JWHvz+HHMmJeEIKIuvgFhmljbGmJRUjGf5/dkYNBnXjsOkSOU/aqRgFM2CNgvsUuYoGA us3mvW5HdSCQn9y8wWxs1Hu+r3GmMQk7xXMIxhkgYF8ByAWBiFkZQM3FZFs01CIMAu+p bowXUaVqvNvIcUvHUcB2mztcjm/eUOfLDWwl8VMKQkq7iSfTUc0zJ3oMGq9Mpwu7I+gu iH3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version; bh=pmri5F4BGRmCLMbLromfBdruM2c+A2EjDDsj1RdU6Ug=; b=VEUZFevEQu1KUAuDp4b4wY4b07OikWAeO8Kuybh4kwLXgp1U/dxDQh+beno+4mk3bZ UXzvgSV3tGt6Tzf0YjqkF4FpG8T3w+nUdO3Bs6ZaLu/IVd7S7k+6Hs3x8V/vjJO1IKZl 3z1IgtZjAuXz747bP1+RpK4WWBsptTB2xRibuxzuIFXBv/9ht7gag9ss3tVG51Dy2YXe bm4k03afk7jR1mjslAcRUCTaleumTpfQls5HHv8yO8FOgtJeb/0EhFXNyXGVbRYLej2U lDEE2rD2j7kFxTwAk+Lv/BP8/WnIjOuaQpAmHGnIxadIBQoSpHa+aF2KwiDjBKJTQcBQ q0Pw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p20si4050500ejr.120.2020.06.22.00.14.15; Mon, 22 Jun 2020 00:14:39 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726924AbgFVHOI convert rfc822-to-8bit (ORCPT + 99 others); Mon, 22 Jun 2020 03:14:08 -0400 Received: from coyote.holtmann.net ([212.227.132.17]:57530 "EHLO mail.holtmann.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726850AbgFVHOI (ORCPT ); Mon, 22 Jun 2020 03:14:08 -0400 Received: from marcel-macpro.fritz.box (p5b3d2638.dip0.t-ipconnect.de [91.61.38.56]) by mail.holtmann.org (Postfix) with ESMTPSA id 8E349CED25; Mon, 22 Jun 2020 09:23:58 +0200 (CEST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.80.23.2.2\)) Subject: Re: [PATCH v1] bluetooth: use configured params for ext adv From: Marcel Holtmann In-Reply-To: Date: Mon, 22 Jun 2020 09:14:05 +0200 Cc: Alain Michaud , BlueZ , Abhishek Pandit-Subedi , Daniel Winkler Content-Transfer-Encoding: 8BIT Message-Id: <7EE6323C-B4C7-471F-A831-F33995E6B662@holtmann.org> References: <20200618210659.142284-1-alainm@chromium.org> To: Alain Michaud X-Mailer: Apple Mail (2.3608.80.23.2.2) Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Alain, >>> diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c >>> index 29decd7e8051..08818b9bf89f 100644 >>> --- a/net/bluetooth/hci_request.c >>> +++ b/net/bluetooth/hci_request.c >>> @@ -1799,8 +1799,9 @@ int __hci_req_setup_ext_adv_instance(struct hci_request *req, u8 instance) >>> int err; >>> struct adv_info *adv_instance; >>> bool secondary_adv; >>> - /* In ext adv set param interval is 3 octets */ >>> - const u8 adv_interval[3] = { 0x00, 0x08, 0x00 }; >>> + /* In ext adv set param interval is 3 octets in le format */ >>> + const __le32 min_adv_interval = cpu_to_le32(hdev->le_adv_min_interval); >>> + const __le32 max_adv_interval = cpu_to_le32(hdev->le_adv_max_interval); >> >> Scrap the const here. > > I'd like to understand why it isn't prefered to use const when you > don't intend to modify it in the code. does the const make a difference for integer values? For me this the difference between adding value and extra noise. >> >> >> And it is wrong since your hdev->le_adv_{min,max}_interval is actually __u16. So that first needs to be extended to a __u16 value. > > The macro actually leads to a function call that has a __u32 as a > parameter so the __u16 gets upcasted to a __u32 already. That is true, but lets be clean and use a proper storage size in the first place. Eventually we want to use the larger intervals at some point. And then you end up hunting that root cause for a complete day ;) >> >> >> That said, if we have this in the Load Default System Configuration list, we should extended it to __le32 there as well. > > I agree, this means the range of default system configuration may not > be sufficient to accept all possible values that the newer command > supports, although I think this is a separate issue from what this > patch is trying to solve. Separate issue and separate patch, but needs to be addressed. >> >> >>> if (instance > 0) { >>> adv_instance = hci_find_adv_instance(hdev, instance); >>> @@ -1833,8 +1834,9 @@ int __hci_req_setup_ext_adv_instance(struct hci_request *req, u8 instance) >>> >>> memset(&cp, 0, sizeof(cp)); >>> >>> - memcpy(cp.min_interval, adv_interval, sizeof(cp.min_interval)); >>> - memcpy(cp.max_interval, adv_interval, sizeof(cp.max_interval)); >>> + /* take least significant 3 bytes */ >>> + memcpy(cp.min_interval, &min_adv_interval, sizeof(cp.min_interval)); >>> + memcpy(cp.max_interval, &max_adv_interval, sizeof(cp.max_interval)); >> >> This is dangerous and I think it actually break in case of unaligned access platforms. > > Since it is in le format already and the 3 bytes from the cmd struct > are raw, I'm not sure how this can be dangerous. It effectively > yields the exact same results as your suggestions below. It is only fine on architectures that do the unaligned access correctly. In case they don’t this will result in a funny value. Regards Marcel