Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2812273pxb; Tue, 24 Aug 2021 08:10:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz85eJkOe7pb4ZTKoTh4D7Wm6UzvKKWJnmvOIg2h6j1zi5cppOOyN2eOd/dXArDJNHf/MFe X-Received: by 2002:a05:6e02:12a2:: with SMTP id f2mr26691079ilr.222.1629817825318; Tue, 24 Aug 2021 08:10:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629817825; cv=none; d=google.com; s=arc-20160816; b=Xvu768vyQJutr2fMcH42G8kCI4ewYnOsg3wQsu83kT92ungLCcFUz2BdpF31eJVuo0 XFISgPC5Tkxt8bNoiD1M3p6ztRYhrfLpDJL/1UHCWdam3m2/qJVdUfQfNwzCFBymaVwU j+A/rTrLV2CVLvuiszYUYkiKqA54EnuXZOWHMfNiw/ydh9suxngwbM4dAtoBCSLRRWk4 KtNUU3R43IpJD8G1zIjzyk1EqAHcqR25WSe8DlwUKhOzGLTTKC4lI2UwkBgmGA05Hx/I 2f0rDaouNroUfA5JbYdloK6KBma/hA0DgU/HYEi69+kXi83t4AhDzVevHMSWG/UzDr4Y 04BQ== 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=+hULPFAkyAPdS/vngzljMkYnL+FEm5rIj4ZI5jqPlpo=; b=rcNTpGhhQkbgI3P3YM0KrVyTD0rrctMKyRaTQ//sRzQtGVv7E/7gIoqJUFVH6NT/sT PUEZyHMTDX19nV0rE2cmf6pDBiJPMgHzRhEEBXthcnX4fs8iXAYa5jvjoJYRX2nLybgz v65DNBDm5Xo0eMsi4t4eL6KJLd78ICRjTtE6pFsQfjQ38Y0xABP18Tiq+OcxMikRpSrT 7PnI1jWW6pfbcWbnrmEb8fpwk0lzPGJPHPWGweRibm7HM2ur92ERKW9K+0G461EYdZci z8SABlI/CiaZZB+zkMckpzEDEJEVPaiv/BFR3wJgx88zoknUOk2/tPQHv3ZNgQx0Bjp5 0ojA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=EQMJ6qdH; 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 h9si17223315ioh.20.2021.08.24.08.10.03; Tue, 24 Aug 2021 08:10:25 -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=EQMJ6qdH; 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 S238150AbhHXPHu (ORCPT + 99 others); Tue, 24 Aug 2021 11:07:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238142AbhHXPHt (ORCPT ); Tue, 24 Aug 2021 11:07:49 -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 6BF8DC061757 for ; Tue, 24 Aug 2021 08:07:05 -0700 (PDT) Received: by mail-ed1-x531.google.com with SMTP id s25so19505041edw.0 for ; Tue, 24 Aug 2021 08:07:05 -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=+hULPFAkyAPdS/vngzljMkYnL+FEm5rIj4ZI5jqPlpo=; b=EQMJ6qdHjnSDnKUPsqFMI4lpIr9Q9caVjs/72KugI9xSH+BHi/jHdSbMCsgPIBrEel TCAtD6YIH6ZvJ33I5Ni2ctlyYq3AxXcBvO/XjBRQk9sTwK+RfM2BIJkSkyYm/9tMY7lW kreBho9k+nyZjW64sCqq6IVidV3QuSTFjuotJrC+6KykAsQQpGw+ThHRQXrYgOarCstK r/ZF8WnylnD2H7sZGLSAOYFu/Kankea2T8qNGRoboy2ZAww3ALoN8nHH7RE+7d4qV4h8 BkFXKj6xGDM+kIabXDEgUxZT2XzC6b182ilrNMzhmfpMIsEvFVKpHWpB4SUS4vNWgt0v FUmQ== 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=+hULPFAkyAPdS/vngzljMkYnL+FEm5rIj4ZI5jqPlpo=; b=geOWWlHc7W+OszkW2NWNORg04HUu2e2nrkdibD6SZhHMM2az9jKFO3nLO2kD9w0gZT XRvAOOwhJXugS/8+cTjmQxEyU5WyXyOipgc3YiFJu8DmxKa+ru/wUqwwd6o22fJqIybc GxOa4MxzbWEEIKrl6uO4DYiY4j/hUDkpNG3JVWrahOvV6yMCJDT6n/vUFR3MGvcJ5A5G idhePhFptx0aOo903ea31oEKuynmouJE+QC0pKBtdZkQK4aBLvaKGFj2zNIPqy4nhUAn lv5j5+6GcdaOvhGRDE6KCyLsWxsJVQMNJulqIls/D6dStBoyOd9Ug1WLHmGEaKHNNalL vs/A== X-Gm-Message-State: AOAM532D1e/pprm68G+lyuCBMLclLx/zz8oC+/EhmV588OTztmsZkOMV ttnZMQQiy7zMbMJru5zI2Cs= X-Received: by 2002:a05:6402:8ce:: with SMTP id d14mr43765546edz.228.1629817624076; Tue, 24 Aug 2021 08:07:04 -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 n23sm11971876eds.41.2021.08.24.08.07.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Aug 2021 08:07:03 -0700 (PDT) From: "Fabio M. De Francesco" To: Dan Carpenter , Pavel Skripkin Cc: Larry.Finger@lwfinger.net, phil@philpotter.co.uk, gregkh@linuxfoundation.org, straube.linux@gmail.com, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH RFC v2 5/6] staging: r8188eu: add error handling of rtw_read32 Date: Tue, 24 Aug 2021 17:07:02 +0200 Message-ID: <1655559.bbUi69aIZD@localhost.localdomain> In-Reply-To: References: <20210824065825.GL1931@kadam> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="utf-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tuesday, August 24, 2021 9:01:23 AM CEST Pavel Skripkin wrote: > On 8/24/21 9:58 AM, Dan Carpenter wrote: > > On Sun, Aug 22, 2021 at 05:36:01PM +0300, Pavel Skripkin wrote: > >> -static u32 usb_read32(struct intf_hdl *pintfhdl, u32 addr) > >> +static int usb_read32(struct intf_hdl *pintfhdl, u32 addr, u32 *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 = 4; > >> > >> - usbctrl_vendorreq(pintfhdl, wvalue, &data, len, requesttype); > >> + res = usbctrl_vendorreq(pintfhdl, wvalue, &data, len, requesttype); > >> + if (res < 0) { > >> + dev_err(dvobj_to_dev(pintfhdl->pintf_dev), "Failed to read 32 bytes: %d\n", res); > > > > Add a return here. Try to keep the success path and the failure path > > as separate as possible. Try to keep the success path indented at one > > tab so the code looks like this: > > > > success(); > > success(); > > if (fail) > > handle_failure(); > > success(); > > success(); > > > > Try to deal with exceptions as quickly as possible so that the reader > > has less to remember. > > > >> + } else { > >> + /* Noone cares about positive return value */ > > > > Ugh... That's unfortunate. We should actually care. The > > usbctrl_vendorreq() has an information leak where it copies len (4) > > bytes of data even if usb_control_msg() is not able to read len bytes. > > > > The best fix would be to remove the information leak and make > > usbctrl_vendorreq() return zero on success. In other words something > > like: > > > > status = usb_control_msg(); > > if (status < 0) > > return status; > > if (status != len) > > return -EIO; > > status = 0; > > > > I see, thank you for reviewing, will fix in v3! I fully forgot, that > usb_control_msg() can receive only part of the message :) With the use of the new API I think that you don't have anymore partial messages. usb_control_msg() returns the number of bytes transferred, while usb_control_msg_recv/send return only 0 if successful otherwise a negative error number. Regards, Fabio > With regards, > Pavel Skripkin >