Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2497966pxb; Tue, 24 Aug 2021 00:03:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyUaoagafWxsFDDkEHPwmopbC8ZPZ4jUbzocQbyeOgLG7lXiBblHBX9/cpSffCJBL0Kthkl X-Received: by 2002:a17:906:7714:: with SMTP id q20mr40100733ejm.551.1629788637764; Tue, 24 Aug 2021 00:03:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629788637; cv=none; d=google.com; s=arc-20160816; b=TZs9e4Ksl3TTbrZfn3yS9+I7OmMkoWO4OPT4yADWeKed424PpKxnktRg9w51IYzY8M OSfc/gbat+CjLl9JGUURisCIM5gGicaaYlObPAYz8V+t8i7JvetjlJfAMn4eIMxFNqnw creLRyMCiMXeGr1PRu57cnK7sU4Ht5oh/giissN05ZVL9KvlanwIBw6qVWXf3IY+ehAq 6a0HNnYPtkWb2nnW/dHMMiPUA7ZaOROrawhuzRsXhbm8ceSpDAIa9dbTsQ5m9IJrimlF llyvotcCZzyXlFm+5Y/ZF27ZPYbpiAs2v5Q05PL/NnIS45MUrFEy4Wzyo+PrFD8NBSYq JnNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=boY+WRSmsQxyePrjVtd+KgGUQgAKGN9c4xSQZsDSEfk=; b=pjiK+utgxuWV2KTNN8edg2qEW0M7NFlLlgQwkln3x/LoHS53u2vXoBQ8wYJpj8SrNZ VLpSGB2fIblqNHN88q7ziRIVtr6P34f8ZZRKdT3IFK2ZRhEmqdP7GpkQMJk/A+Zpuwu6 tVgbIb4DdpNtT2NRJ2q6zFWXeAt0YysmcOwCFEM6RzrqxIePCdcXzIfopvCcnSIyMgl2 Mt0NNPRmxMaOrfVFSIr3FCas18Pejv644emHDAGOg/ZiMeKk8ou7b+Wwyt+yyY+zh77t Pcsw5LOOweL+L8lWE6rBc9OR7cdK7nRDi6TowV3HbP0/jjOg54iDWNUwkn8hV1ihb0z9 T8RA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=tiQTu5qk; 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 16si18225839ejj.242.2021.08.24.00.03.35; Tue, 24 Aug 2021 00:03:57 -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=tiQTu5qk; 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 S233436AbhHXHCM (ORCPT + 99 others); Tue, 24 Aug 2021 03:02:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231483AbhHXHCK (ORCPT ); Tue, 24 Aug 2021 03:02:10 -0400 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D79EC061575 for ; Tue, 24 Aug 2021 00:01:26 -0700 (PDT) Received: by mail-lf1-x136.google.com with SMTP id p38so43387267lfa.0 for ; Tue, 24 Aug 2021 00:01:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=boY+WRSmsQxyePrjVtd+KgGUQgAKGN9c4xSQZsDSEfk=; b=tiQTu5qkMepoCpYNmDf5S9OEh7vMa/BOBctsTK/YAeAaS0Swkun2sk5rI4M+6n8AvC 9LOjCS66QrDxgYXv52+4MlAepNbqZs6NoEs/C7jlWKbXfM19Plu72yUW43emvNvtDIp1 HAZ+LSJ2nBzsvdsfAdCOLw9Z4RkIOFsunsGijEwNuKkONHD+zhv5ZKH+3T7WcDBkzRQA PLk1+T+e/ghzLwaEn3AxG0y5NZHHPkXaoGwv2u2WwMKl5GXNHlqnK+b/kkHLxPSTxoa+ 1WnhUdTE0lP1hLpWZfWE5/mf3MUNOrMyc50GrcJWk2VjkV8X9qneEtYUTGX1pXRUVyay x1Cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=boY+WRSmsQxyePrjVtd+KgGUQgAKGN9c4xSQZsDSEfk=; b=R04o9XwvPzNCG9hTEzTuwnpKPRzPH61IVBsLAJM9jWqPf1u9g5GCN4ILs31dDNLrEE /V7gsyrkPhPOXy26vOuJ32eEn17c7Va0+BsKi/S2pKDSRQWz+x2rzAFpVq2KXGlwKO3u jD2/ovNVsKpwJ1b9abaPTuP2gjPU2viuEczbiFZh94FiAAUeeRwdRfFlydLLqf5Q09/C tRNEV4AnoMS10w+Hu4sqdNjsXTACloJqapTH2Gx2IGOJxyIMZ1pXpQsUjv+LpQ9+uzvG rLB1JUFFq4q5D4V3+R9vqwqB3SbVzRqz/lfDTigFn59UPR66yfVsUHTskbuqCijijccX zuGQ== X-Gm-Message-State: AOAM533slHu92g+C/jlvddON2/B1ke9gJktqwwUcXJ1Q7SCxUEMhRKEZ 7ymwwbmKoIxS296YYS0N/yASkVjUuMOjIQ== X-Received: by 2002:a19:ac42:: with SMTP id r2mr27670685lfc.167.1629788484487; Tue, 24 Aug 2021 00:01:24 -0700 (PDT) Received: from [192.168.1.11] ([46.235.66.127]) by smtp.gmail.com with ESMTPSA id g27sm1782929lfh.300.2021.08.24.00.01.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 24 Aug 2021 00:01:24 -0700 (PDT) Subject: Re: [PATCH RFC v2 5/6] staging: r8188eu: add error handling of rtw_read32 To: Dan Carpenter Cc: Larry.Finger@lwfinger.net, phil@philpotter.co.uk, gregkh@linuxfoundation.org, straube.linux@gmail.com, fmdefrancesco@gmail.com, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org References: <9004eb2972780455db4cba9694244a2c572abba8.1629642658.git.paskripkin@gmail.com> <20210824065825.GL1931@kadam> From: Pavel Skripkin Message-ID: Date: Tue, 24 Aug 2021 10:01:23 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <20210824065825.GL1931@kadam> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 regards, Pavel Skripkin