Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1067374ybb; Fri, 3 Apr 2020 17:40:41 -0700 (PDT) X-Google-Smtp-Source: APiQypKWTdmnbEPajiwhxXS5vosrp5rBjEwzLz0xLQxjkSUeR8xFpAnqyj0Jg4bhntg+C9t2DUZ5 X-Received: by 2002:aca:fd48:: with SMTP id b69mr5082564oii.126.1585960841421; Fri, 03 Apr 2020 17:40:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585960841; cv=none; d=google.com; s=arc-20160816; b=07Ra+dxUKEu2Syq9vufS0XUdazUbpy2J+pQu+KRLb9x+DrZ9oXd54LhnNZWIdgqr8m qmi73tYwADoftKnnYWBUDae+NoJCNp1YY+uxpvwc5OfLcDCP/oV/nJkHiQyWfQ56Y98f UNBaADHiEF2p6NhSK18CVpvlWhkKIppyuzvUtnPUomYz9+A8Erl83eE1+Up38JoHpHep pIqKd/BbA+jpUqYeGNreSmvuFmtvJtKvyAP3rxNhcOY+LuzP/G2WsJPymU+coQWgre/0 O/V6mVqU8RcMVSOhidiodQoQzn6WWV6UDYGDAQFVlfP74BE8L2R3K62yuyt6R2nMRaRF RhAg== 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=fwdppA0HowuUxClKJSgNKg+JHXHmd+YQUDGgvkgPrgc=; b=dz6LCE6bOERfavU35Vsqp8iDaHt2z/ZXlbenzAGMrJBL/eqzaHCZosOn0Y/FY1R/WM bpXeZh2foYMo9dBTy3dVUEA+dU1PLODzGg6kUVYasGyFT+hweT+sRdZ/cTXMVoIGhzcf DiGE81Dv0HwJtUM2lVvhh/B+F/h/K5857enexgmMfA/bVNPKRRW4lIETIMwpzutSu7J5 ySOXHgqGu4vCsURw9J2QCVOcZd4+J4V14uHFBgNAjl1vjfwMStT8lhhYWl90w72rlIyG dytB8iq7NhoNfHlE65XUhBG5lPI+xFNJnskyfNWvq3mtJA6zEp9jbTrdeU6S6Tkq5L6L 8NhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=CTYeesYi; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w4si4468621oie.124.2020.04.03.17.40.28; Fri, 03 Apr 2020 17:40:41 -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=@chromium.org header.s=google header.b=CTYeesYi; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726464AbgDDAjs (ORCPT + 99 others); Fri, 3 Apr 2020 20:39:48 -0400 Received: from mail-oi1-f194.google.com ([209.85.167.194]:37891 "EHLO mail-oi1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726461AbgDDAjs (ORCPT ); Fri, 3 Apr 2020 20:39:48 -0400 Received: by mail-oi1-f194.google.com with SMTP id w2so7841812oic.5 for ; Fri, 03 Apr 2020 17:39:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=fwdppA0HowuUxClKJSgNKg+JHXHmd+YQUDGgvkgPrgc=; b=CTYeesYijL6YL0zbY2T3qZ9i9jeI+GL+zJV/w8dCXBJeLXh80ZNTvBGixknssfhX1T 1rCCELoyTTit8BEXfL9towo6fN7qTznLFlsXaS3X17sDNz77Xy9qtI2NGU4R04t0aovx OuWqaIM5p76ajHQA97GKBo8dejcwB7YDY/FWI= 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=fwdppA0HowuUxClKJSgNKg+JHXHmd+YQUDGgvkgPrgc=; b=JkJXvmknKfWLiZXJIL8Ddo8qI5/BJL8NA928qxWYuyko04Er2y7+/8WQkfqrN6X5W0 IwxiDSKz/heC1fVYPQFh6ebosrR2CziUCM7itZueVtKXudO51CI2oGLy9zMnuwxeiOyo i5am8qwENsXmGJ5DLQcZYw+frDoePLFkkh0val7JyACMBL8MoCisbcO2/Uvrg+i8BoV6 7sn32No+YF0qyZikEsaax/dwwz0NBX3iHnenjLGl98NUVOF+/1js/9Vv+Rr7RSknZZW1 8a49wpOHEhNUVcTQRnBIwMXW8ZUXFk6AMTHnW2c/SxgbCMMHsN69LKeNHUQIyDMXQ16S erow== X-Gm-Message-State: AGi0PuaC/OZ0AjiiaztR5qWDoWmnBV2KXqRBp7W3v5YtdS356hbi1Hqt GPxLG2deXxbLlckYeVUxSaJpyUzx6DNvHAh5Rx5aeQ== X-Received: by 2002:aca:1e0e:: with SMTP id m14mr5275665oic.136.1585960785750; Fri, 03 Apr 2020 17:39:45 -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: From: Sonny Sasaka Date: Fri, 3 Apr 2020 17:39:34 -0700 Message-ID: Subject: Re: [PATCH] Bluetooth: Simplify / fix return values from tk_request To: Alain Michaud Cc: Guenter Roeck , Marcel Holtmann , Johan Hedberg , "David S . Miller" , Jakub Kicinski , BlueZ , netdev , LKML 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 The patch looks good to me. Agreed with Guenter's assessment, I made a mistake in the original patch by not being consistent with the function contract. On Fri, Apr 3, 2020 at 9:57 AM Alain Michaud wrote: > > 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 > > > > >