Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp176759pxb; Fri, 20 Aug 2021 22:57:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx/JONIXXcNsyBo1FiOEYCHvaG15K7N0/vrtlepoBExva+CYsdTB/W91OXzTs7Qyg+Hq6w9 X-Received: by 2002:a17:906:a382:: with SMTP id k2mr25093585ejz.454.1629525464694; Fri, 20 Aug 2021 22:57:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629525464; cv=none; d=google.com; s=arc-20160816; b=QqK7o8OwJSDz1pe+3kXuKNXuNy5tNAiI8IIxpjaaoMqvoqtj1L7Us6P5a/7s9Gzgfb 84N6ihAjTd8NRjTV+PlH9UgOSm8DzB48tccLB/eW51x0HnjguHDfjFHHCp2JE+kQpgGK tstcL6NCQBholybhIyH9GdyKTetK7NveyKhWxWs1sG05BS8DjTchlyDA4+8EWBAUFtB6 Hct+mcczMHPZJI6rK0tSCnRcYMhAiH6scXhZLVULcs5uZYhbUKoCxEXZN2oohF9/B2yn C7WhSGbhT5SDsmfr1sekdDhe50nEvy39X02aLi71Hp8c3Zko9rdWdj3tr1IOQk+0D9Jr VoEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=aMXSgeio3h45yxi1jpobrvpZ5kfyPjCGua20HuqkoIk=; b=mnau12PK5Wf2NIItORYOAGU1L7nEG4QxhhSxUDmyW4zGbd0ol3IKYBQDehIB8FmAJp /jEBGfMy+HEe4cE8LWSflFaRbNR3nD87LQCM63EXmdgJrCwQyfUCqvHXPGuKWdVe+NCP JAc29SXzCXkgmfIl/mWY1rfeThXE1igxeyJMVEyUfdxlKItA26TyKB6zXfvhNY2PdqRR /efgP7yx/6+4ZYzsrBVSdXfoeNFA71eZR042kBsTzgfMJIfWkXC55qFmnK37E+sRxbD9 CKDut8OCBB2aqZV2c37qw8qBC1qokmWHLgXnPt0MnBSwOZXfr4ykAjBw7wo8sopY89Uf gdzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=DfXFHYO+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j25si9692553edj.366.2021.08.20.22.57.14; Fri, 20 Aug 2021 22:57:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=DfXFHYO+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231917AbhHUF4W (ORCPT + 99 others); Sat, 21 Aug 2021 01:56:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230375AbhHUF4U (ORCPT ); Sat, 21 Aug 2021 01:56:20 -0400 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A20D7C061575 for ; Fri, 20 Aug 2021 22:55:41 -0700 (PDT) Received: by mail-ed1-x531.google.com with SMTP id g21so17144464edw.4 for ; Fri, 20 Aug 2021 22:55:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aMXSgeio3h45yxi1jpobrvpZ5kfyPjCGua20HuqkoIk=; b=DfXFHYO+pe9tx63qBvcpTu8tG9Rdogldu/rTmkMhZxmVSQikl1Li1oCuh4o8LFGvRU G1tjw6ES7+5T/lKSp59oD1hjVRaMVxHrtcr98IodhIJq/WUczgwd43fsgyX0ye84TqMU hE9FuaisdL8hjyhZ8LFtZ7EH82X863LZcLQ6GAdufCpkcJqYGd9G7ckDYtLWJj0H6Ift YlWJS+iCMuBJRsY5LsJUAP/FSqJ8phhaumllqUcKSTydPuPbktj/nK/mmOE/r+yUSd6L 82teS8bmjKwP/kG3iGHkMXdZTzRIDuCW3LvjQV3dpuKd1ESfFXQqEk3mozuHIND60Zr1 c3Gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=aMXSgeio3h45yxi1jpobrvpZ5kfyPjCGua20HuqkoIk=; b=t/6m+xvUCBLkITHZRl5A84ibrt13t6Wki5WSX+IZXDV6wAgP0yu/7Te47w7RQ+t5lN EynrWUInHCAplv8v2ye937j2rzkQ8zY4wHKB6tmc7IpiVS3I32zq1VgMX94iDJ0c9DN7 ouMrryEbOQ2yOXkZafF+zSVXSJZ9UiOZM7smpBUizUdnP4WafkRyMYrB7912SQH1qI+5 atXsMGtH3r/+y0wUlDljRk0uwOFWEL1yB4S7+9kjXSscthBNr7ovv6ym85N/u53ZI9eo +h8JZDFyW/d02KxbmNvJl9t1YmvEFcQuu9YuaJnTVa2yswGSU8FbRrNmiH7MnBQ/HjgL 67dQ== X-Gm-Message-State: AOAM5301nMH9RbH0miCIvxsEW/eNxQWDZydXhxJJ06+mDw/nFApUmWHT sTjpcXCtd+pCjEafOjPDJmA= X-Received: by 2002:a50:cb83:: with SMTP id k3mr27091002edi.102.1629525340168; Fri, 20 Aug 2021 22:55:40 -0700 (PDT) Received: from localhost.localdomain (host-79-22-100-164.retail.telecomitalia.it. [79.22.100.164]) by smtp.gmail.com with ESMTPSA id k12sm2037637edq.59.2021.08.20.22.55.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Aug 2021 22:55:39 -0700 (PDT) From: "Fabio M. De Francesco" To: Larry.Finger@lwfinger.net, phil@philpotter.co.uk, gregkh@linuxfoundation.org, straube.linux@gmail.com, Pavel Skripkin Cc: linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, Pavel Skripkin Subject: Re: [PATCH RFC 1/3] staging: r8188eu: add proper rtw_read* error handling Date: Sat, 21 Aug 2021 07:55:38 +0200 Message-ID: <5720270.rXTAdOU5UK@localhost.localdomain> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Friday, August 20, 2021 7:07:36 PM CEST Pavel Skripkin wrote: > rtw_read*() functions call usb_read* inside. These functions could fail > in some cases; for example: failed to receive control message. These > cases should be handled to prevent uninit value bugs, since usb_read* > functions blindly return stack variable without checking if this value > _actualy_ initialized. > > To achive it, all usb_read* and rtw_read*() argument list is expanded Dear Pavel, Please, achive --> achieve. > with pointer to error and added error usbctrl_vendorreq() error checking. > If transfer is successful error will be initialized to 0 otherwise to > error returned from usb_control_msg(). > > To not break the build, added error checking for rtw_read*() call all > across the driver. > > Signed-off-by: Pavel Skripkin > --- > drivers/staging/r8188eu/core/rtw_debug.c | 79 +++- > drivers/staging/r8188eu/core/rtw_efuse.c | 83 +++- > drivers/staging/r8188eu/core/rtw_io.c | 18 +- > drivers/staging/r8188eu/core/rtw_mp.c | 37 +- > drivers/staging/r8188eu/core/rtw_mp_ioctl.c | 20 +- > drivers/staging/r8188eu/core/rtw_pwrctrl.c | 6 +- > drivers/staging/r8188eu/core/rtw_sreset.c | 7 +- > drivers/staging/r8188eu/hal/HalPwrSeqCmd.c | 9 +- > drivers/staging/r8188eu/hal/hal_com.c | 22 +- > drivers/staging/r8188eu/hal/odm_interface.c | 12 +- > drivers/staging/r8188eu/hal/rtl8188e_cmd.c | 37 +- > drivers/staging/r8188eu/hal/rtl8188e_dm.c | 6 +- > .../staging/r8188eu/hal/rtl8188e_hal_init.c | 198 +++++++-- > drivers/staging/r8188eu/hal/rtl8188e_phycfg.c | 26 +- > drivers/staging/r8188eu/hal/rtl8188e_sreset.c | 20 +- > drivers/staging/r8188eu/hal/rtl8188eu_led.c | 17 +- > drivers/staging/r8188eu/hal/usb_halinit.c | 394 ++++++++++++++---- > drivers/staging/r8188eu/hal/usb_ops_linux.c | 16 +- > drivers/staging/r8188eu/include/rtw_io.h | 18 +- > drivers/staging/r8188eu/os_dep/ioctl_linux.c | 168 +++++--- > 20 files changed, 941 insertions(+), 252 deletions(-) I agree with Philip: please, split this long patch. If I were you, I'd make one patch for each of the three rtw_read*() and a fourth patch for usb_read*(). > --- a/drivers/staging/r8188eu/core/rtw_io.c > +++ b/drivers/staging/r8188eu/core/rtw_io.c > @@ -34,44 +34,44 @@ jackson@realtek.com.tw > #define rtw_cpu_to_le16(val) cpu_to_le16(val) > #define rtw_cpu_to_le32(val) cpu_to_le32(val) Not related to your patch, these macros are useless and misleading. > -u8 _rtw_read8(struct adapter *adapter, u32 addr) > +u8 _rtw_read8(struct adapter *adapter, u32 addr, int *error) > { > u8 r_val; > struct io_priv *pio_priv = &adapter->iopriv; > struct intf_hdl *pintfhdl = &pio_priv->intf; > - u8 (*_read8)(struct intf_hdl *pintfhdl, u32 addr); > + u8 (*_read8)(struct intf_hdl *pintfhdl, u32 addr, int *error); > > > _read8 = pintfhdl->io_ops._read8; > - r_val = _read8(pintfhdl, addr); > + r_val = _read8(pintfhdl, addr, error); > > return r_val; > } I really don't like passing errors through arguments. Why don't you pass a storage location where the function save the byte read and instead use the return for errors? I think that this would result in a cleaner design. Furthermore, it is used everywhere in the kernel. > -u16 _rtw_read16(struct adapter *adapter, u32 addr) > +u16 _rtw_read16(struct adapter *adapter, u32 addr, int *error) > { > u16 r_val; > struct io_priv *pio_priv = &adapter->iopriv; > struct intf_hdl *pintfhdl = &pio_priv->intf; > - u16 (*_read16)(struct intf_hdl *pintfhdl, u32 addr); > + u16 (*_read16)(struct intf_hdl *pintfhdl, u32 addr, int *error); > > _read16 = pintfhdl->io_ops._read16; > > - r_val = _read16(pintfhdl, addr); > + r_val = _read16(pintfhdl, addr, error); > > return r_val; > } Same. > -u32 _rtw_read32(struct adapter *adapter, u32 addr) > +u32 _rtw_read32(struct adapter *adapter, u32 addr, int *error) > { > u32 r_val; > struct io_priv *pio_priv = &adapter->iopriv; > struct intf_hdl *pintfhdl = &pio_priv->intf; > - u32 (*_read32)(struct intf_hdl *pintfhdl, u32 addr); > + u32 (*_read32)(struct intf_hdl *pintfhdl, u32 addr, int *error); > > _read32 = pintfhdl->io_ops._read32; > > - r_val = _read32(pintfhdl, addr); > + r_val = _read32(pintfhdl, addr, error); > > return r_val; > } Same. I'm done for now: too many lines to read all at once :) Regards, Fabio