Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp673312ybb; Fri, 3 Apr 2020 09:43:20 -0700 (PDT) X-Google-Smtp-Source: APiQypKwtyR1BRKKYG7ERk9VM+SKFDcmDV6FkFhg9Zu0UXX8lmAIJ2YhUlykWbjSXu2jc2XUJslf X-Received: by 2002:a9d:221:: with SMTP id 30mr1280070otb.41.1585932200153; Fri, 03 Apr 2020 09:43:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585932200; cv=none; d=google.com; s=arc-20160816; b=FX1jrcXdOiycLX4NQJSng94cifBGDWkL6ZgeE53EdHzCWk704l+0t2OrMHMpMRr6XT /iyxe3JR5FmMGEtrjpYa5lrey09kKrrOa86LzngDvQT1zdME9xzfLWYi4sG7rYMhhhxs Ch0eyF2tMmYB8ptKtTcdwwdyYTvuk0/AyYbAd2fML8AACXLP/7pMceb/CZuK7gHbMDPn Tp7BEg15L62BsgDmvWEDajw9zBSuxUaxcXAp6WCswXT3UmqNUTGu3jGdSvROB2hVxDlP lakha4x7Cpdn5AcLXeIdttWjzRS3DEi/qKy1j5BIycz5COFezbnq+F5spENa5PLDn8z/ 5HTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:from:references:cc:to:subject:dkim-signature; bh=5o7FgpRekkJWKWnqOGlOTdK7UlK2ntTVJ9iFNyEogmg=; b=DxRxUJM9HwtX1fkm0eOd8vEOMwDAFgzsvsAED4vKCY9htixJRWkPDCVWZlbAtY3ZG7 zJvcD7tBGlU+yYxbn9ZkUhiCjpnxBFGa3mdWahNmSrjJfHGdEU3lN1qdlEA21/vYzhaZ r6yyHcMNn9RnXBBePTSimt3HwxvVRZIc4Nc1OeZHOKdQk+9rW1dShNUQf9pCgog4crrn zT91FkVrUWxeXfwRVtgh/igv2Hpb353GU7MtjYR3I1zTn/dopWA9i97XXY7YeBr4o4y/ ibrd3TM6vRjkROiFi6m/UcGMNmrFhw1aIilZiz5YXJhEnpVQQL+d7budzL7mc7Ep1G2r Btlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b="AJSSWkH/"; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d10si3808536otc.287.2020.04.03.09.43.08; Fri, 03 Apr 2020 09:43:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b="AJSSWkH/"; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404233AbgDCQnC (ORCPT + 99 others); Fri, 3 Apr 2020 12:43:02 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:35431 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728352AbgDCQnC (ORCPT ); Fri, 3 Apr 2020 12:43:02 -0400 Received: by mail-pf1-f194.google.com with SMTP id a13so3754129pfa.2; Fri, 03 Apr 2020 09:43:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:to:cc:references:from:autocrypt:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=5o7FgpRekkJWKWnqOGlOTdK7UlK2ntTVJ9iFNyEogmg=; b=AJSSWkH//LdVPzBJCBtq5++foxAHGjRBA6cVXWLYJdVoULlWZBwVhTQvvBgEzGX9Wm KTKIQ8xK00qe4NagAq45yhwW44LucojH7J+DK1vZDmzRb1dVoX41Ng1pTZUdY0vpl298 T3OuFQ4Cp00sGld71HuefofI3yznV+1bjezfKXzGtZhSmZIRazwvIqEjLjYSPd5X3OyU D3FIh91uZOp7mOOkuTQiPsA9/z0sO6/xB43ZjaiNR+yvu4fuGYh9X06NnL1jn/MZvGv2 BJIrdDgRIdCH+2y0km+gwHHV5835iPgJYHnAr6yocslHQmaGa3OgN+NEEvtqSXxrBzCb 8YFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:to:cc:references:from:autocrypt :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=5o7FgpRekkJWKWnqOGlOTdK7UlK2ntTVJ9iFNyEogmg=; b=HOZmwevJ2+TZuxtlTeoYEa6EpbuyuYYWGJotG+l8xtiSnYhXN0017KPkvRLrkyjFIF vynjIDXU77PNFzYfyaZbGCh+GmKF8yzA+i1t/HSm6VvCE3TeowhuEoCb71HMqhJb7KU3 L9oL885d5+jObUu7SCs4jvpC0186Ry/c7dF50nUn7novaIhNDErst9GTBdc8d4LzfDuD 4haPEtq/70O4kJzZN8bsYPpIpyLk7qvIvlZ6KVEUt6zOUz/KlJlehzF8VlwsIHRN1U8q GlQ+cJyE+u7xspStst5bbwMcpOSOvcV+pJm5nvpM/KKjbXA2HIZDnYC5Osem4Kjk7Y2d qrHg== X-Gm-Message-State: AGi0PuaMF67U0PT8N13UeUH4QBFBGPn4oNcQT+CE/7m4StxhFGsAlvoL pOs9Ja8EX6Eq0V8h12EGqx0= X-Received: by 2002:a62:52d7:: with SMTP id g206mr9618447pfb.286.1585932180544; Fri, 03 Apr 2020 09:43:00 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id t1sm5595886pgh.88.2020.04.03.09.42.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 03 Apr 2020 09:42:59 -0700 (PDT) Subject: Re: [PATCH] Bluetooth: Simplify / fix return values from tk_request To: Alain Michaud Cc: Marcel Holtmann , Johan Hedberg , "David S . Miller" , Jakub Kicinski , BlueZ , netdev , LKML , Sonny Sasaka References: <20200403150236.74232-1-linux@roeck-us.net> From: Guenter Roeck Autocrypt: addr=linux@roeck-us.net; keydata= xsFNBE6H1WcBEACu6jIcw5kZ5dGeJ7E7B2uweQR/4FGxH10/H1O1+ApmcQ9i87XdZQiB9cpN RYHA7RCEK2dh6dDccykQk3bC90xXMPg+O3R+C/SkwcnUak1UZaeK/SwQbq/t0tkMzYDRxfJ7 nyFiKxUehbNF3r9qlJgPqONwX5vJy4/GvDHdddSCxV41P/ejsZ8PykxyJs98UWhF54tGRWFl 7i1xvaDB9lN5WTLRKSO7wICuLiSz5WZHXMkyF4d+/O5ll7yz/o/JxK5vO/sduYDIlFTvBZDh gzaEtNf5tQjsjG4io8E0Yq0ViobLkS2RTNZT8ICq/Jmvl0SpbHRvYwa2DhNsK0YjHFQBB0FX IdhdUEzNefcNcYvqigJpdICoP2e4yJSyflHFO4dr0OrdnGLe1Zi/8Xo/2+M1dSSEt196rXaC kwu2KgIgmkRBb3cp2vIBBIIowU8W3qC1+w+RdMUrZxKGWJ3juwcgveJlzMpMZNyM1jobSXZ0 VHGMNJ3MwXlrEFPXaYJgibcg6brM6wGfX/LBvc/haWw4yO24lT5eitm4UBdIy9pKkKmHHh7s jfZJkB5fWKVdoCv/omy6UyH6ykLOPFugl+hVL2Prf8xrXuZe1CMS7ID9Lc8FaL1ROIN/W8Vk BIsJMaWOhks//7d92Uf3EArDlDShwR2+D+AMon8NULuLBHiEUQARAQABzTJHdWVudGVyIFJv ZWNrIChMaW51eCBhY2NvdW50KSA8bGludXhAcm9lY2stdXMubmV0PsLBgQQTAQIAKwIbAwYL CQgHAwIGFQgCCQoLBBYCAwECHgECF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FnU mDW4+i+XlNFUPUYMrIKi9joBhu18ssf5i5Q= Message-ID: <0f0ea237-5976-e56f-cd31-96b76bb03254@roeck-us.net> Date: Fri, 3 Apr 2020 09:42:57 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org On 4/3/20 8:13 AM, Alain Michaud wrote: > Hi Guenter/Marcel, > > > On Fri, Apr 3, 2020 at 11:03 AM Guenter Roeck wrote: >> >> Some static checker run by 0day reports a variableScope warning. >> >> net/bluetooth/smp.c:870:6: warning: >> The scope of the variable 'err' can be reduced. [variableScope] >> >> There is no need for two separate variables holding return values. >> Stick with the existing variable. While at it, don't pre-initialize >> 'ret' because it is set in each code path. >> >> tk_request() is supposed to return a negative error code on errors, >> not a bluetooth return code. The calling code converts the return >> value to SMP_UNSPECIFIED if needed. >> >> Fixes: 92516cd97fd4 ("Bluetooth: Always request for user confirmation for Just Works") >> Cc: Sonny Sasaka >> Signed-off-by: Guenter Roeck >> --- >> net/bluetooth/smp.c | 9 ++++----- >> 1 file changed, 4 insertions(+), 5 deletions(-) >> >> diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c >> index d0b695ee49f6..30e8626dd553 100644 >> --- a/net/bluetooth/smp.c >> +++ b/net/bluetooth/smp.c >> @@ -854,8 +854,7 @@ static int tk_request(struct l2cap_conn *conn, u8 remote_oob, u8 auth, >> struct l2cap_chan *chan = conn->smp; >> struct smp_chan *smp = chan->data; >> u32 passkey = 0; >> - int ret = 0; >> - int err; >> + int ret; >> >> /* Initialize key for JUST WORKS */ >> memset(smp->tk, 0, sizeof(smp->tk)); >> @@ -887,12 +886,12 @@ static int tk_request(struct l2cap_conn *conn, u8 remote_oob, u8 auth, >> /* If Just Works, Continue with Zero TK and ask user-space for >> * confirmation */ >> if (smp->method == JUST_WORKS) { >> - err = mgmt_user_confirm_request(hcon->hdev, &hcon->dst, >> + ret = mgmt_user_confirm_request(hcon->hdev, &hcon->dst, >> hcon->type, >> hcon->dst_type, >> passkey, 1); >> - if (err) >> - return SMP_UNSPECIFIED; >> + if (ret) >> + return ret; > I think there may be some miss match between expected types of error > codes here. The SMP error code type seems to be expected throughout > this code base, so this change would propagate a potential negative > value while the rest of the SMP protocol expects strictly positive > error codes. > Up to the patch introducing the SMP_UNSPECIFIED return value, tk_request() returned negative error codes, and all callers convert it to SMP_UNSPECIFIED. If tk_request() is supposed to return SMP_UNSPECIFIED on error, it should be returned consistently, and its callers don't have to convert it again. Guenter >> set_bit(SMP_FLAG_WAIT_USER, &smp->flags); >> return 0; >> } >> -- >> 2.17.1 >> > > Thanks, > Alain >