Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp687236ybb; Fri, 3 Apr 2020 09:58:40 -0700 (PDT) X-Google-Smtp-Source: APiQypJw7L2pgVSVOb7HjDCuhwmly5KNK89G4H87pXwAuY/3osUHXIa4CPSmvjO8eBhQrHVrRw8c X-Received: by 2002:aca:4cd8:: with SMTP id z207mr3646317oia.155.1585933120653; Fri, 03 Apr 2020 09:58:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585933120; cv=none; d=google.com; s=arc-20160816; b=j3RUDYv3QLUCODrnbLTaR73TpTeeyUqAUXQj4I6o6QqP5pv658LHFNSJ3cHonDDItq YKuekOCUbQN1WSPZQat8jrmT7hHJLp6Yaos4zGmAQKiDsO+6nhqNOes+oTSju0hSk0UF uYLBkmXzS1k+53/GHKZYjoKRQuHw+GhQsV0h8TZWtHMp+H5tQQwAqSDTT2DeepRCEWQ+ GznnCIsQ9/iM+7NLS8ejAYSi21VNzebsvN6UvIGfhfKYlIvoDkxC4SZCMgt/LkceoWNd 7ot7DY4S99PnHXeILPG/7fJEHJzHzCItMzhPtRGw27Tm67j1M0p4GYqqWB/sMx1Rx5c4 kSLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=Lrcp2Eiyu9q3gbWwkT5O7o0+h0SVlGQKfd2CEGLpkSk=; b=uwuIJRlAYDliarJIQC+1jy94/oaHDxUzzNCskWlEg7PYQI448EjAu+h7L+TaQg4ChC ZhcGKiQ2LIQm1Gtllx+ZA1GZ1FoWuWLEmjS28AsfwnPWL4EfckaKFlTdJvjxocy0WMoo 4ajtukMXC96yUQOZQhbHkjn9UvA3r7So3paxyQhePCt3XHCNHXb3xPQKvl7GXDz1gQjK JIn/rTC813NhbweuaJXWpCzkSGs30qvgDBzRArX+jQ8GZBpxbn8vBi2tnyiHKcUPN1DK X1vShj8MB68AwAtdG5FlFGDmRLtp0+4FOTPOboKNobt3IKFzNJ8LWWL73Fa5YPo5Svrt Tr1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="vO+eeiD/"; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f12si4366231otc.147.2020.04.03.09.58.21; Fri, 03 Apr 2020 09:58:40 -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=pass header.i=@google.com header.s=20161025 header.b="vO+eeiD/"; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391092AbgDCQ5N (ORCPT + 99 others); Fri, 3 Apr 2020 12:57:13 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:38436 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728284AbgDCQ5N (ORCPT ); Fri, 3 Apr 2020 12:57:13 -0400 Received: by mail-lj1-f196.google.com with SMTP id v16so7679891ljg.5 for ; Fri, 03 Apr 2020 09:57:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Lrcp2Eiyu9q3gbWwkT5O7o0+h0SVlGQKfd2CEGLpkSk=; b=vO+eeiD/lQC1CSyjmAXdVYyjpxA/6wbx6QY3B5R4u3MdCODxv2AslQR1ctFAaT7Aiy M9dGkV21vwGECTPiycUVxQrhI9MhY1PzspHbaY6FW/oApQmcN7Cj68qfIrILTvpecWZ6 dtnrdRZbuRoQGG8bZNEuizWEXp98DPxaS/0Z3pMrDqmgQ4pQrasHu20byweMwOpvHP9o lznug//ruWUFVKFQHNlmQKZV780xNoLsJbugMYOVO1u99suFlF//O1oyjBBhXoCtaK2q NgiTmlJL0R8sTYudb1wOCt7/AaDp4bNDioFGPUcAlU4I9f9g5m96fBeiIq1D24Pxf0n2 h4Gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Lrcp2Eiyu9q3gbWwkT5O7o0+h0SVlGQKfd2CEGLpkSk=; b=hZcSeTNz6GMONMzyhQmUtUFg/bxdfrcVIFeP7A8MTkfCOybNwV6LqzxGajU+3mvrX9 yoexqFmmeXo6Ee099RegFyUIBUh2NsT9DZ7Gdm5xYvPHaqVKpARWxBNOc6eNTtOkUddM JZOMnHnkYtcdr9D6fEaBbJQ+ebcO6z+p0eqEmewibwZU0J7qFB7J9dHKKMVU0ff6/7C2 ePRFxNfywuSX5j0yRSK6/9sjlJJjHBcEph7g+ltQPDKTIIsBxXpLY+/mvfDL5DRY0/xw aWDABMyhIHYanKmy2462SNAqfT1h4wVfIbSnO9H8ODMjSMEehlBzx+TzTZSK3Ide6SGo NteA== X-Gm-Message-State: AGi0PubWxXrLwD2sqTrw0HrXrpXBIgl16MrIvsFbOGc0RzmPH4kQEpgj YYapCoydVKDULJXWWV3k/1UZj/imSyeVbH/ryA1tdzp+ X-Received: by 2002:a2e:9652:: with SMTP id z18mr973853ljh.79.1585933029892; Fri, 03 Apr 2020 09:57:09 -0700 (PDT) MIME-Version: 1.0 References: <20200403150236.74232-1-linux@roeck-us.net> <0f0ea237-5976-e56f-cd31-96b76bb03254@roeck-us.net> In-Reply-To: <0f0ea237-5976-e56f-cd31-96b76bb03254@roeck-us.net> From: Alain Michaud Date: Fri, 3 Apr 2020 12:56:58 -0400 Message-ID: Subject: Re: [PATCH] Bluetooth: Simplify / fix return values from tk_request To: Guenter Roeck Cc: Marcel Holtmann , Johan Hedberg , "David S . Miller" , Jakub Kicinski , BlueZ , netdev , LKML , Sonny Sasaka Content-Type: text/plain; charset="UTF-8" Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org On Fri, Apr 3, 2020 at 12:43 PM Guenter Roeck wrote: > > 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. Agreed, the conventions aren't clear here. I'll differ to Marcel to provide guidance in this case where as a long term solution might increase the scope of this patch beyond what would be reasonable. > > Guenter > > >> set_bit(SMP_FLAG_WAIT_USER, &smp->flags); > >> return 0; > >> } > >> -- > >> 2.17.1 > >> > > > > Thanks, > > Alain > > >