Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3237352ybb; Mon, 6 Apr 2020 05:06:34 -0700 (PDT) X-Google-Smtp-Source: APiQypJcbJKiZsZFocqR8X1C1Gah+cit3zIVz+qVG90nCekaB3nDUQANENIp9Ayw+gPc9w36De2k X-Received: by 2002:a4a:3f19:: with SMTP id e25mr17333604ooa.67.1586174794121; Mon, 06 Apr 2020 05:06:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586174794; cv=none; d=google.com; s=arc-20160816; b=VBwDJiYCO/6vnVhsYR7TpMSSbwBrgTYbPvJg3luUV0xqg2gY3jk97GLeFxa47sV8yc d1bBuI5OYRSEeSwQdXYuVpBMUx1f8lz9luIvDfOAVU+hDwicjUfa0eOsD4WOAGNhCp93 ipwNRwa6jaPBnFA0KWuz0dzfRR6cCDTWH26PEquVPQ4y0zXVCsVNRQnAl8j77ZfK6AgL t1tRoMxTaOs48bhjA0qFBYOgcn4uwN1yNPzHn9w9y7cwwkVvt8Vlfr5pwDHyIQlDHI9q dDZKFxyCPX/tsPjzEE7B31/VriKugyoag0g2SoAH+eUQx5c3/WS7EpccWPDAEqHXwh9a yIpA== 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=yWdmRwGKL9yrwgQ6BECFFWJNLwC9pOY+oG/5xJhqBzA=; b=KY3xWi6rRS3NmLAcUfeEIJAb5ryOp+ZM+Jad+Sw1hEt9mv3G/KpGvqtbA85XmwwGRM d7EW2plcSh/ONHUqLnmR4BWI/svesZGaCiO5ru3cMxZYSynBCtO1upR/YbXM0btatf06 M8sZQtaPmmYkH6j1JwxP0jyF2zu+rjVv+ybq92k1nd8IsW3YrETVTsNsn8bb8wlO79wk I7vEUvLD7Jg5CXjcZO3IaGAOTtwA3AYXKRB4Y81U+56WbYsn70NNWlOEEjL/xuOKtHvn rS6Y7uaFOmjeAvUCKVTM4mM7RQ+NbMSYxfdJm1EjstKBLuckOGokx8h5cxnRQThvssAB r+Hw== ARC-Authentication-Results: i=1; mx.google.com; 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 f11si611089oop.27.2020.04.06.05.06.21; Mon, 06 Apr 2020 05:06:34 -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; 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 S1727666AbgDFMGM convert rfc822-to-8bit (ORCPT + 99 others); Mon, 6 Apr 2020 08:06:12 -0400 Received: from coyote.holtmann.net ([212.227.132.17]:52364 "EHLO mail.holtmann.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727857AbgDFMGM (ORCPT ); Mon, 6 Apr 2020 08:06:12 -0400 Received: from marcel-macbook.fritz.box (p4FEFC5A7.dip0.t-ipconnect.de [79.239.197.167]) by mail.holtmann.org (Postfix) with ESMTPSA id 47318CECC3; Mon, 6 Apr 2020 14:15:45 +0200 (CEST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.80.23.2.2\)) Subject: Re: [PATCH] Bluetooth: Simplify / fix return values from tk_request From: Marcel Holtmann In-Reply-To: <0f0ea237-5976-e56f-cd31-96b76bb03254@roeck-us.net> Date: Mon, 6 Apr 2020 14:06:10 +0200 Cc: Alain Michaud , Johan Hedberg , "David S. Miller" , Jakub Kicinski , BlueZ , netdev , LKML , Sonny Sasaka Content-Transfer-Encoding: 8BIT Message-Id: <6456552C-5910-4D77-9607-14D9D1FA38FD@holtmann.org> References: <20200403150236.74232-1-linux@roeck-us.net> <0f0ea237-5976-e56f-cd31-96b76bb03254@roeck-us.net> To: Guenter Roeck 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 Guenter, >>> 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. maybe we need to fix that initial patch then. Regards Marcel