Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp108137pxb; Tue, 24 Aug 2021 21:44:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx0MtIIkz49y1z6RLESBhDwB1GvDjT28nraDJnd/4ve2ctgidBEj6wlwDcMpR04RO/e49Yj X-Received: by 2002:a17:906:c7c2:: with SMTP id dc2mr45073143ejb.472.1629866692620; Tue, 24 Aug 2021 21:44:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629866692; cv=none; d=google.com; s=arc-20160816; b=QVCp02/bkcF7egmaoVCa0cZbl33qCN4EXO4uhDAEmf4G3hK2EatTK6igHDbI+CMEZB b70jFPQK4qCrtOCFLb+Bw6mSsvnu5TuWnMxNe37Z4evnHh9TRosC8jKoSwKTCFTDbIwz p79yoAHBj/d54bHtpepgvf8FuOnEVhaq5uy95iDCSjeq84Ywx/Op9/FvZFQGISvR5WIJ 5npNvN0sUhErgDRu0XHFrogfh8jeeNai67BTqO0vklFl02Nf9Iys4UVH7A+pdFPo41jR OAVGRcZT05zAxceJvJCw38wKGI/BQXKkJ1nad4V7BYhUod5IdMhJ22oeRVsy9mKsieuH G5+w== 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=DVs+REb065XqkXSI+Yu50Se8g0p/Fqtt0gWQBb3WmuQ=; b=bziHK74f+w2eoN1CqyM8fYzyyq1hyBSfU3vIy+UDJVUhaO4UZcS582NuZYQTLVE8BJ HXXrkAPTXqra72tPUC1FZCzU2mYHPe7Nl3yS5cVUy6P7yU26aUsTI+nTCCT59s12wCU3 wzVMUeFyOt4M5Gk0B9OP9R5mVNiTKzjVkrGhtwveXHU+ilHtlFlwpczOs8v76KQIPNbv VvidvrMWE2hD9pQzEKPEu7F7BMRTDgEr57uY7UjTf8NIcuLKKnX3RcVAcNBKDXc2gk/a EJk6pvVaV2CqZuNfSE8Q7zWk3Q8cVJnSwreXdHOQ2RVfbbTcR+KEK7r0E9S4GZ0U0bHE Va4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=FG0vFRLE; 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 hp36si1499263ejc.19.2021.08.24.21.44.30; Tue, 24 Aug 2021 21:44:52 -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=FG0vFRLE; 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 S230057AbhHYElZ (ORCPT + 99 others); Wed, 25 Aug 2021 00:41:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229500AbhHYElX (ORCPT ); Wed, 25 Aug 2021 00:41:23 -0400 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 688DCC061757 for ; Tue, 24 Aug 2021 21:40:38 -0700 (PDT) Received: by mail-ej1-x631.google.com with SMTP id me10so20513876ejb.11 for ; Tue, 24 Aug 2021 21:40:38 -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=DVs+REb065XqkXSI+Yu50Se8g0p/Fqtt0gWQBb3WmuQ=; b=FG0vFRLE2hJ4UIWorO3vLdb5chKPQM/8JffhiDTMnSlH4j018y5+QL2z2cWKTomNKA NjToakFX9B2UT7Ol3WaYlrmQ56eTRFycjcTxkvNvEqqgNDN/L48rTUsIGCJ1chpYHyzO KF8WGu8MZAfA09jVXgVmNInfhcUzM3jdiol1tJ6zOTq9vLEkCh3aN4P3IjVgn54E09SE MR0g3+RCqFKHbJ3nvvybzJcChTSLVPksAfIpTzLnojQwtFIVwk/dqy3PElvKLG38q9fK FvgUD/mk5cszTZIigR74znk/Lohjr+AtJ4pHTDTCyVPkJzKV8sy/y/uTIz7dT53Mumtn kGbA== 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=DVs+REb065XqkXSI+Yu50Se8g0p/Fqtt0gWQBb3WmuQ=; b=f8ywxWfekOrpygbTJEjXRHI+aiTowVq/G4+sqiyuDWGDzl3jBMgbekWFjb2tIVEH73 w3SKqSKnz4d3T5X43qjxj+rP8Kf9Jb/xA6ohkfIaf2MDBcxhoHvIJG1QGRQgYwWLP+d8 Y5kRtJtggaPwWssQsK98adubZl6PwxiuYb1Lcq6y1cuBWa2NnJvX/Mq6VnWOSA7ikLV3 gELKHcqV1mms6rR32AbphIfGybpz+vNnq4dW6kSJz92aKsn3Mc1OV8RTjPhu90YPydb8 /e30xub9csw+v5LaQVqo8WRMy9bQTuiiex7Dlx7uujPh3KxV3z+vjbqr4XsiCJGzqOJX t55A== X-Gm-Message-State: AOAM533U5/Yi+VXgAeC44OLAoFn8oEbO3vJveDdX6UYeb0Vib63Rw8R2 8o9JTJ6oMWIUyaOKzJHJU54= X-Received: by 2002:a17:907:10cc:: with SMTP id rv12mr9552230ejb.423.1629866437030; Tue, 24 Aug 2021 21:40:37 -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 h10sm12718423edb.74.2021.08.24.21.40.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Aug 2021 21:40:36 -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 v3 5/6] staging: r8188eu: add error handling of rtw_read32 Date: Wed, 25 Aug 2021 06:40:35 +0200 Message-ID: <4686124.Q29LyLEoG2@localhost.localdomain> In-Reply-To: <93bf46ce2d0ce12e94672acf28b64dc341fde038.1629789580.git.paskripkin@gmail.com> References: <93bf46ce2d0ce12e94672acf28b64dc341fde038.1629789580.git.paskripkin@gmail.com> 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:42 AM CEST Pavel Skripkin wrote: > _rtw_read32 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_read32() 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 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, &tmp, len, requesttype); > + if (res < 0) { > + dev_err(dvobj_to_dev(pintfhdl->pintf_dev), "Failed to read 32 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_read32() will always return -EIO even if usbctrl_vendorreq () succeeds. > + dev_err(dvobj_to_dev(pintfhdl->pintf_dev), > + "Failed to read 32 bytes, could read only %d bytes\n", res); > + return -EIO; > + } > + > + *data = le32_to_cpu(tmp); > > - return le32_to_cpu(data); > + return 0; > } > > [...] > Regards, Fabio