Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp5373038pxb; Sun, 13 Feb 2022 18:58:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJzgNRTdZWN973yiQ0hmRd81sXhz2KlEK/ywALoQGHL1152Tesd1AhvxMDGB63aD5DGV6sjQ X-Received: by 2002:a17:907:1c10:: with SMTP id nc16mr9644378ejc.342.1644807539628; Sun, 13 Feb 2022 18:58:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1644807539; cv=pass; d=google.com; s=arc-20160816; b=qpUtDUh7t5xIg39932TtJ+SvMKydZ/y9bSAshGu0MJsBRlxlrfR1cthXFIROtHWl5F GxeScZW57jjJsUlCuBN3G07phmyhi05YWGyD8HI+e0TLKBdfv7S/6niKSxOlCRWRZ5Ww MxPHol1uLVuE43oqo1GQdEd8ii27mlPKcJvikMdh8Si6cxe61qhSIuRGQslpf6Mh9Qpg oc9MQSgBi8l/U0cfblWSI50Bs9Z7niNqO5ue6u3GjRingpolIY3Tx4w8VcfkFs8UuErB kF3LWetyWNmktTKbyNEAtD0I5aK4XitcgA1wfPAmfV4K02xwqzHAlDs4n9nQyHwBCoko t5OA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding:subject :from:cc:to:content-language:user-agent:date:message-id :dkim-signature; bh=iRi1MF4CZjlLaJIVvAuNydkH/V+l9HuJ6juhL0I8kQE=; b=hv84melzdDYQowYnUzRdIzCexwlDjUpjwgJXbkfGwAm2ocPl0GvoZsbMOON1wdsmGp /cFiONrq241OUVtIh64eQ5H/8bfw+Hd8jUoUbFx1RnykkpSeDCroFhxeGAZfBpoCIdQU tHwdyniXdNL2MDvFtcy/Tah5MeFE/y5I2mPk0qo+IzbhKiwcB81B5FAE67/D4CvtOJ3t 6TQCMTEkfezUjBUrp8b7tguhPjU3R1TmcC4EkTqf+KKC+gUBMqLtmG8VLJKDyB5K/J0H RHAu0c5aeALkpOOTKCnvqB0PfujenIyYtsM09qG7w+7yjQHacqTK1GRS/c9lKctZpPCz S5Bw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ugent.be header.s=selector1 header.b=CZxPJfOe; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ugent.be Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gb41si27740287ejc.425.2022.02.13.18.58.37; Sun, 13 Feb 2022 18:58:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ugent.be header.s=selector1 header.b=CZxPJfOe; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ugent.be Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232419AbiBLXOl (ORCPT + 99 others); Sat, 12 Feb 2022 18:14:41 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:39940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232399AbiBLXOj (ORCPT ); Sat, 12 Feb 2022 18:14:39 -0500 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-eopbgr70094.outbound.protection.outlook.com [40.107.7.94]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49FF95F8CF; Sat, 12 Feb 2022 15:14:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mDFOIjR2O7DEYj3qzOdhF6mYeuHrCKWxKkFU0h4UWgDEK1WTVbHNlJW8km3b7O2NyHcNIH2cS5Uy+B82T7gQBfozEDZMlSEnikJGad0ivfwZp4Xx8u1YrP07dhUzzY6ZkzXMJmQxZQkFvX9jBOiQWc/Ig9GZXZd1y6THCHeC5s9GhZ/TP7DHRD4x/zSQZMHDE3esSv8Ie7KzwJg7vFbsxO8oKGydodnb9u25ZCjR/9p231jIfK05263M6KvZV5cw2WOk26phJzDjpKwm9GP3eLPUhIALYTT3O65dUCap/Dw+ad1NnkGvBhtJyXrOtflRwQ/CZGMu9wAUTiLh96NKdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=iRi1MF4CZjlLaJIVvAuNydkH/V+l9HuJ6juhL0I8kQE=; b=Q/0mje9ldCF1VtW+DSiuEvQAe0y8elgbFedlDKPTS2XnUeKz1Zpp9SxX4dVpjbqaKUbnax2Cw3EExwiQZNXkGOna1Tfr6ToDHvKEp9vKDEW4w4Genb1E0Bgq4jPehsFgByBfQ5vILz8eaZiAaoYC3nHCWxgT/rpkQHeeQBa2883Uk+9WqKnPomV9q+LBrEwhzWgM+K9gfv6mR2mKs2W6ZILvgtmHpoEwu4x2+B/1+Il1nztvxsaF+hJsm0xdmMxQ5Es8s1BlIKw0i8Erf+jPViVvmzDLSMhW3zCZFbH8Bmtmb39U+6k5IQqB8+TMe/t2WaxjMQFIk0X8f6wK3NFIDg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ugent.be; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iRi1MF4CZjlLaJIVvAuNydkH/V+l9HuJ6juhL0I8kQE=; b=CZxPJfOeGPVZJS4GCRz0HT+hmBX5chaJcAV07PHZ9mU/nt9UoRdGNxANT4PHpZo4wp14kyKY3jkaBFRb6WXRNFvifW4wJJw5Gix7/DscjriZNNacnZ97nFUPSG1vpx9RaIvZxa+rTI+H0hIzn4dDyZHo9PvTJeWHSlwcMIHiAYI= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=ugent.be; Received: from AM0PR09MB2324.eurprd09.prod.outlook.com (2603:10a6:208:d9::26) by VI1PR0901MB1440.eurprd09.prod.outlook.com (2603:10a6:800:8d::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.15; Sat, 12 Feb 2022 23:14:31 +0000 Received: from AM0PR09MB2324.eurprd09.prod.outlook.com ([fe80::b115:2e4e:1623:f624]) by AM0PR09MB2324.eurprd09.prod.outlook.com ([fe80::b115:2e4e:1623:f624%3]) with mapi id 15.20.4975.014; Sat, 12 Feb 2022 23:14:31 +0000 Message-ID: Date: Sun, 13 Feb 2022 00:14:30 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Content-Language: en-US To: Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz Cc: linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org From: Niels Dossche Subject: [PATCH] Bluetooth: move adv_instance_cnt read within the device lock Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: AM4PR0701CA0029.eurprd07.prod.outlook.com (2603:10a6:200:42::39) To AM0PR09MB2324.eurprd09.prod.outlook.com (2603:10a6:208:d9::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0f5471ec-d5a0-4644-f7a0-08d9ee7d6cc5 X-MS-TrafficTypeDiagnostic: VI1PR0901MB1440:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: aM4FfqXtVJRHte7Fh0+ZOgKNy5w+UvJjN43V39+CuncNOiCfbb5oiw82krWtPVSUCkk4ruNdPTHibvzUByp2fjU/p5IG9BDg9wvnipFawDHdnZOwzfKzcz7zTVR4A7CyUDxYS8FwNLgK8L6imtPmQ8Vw5050w9zK7pmUGhNBepsWc2RiZnBiMNPKljpQMV2wXABc+XFeGV+8PQbbTkOU/aHZotTv3eTr65g/8dMza35ENfmBf2VHUDEHeSqcTQyB+Iy06MwXbsSEA5tplPMkCpMclbfMO6QGnWrll5FY5O8OzkswBwvJmHJVB7KyflcyjXV3YsfBc8/+leeQlXn3iJ8Qeh0TQQBDbgvInHZAXOiiq7xmALuZJzGShiqXkWmqZwGEVuPgVFAYxUU9ktDWYw30DRBzOUo+prvEd4BVOr8MjLNOMPHcDklnrjBY0+nxkxrQB7TQHC82VowNwV7VES6qRtCuIul3rcnYeVqcsbZ8rF9IUiJdDlPbyr650PJNaIe2FOIakrMcd2XLRJtG5Z4S2eXSahBaTcbmIafMgp+ly4mr4/8Dg5s9MamaaO4VRqkaqrk94UQUDH7cyBka9J/x94XlUqtqfWWiLR/L+D5Kd1zSh3Jwft3MHyTl6MGB/Iq764+8NLzJ14dYaCWADa6AuoodniYjacMDuiUCZ0NCNsaL54/ja1au2BQNDyHQzCfoiuhM/ik53dhAgECI0mGk36vh7AhbkXfoyzV/d/E= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM0PR09MB2324.eurprd09.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(4326008)(66556008)(31696002)(66946007)(6512007)(8936002)(2616005)(66476007)(86362001)(2906002)(83380400001)(508600001)(186003)(8676002)(5660300002)(6506007)(38100700002)(6486002)(786003)(316002)(36756003)(31686004)(44832011)(110136005)(45980500001)(43740500002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?MHlLdEswMVhjeVdKUDFXNFB1a0F5UC9walR3Tlp5YWFJNmRna0gzbzZ0SWhu?= =?utf-8?B?V3FhRzhiNmxhMFdUM2QwaVVLOCtPbzZvVTZxY2hPY1FLVTRXcmFvbDZpS3lJ?= =?utf-8?B?dkpYSFhkUEhCQjRxWVhkemRCSVh1YkRoL3Z3Vm10QVlYanIwYlN4YWxESlRu?= =?utf-8?B?VXVmYm5wL05oNkZOQmNtSG10TjRQYnl2cFRrOElOakZRa1ZkL2dNa0IzQWds?= =?utf-8?B?MjROeDk5OU5OKzV1WVdoZW5kMGExbjJoVkduWTJGT1AvMjJoUmJoenFPRk4v?= =?utf-8?B?UlYyaTlxUjFkTTlwMHgzYit4UGZ1bjlrNGY3ekpYSnVPSFNIYk1jbUt2MHlm?= =?utf-8?B?MjhwbW1zTDlQdVpqYlExSVJ3V3QzTkJranZ2TVAyeWdmV2N1QjRmN0JET1Zu?= =?utf-8?B?SmdOMUthaFVsQklDRUdibXlZYTVzODNoUGhpVFNiUE1rQmhjWGFGcC9YTWpF?= =?utf-8?B?cnFoZ0VPbXdZYzFmZlI0TTJ1emFyWHJsS2ZSZjZ5UVlPR0RWMzIzcEMxMENo?= =?utf-8?B?dTNsYzBUQnNtYWdqem5PUnFuR3VjcmgzelRQZE16WVRTbzd2SkxZOUh5VTFo?= =?utf-8?B?OU1KSW4vdGgyNDgrQ3J2by9pT3Jjd2tBOXNUcFFtK20raWxPd0tGYnREWVNT?= =?utf-8?B?SndQOVdQSU42bGJwdmNsK052b0ErS3Q5VlFtUTRvVEVjYnVHb3ZValBmamx6?= =?utf-8?B?KzFLcGpmYm5ZeHZ4RDdWOVEraGtXdExkMERRcEo2S3pZRTFxTG1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E1FWEtsWityNzVrZURZaW1D?= =?utf-8?B?Nm15YTd3S3VmKzJzdWlBR1lraGhmYS9vbGpEV3VBZGZSZks4OHc0OWE5TzlY?= =?utf-8?B?aktqQWtZZHJQOWQzN0h1QWlHQndjTkZpQkM4TDRUTHM3cWt6ZElxZEx1WGRP?= =?utf-8?B?OWZOaFRnY0UwWDYyLzVCRUJ5NVNLWmdNS0ticE9ZL3ZIODM1S3EwS1RZUVFw?= =?utf-8?B?OGJpdm1uMmphRDJIdEo0WWl1Yy9ZRUZZWldhbDI5ZTFRMkFnTGljZ25QbTh4?= =?utf-8?B?TnpNdUhic2NId2ZsMjQ5TWp6YW03VzJyOElTNFpkcVJHK0FnZTZpWER1d2Qw?= =?utf-8?B?NVo1N1I5eFMwN1YyTGJFbHI5c2swWHZZcmttcE9hTjBXYnl4d2JlQXdHNlpC?= =?utf-8?B?VndRczl6R3BJQUY0cnkyZHNlOGx1ckswNVdkWEljb3ZtbW4zSVp4ZHVyZ0JB?= =?utf-8?B?N0c4UFB3VXJ4VWFkRGlGZ3NhNmh2QjdCRnhXNk9BRkc4UndCaVgzOFYxZWRC?= =?utf-8?B?czFpVERrWW5oMTZvNHdDYnI2ak02eXlubWhmbGs0NFdVOUhkR1RqbWJKY1E4?= =?utf-8?Q?QyD8P8Mi9ZJ8IQXs/1TJKkpGqivuah/zlE/KkkszQY=3D?= X-OriginatorOrg: ugent.be X-MS-Exchange-CrossTenant-Network-Message-Id: 0f5471ec-d5a0-4644-f7a0-08d9ee7d6cc5 X-MS-Exchange-CrossTenant-AuthSource: AM0PR09MB2324.eurprd09.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Feb 2022 23:14:31.4434 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: d7811cde-ecef-496c-8f91-a1786241b99c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: COGr7kDS1zCLIrVB0+xm6a7tQyxixCgBp+RcIuyACHslLgLizMOAmRYkTz5aDJI+gzD8+obxNYsoBHDqOzoiTA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0901MB1440 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The field adv_instance_cnt is always accessed within a device lock, except in the function add_advertising. A concurrent remove of an advertisement with adding another one could result in the if check "if a new instance was actually added" to not trigger, resulting in not triggering the "advertising added event". Signed-off-by: Niels Dossche --- net/bluetooth/mgmt.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index 37087cf7dc5a..e0dc72f147b4 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -8046,7 +8046,7 @@ static int add_advertising(struct sock *sk, struct hci_dev *hdev, u32 flags; u8 status; u16 timeout, duration; - unsigned int prev_instance_cnt = hdev->adv_instance_cnt; + unsigned int prev_instance_cnt; u8 schedule_instance = 0; struct adv_info *next_instance; int err; @@ -8097,6 +8097,8 @@ static int add_advertising(struct sock *sk, struct hci_dev *hdev, goto unlock; } + prev_instance_cnt = hdev->adv_instance_cnt; + err = hci_add_adv_instance(hdev, cp->instance, flags, cp->adv_data_len, cp->data, cp->scan_rsp_len, -- 2.34.1