Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp585386ybb; Fri, 3 Apr 2020 08:15:05 -0700 (PDT) X-Google-Smtp-Source: APiQypJpsg0pN11vcLpwHpVN/lGxLA0hXGXA2sjmmTEudvDwgnLlDs2ar+5jL05uy6FAvkIUbEJ4 X-Received: by 2002:aca:75d5:: with SMTP id q204mr3452126oic.9.1585926904993; Fri, 03 Apr 2020 08:15:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585926904; cv=none; d=google.com; s=arc-20160816; b=E5hh2eBT27c65lTMy9SKBgsGHPnzmgFUfs9HN+IrqYjVqnvomL6ZYRJe2Q+GzKyMyj rIMq3mMSVD5mBlpdckurntPFPEPa50pvYIa5vtnsKjLA2ScsJWDOApXC9HOKGC3q9sN6 zbSqSqee3Io25GMXjtmOmr9drGw2F+IpoTUEFqkUrQYi3hzY6eaORbSC4G61oJB8mij0 4wngMV735n9n5ecPeXfTUO12Y/oqfINUpCcKqBChAtfJSAONXAqvhvJ0CN8g/Hx/bKOq +GQmDh1DHiEE6cZugebFDHBny/pj0mnxZo4xcQ/x4heXLuwAauejxGvUu/zKtBcvGJVL iREw== 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=DSB/s+jkbmzG+872wg2P5RsXw25dw+k96VoLRNM+xIk=; b=uqieNtVDm4YJ/sjFzGSO7qLF46miqjRtC2Qmi8CkfHHPM4psIno5BuQaYBaZzl9G4k uWdZWUw/KANsZ07qW75RRc/DZtGb7IDmkvR8tIQmtwxgntjjtt7YF3FjmkFKZkqhGod2 O3do76MHSXaz8Ft2QS7DLFADCwDitAqiiSqmG53TMFrf05Is8RZqzLRZT3C9ijMg+aQm ouzLLa6EEe75Jo4O1m+SFmKON89qydCWAQIWYaEFlCn3iZKKDRKG0qv0NA7L2126BKSH jj6PHCm4BsII0mQe2AvkebCWwLlaYsNbSfnS8Po2K1+jfaGlCeSUb3T3Q01nGdwrBXW4 ufjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=NnJYHcrE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 y4si3900105ooh.53.2020.04.03.08.14.51; Fri, 03 Apr 2020 08:15:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=NnJYHcrE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 S2404163AbgDCPNx (ORCPT + 99 others); Fri, 3 Apr 2020 11:13:53 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:41585 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728213AbgDCPNx (ORCPT ); Fri, 3 Apr 2020 11:13:53 -0400 Received: by mail-lj1-f196.google.com with SMTP id n17so7299756lji.8 for ; Fri, 03 Apr 2020 08:13:51 -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=DSB/s+jkbmzG+872wg2P5RsXw25dw+k96VoLRNM+xIk=; b=NnJYHcrEmoB8qNXKZ3slYqn5PMbvp36PsylL6He+9olAxu//fFL0pW4XIUIvD8cMrC Y6yJUUkqD6a9+uUEcC8JRoRzvnPwwrxRCwu5cm7XKxdFF0A/t/nmcgJKXjWTTn4txEwc Zq2lnpBvjQjY0ThdGLJ6pNVSru7mBNvrD2SWMqXXZmWfZHKPmHXm4eNcwAw8ElBj/jT3 cNeyUrYOt0SLmx7WShfQxs1JwZ5G+ZKdS5bWF08a2A6lsdVXeADyUkvgW+k9aHrbsLSu +O5s8Z35IVJrBBcJYxOOQJRSxgQpvskRgy5RHSR0ueUphiBEl+Tl3s1X/15Em29ndTdH X6ww== 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=DSB/s+jkbmzG+872wg2P5RsXw25dw+k96VoLRNM+xIk=; b=ls4yhpWD1iUZtk9WmFcUtZfEchrBKKimda9o66JzVF4Ax1/jfhF/mYqBbZ5aMMa1tH ukJrNggr/l0V8hVVKsFgVfxDJWdbiQuI1IyHcz5DUIqeUs7+a7qI02e0YvVAWATTNS60 cPoSP4Zm0vIzHgtz3izQATV1mZYZt9sVC+aVWM5ypzmY+t1fMmXX4oyNiYlQvCYuTAy9 4k+bmGzeCVXzKw3Z/vHa+nGvBRpRxPAKGbOMw0H50kFVKMS5WrFLR+nrFanLB7cD5d8F jB+pQNGH5FbxG2cPWkbrCKgN/jWeHcR7oLw15PNnqJ3lzhozBFI27Boz/Bsvp0NGwnum 2fag== X-Gm-Message-State: AGi0PuY42dHc/6BfeH1GEpV6881DIzsHaOKNmkvphQmQkoOFB1tj3RcN sKxOtp92j3Q+tVzaLdCZbUvcVrOEFrx3u8fCOAVqGw== X-Received: by 2002:a2e:9084:: with SMTP id l4mr5287406ljg.277.1585926830857; Fri, 03 Apr 2020 08:13:50 -0700 (PDT) MIME-Version: 1.0 References: <20200403150236.74232-1-linux@roeck-us.net> In-Reply-To: <20200403150236.74232-1-linux@roeck-us.net> From: Alain Michaud Date: Fri, 3 Apr 2020 11:13:39 -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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. > set_bit(SMP_FLAG_WAIT_USER, &smp->flags); > return 0; > } > -- > 2.17.1 > Thanks, Alain