Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp104198pxb; Tue, 24 Aug 2021 21:36:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwwsc7XlLY5jvyvB/FndrLUpsiIrfZWr3U7Nj5TzWgooff11px25X5sE8Xm2+cbSbWFHTB0 X-Received: by 2002:a17:906:2bc2:: with SMTP id n2mr44000020ejg.455.1629866213962; Tue, 24 Aug 2021 21:36:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629866213; cv=none; d=google.com; s=arc-20160816; b=cbpcHq/N3JiLop6bibmhzErieXU3YzhzJk4d2+5MvctgRB6N9Wez9Khmj2uOQNoEcU cVLFHC4Gm5dwqJgd5888LbZV6NaFIV4IXe6UiWgQyQYCYBxFHz0D1KphFx+XFw48QClI iIg2tRwXtMeYyBBE+f5JoFZP1VidG3AfmDW2N0dMh3bXqnJZHlUY/4MPKTDHdUH/xkHB bMi4faApn6S8s/PqecsP5h/aQ7owgifjxg7CpFTcgt0wksOWx7pl9o06g0WeSBQhAcD9 l0cRKyLuhkFdXMIsamNB1zq1Z36Qctck7lJ1Wn0e+YeVWvoTH6Uy5Hw2+Np0eNPep/YH /DHg== 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=jnVkSyJgN3E1sDFilQH189RfendGOGfI1/ufZRZKyB0=; b=pDyxMwv60g1mX49TW02QS6SJ8ONscmwWVPdhEA9XPSB6NuDDtJ0dJ88bF6V3j033KS +59wdZNCZWMnu0XY55zu1QFTjRvOnM7nEHQrxwPqjh6RFCQi2Pe44sTF5vb2HQI0Rqla YQbTuGGfIGcFvsmz8HtKyCGyP8YmYYi9CFvSTnOiAYJkbhR4AbqNUQR8TBBEAq+DoHiZ d94GQ0b+go0QCy0xxDTDfz/hmwo+GqebqfJc/BfSAzkYkfC1khC+K9B4y/RNjmI6o+Fp cNnQ6Ll3IsiVERu2dmr3R/ZB/6W8ytGfW6hpYK+jv6nsK99iXsQDj+aCgKG1g5Pi9Sk7 cbHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Cco65m4H; 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 i18si24921114edc.271.2021.08.24.21.36.30; Tue, 24 Aug 2021 21:36:53 -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=Cco65m4H; 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 S229765AbhHYEf6 (ORCPT + 99 others); Wed, 25 Aug 2021 00:35:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229500AbhHYEf5 (ORCPT ); Wed, 25 Aug 2021 00:35:57 -0400 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7D96C061757 for ; Tue, 24 Aug 2021 21:35:11 -0700 (PDT) Received: by mail-ej1-x630.google.com with SMTP id h9so48858794ejs.4 for ; Tue, 24 Aug 2021 21:35:11 -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=jnVkSyJgN3E1sDFilQH189RfendGOGfI1/ufZRZKyB0=; b=Cco65m4HBzBTv5b8p+0hDWptfNctJ7xmLI2VkvaRSCIRXeS2lcwfYCJx1TakW/zrB/ vBm+AhQNFZuLtPcsAieUcgf+06flF3tDmudZ+wNG/LwyweO6IgiIga+cK2VEv6kVphZa bWwVskoq6mgw31zYgX9ocyPqW8jPOMtp1H1Q2dsd2fRu9mGHy8UTESBoRmy9Pa1CltWT AyBHLW2Y4zVpLep+696g9UTNSo27PvANqWC5NrMZ1tKEwFRYB4r2/Fbuz7CQ4kQLSwNh I168HLpgNZdTkp5GqGy7Rn3XBehwH6nMCvQgUrdIXkOV2AU5usEx2gfJnr691a10XB7L XaVA== 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=jnVkSyJgN3E1sDFilQH189RfendGOGfI1/ufZRZKyB0=; b=YbOM1vGb4X3m2xvThK7AvBQT86mR1r4Gg/1QZjbhualfOBfYVVkhZDCMiY5cwmdgEd rM12onXrEz0lVKmZx8HUpsusKONHajN11Z+ZhKWHwzVNWs3eHnV/rdX03Gl+45/M/CzJ rmmpdBPksOUVSe1jkzqxrkmz4Aiob3ZmJUz4fgWmKqwb7lYVRtNElvHE7WJWbenoAzeS 2wMUJJ+Mrm/wVU7nZO3AoqN6oH8E2yK4alhDAzclFR+SmIotN/Jsqga72DQcZpdmdw4h XI5+4it5J9xEIgRNZ6tcvCLFFJe7SepOViRYIZeMAzcsEmQPgj1B+hzthhW35ei+jp6s ZcPw== X-Gm-Message-State: AOAM531BZGIekSQ7/x648i38XYmEG62iiAo/CIzu+1/NprXLdUH2YoTz nO+B9mRy5vAnnH5XNUSJxUs= X-Received: by 2002:a17:906:b183:: with SMTP id w3mr30349862ejy.394.1629866110430; Tue, 24 Aug 2021 21:35:10 -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 v12sm10292649ejq.36.2021.08.24.21.35.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Aug 2021 21:35:09 -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 Subject: Re: [PATCH v3 4/6] staging: r8188eu: add error handling of rtw_read16 Date: Wed, 25 Aug 2021 06:35:08 +0200 Message-ID: <1665728.ljvk3MsED4@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 Tuesday, August 24, 2021 9:27:35 AM CEST Pavel Skripkin wrote: > _rtw_read16 function can fail in case of usb transfer failure. But > previous function prototype wasn't designed to return an error to > caller. It can cause a lot uninit value bugs all across the driver code, > since rtw_read16() returns local stack variable to caller. > > Fix it by changing the prototype of this function. Now it returns an > int: 0 on success, negative error value on failure and callers should pass > the pointer to storage location for register value. > > Signed-off-by: Pavel Skripkin > > [...] > > -static u16 usb_read16(struct intf_hdl *pintfhdl, u32 addr) > +static int usb_read16(struct intf_hdl *pintfhdl, u32 addr, u16 *data) > { > u8 requesttype; > u16 wvalue; > u16 len; > - __le32 data; > + int res; > + __le32 tmp; > + > + if (WARN_ON(unlikely(!data))) > + return -EINVAL; > > requesttype = 0x01;/* read_in */ > wvalue = (u16)(addr & 0x0000ffff); > len = 2; > - usbctrl_vendorreq(pintfhdl, wvalue, &data, len, requesttype); > + res = usbctrl_vendorreq(pintfhdl, wvalue, &tmp, len, requesttype); > + if (res < 0) { > + dev_err(dvobj_to_dev(pintfhdl->pintf_dev), "Failed to read 16 bytes: %d\n", res); > + return res; > + } else if (res != len) { Dear Pavel, Please note that if and when my patch "Use usb_control_msg_recv / send () in usbctrl_vendorreq ()" will be merged, "if (res! = len)" will always evaluate 'true' and usb_read16 () will always return -EIO even if usbctrl_vendorreq () succeeds. > + dev_err(dvobj_to_dev(pintfhdl->pintf_dev), > + "Failed to read 16 bytes, could read only %d bytes\n", res); > + return -EIO; > + } > > - return (u16)(le32_to_cpu(data) & 0xffff); > + *data = le32_to_cpu(tmp) & 0xffff; > + > + return 0; > } [...] Regards, Fabio