Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1234607pxb; Sun, 22 Aug 2021 10:00:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzl5SZNra5WGc8kn7RlazSHXZSzWoTpkn/uCOCoHJ6DHDSXY/7AC7BF4qe7Skgqcj6O/1kT X-Received: by 2002:a05:6e02:1b88:: with SMTP id h8mr20527300ili.237.1629651629607; Sun, 22 Aug 2021 10:00:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629651629; cv=none; d=google.com; s=arc-20160816; b=bNcO7+N7pfwAIz7bsZuN4rRLWgSVaxRV7T49Q1QYiRl9f36btIyedK9s1y95NrT5Tb oUTAlcxKsAlFs6A+ve6+JG4FfnToVaRV5Xqtp2B378OasuviM/PLLJRTf7Xb4yYBS+jZ fZjUSD81JkkTzWBfeFhwSJlZJ9QicB/VmADJGVH/d6Pbz1lXQkCWdfIohmsANs0MhKYp cUGLONQQdYTvJzdaIkh3KuQcK+DllwMRT/UXfUFoC17sMnaWYU4WcYqE48FgMeEvwA/S /xkpxOxsIZvFVTTWYQK0h+YPrCb2DdzOXX24thcW4o7kAxu0MVbfCR1jXzYuYuhNLXLF +/8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=4fl0rKcBEkOFPXLebLuOrlJkc1BIWC9NyBr1+v3C+iw=; b=w/zDls57uRzLiXOC0ybvfuHJm1atJqC/FR0dvU+K/bUwV5BGX3csbTfg3TmOK9oPH6 hbG2JSJcngG/7ITa9mtvavBIAS49rQKcY79iEypwoFhVNfkmGfk6o0qsdiaDmu2JDrF5 r/vjZ8mMGKAj7b6mreL9+xpn2km1rRQb0dhVKIFYCL2UNZxOncdKqybAlA4pKokn+dRL HGVK/cG8+j+HX+IaawwCq01YKtE11pVFKHbZkXHoj6z8oftWrfC+YG3F1ytPW1K82exK Ez4r4ThYYbkVACfsvQovYOjtas7/SY+FvQa1b2YqLoO/1674cStw+/fUG+CcWaUUkuTG EAhg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o1si11537263ill.7.2021.08.22.10.00.16; Sun, 22 Aug 2021 10:00:29 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230336AbhHVQ7f (ORCPT + 99 others); Sun, 22 Aug 2021 12:59:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229586AbhHVQ7e (ORCPT ); Sun, 22 Aug 2021 12:59:34 -0400 Received: from viti.kaiser.cx (viti.kaiser.cx [IPv6:2a01:238:43fe:e600:cd0c:bd4a:7a3:8e9f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CFE3C061575 for ; Sun, 22 Aug 2021 09:58:53 -0700 (PDT) Received: from martin by viti.kaiser.cx with local (Exim 4.89) (envelope-from ) id 1mHqo0-0008Gc-AP; Sun, 22 Aug 2021 18:58:44 +0200 Date: Sun, 22 Aug 2021 18:58:44 +0200 From: Martin Kaiser To: Michael Straube Cc: Greg Kroah-Hartman , Larry Finger , Phillip Potter , Dan Carpenter , linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH 08/10] staging: r8188eu: clean up the usb_writeN Message-ID: <20210822165844.2h6yt42ejshw7tnc@viti.kaiser.cx> References: <20210821164859.4351-1-martin@kaiser.cx> <20210821164859.4351-8-martin@kaiser.cx> <6593f24b-8986-df5f-e2ba-5358360939df@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6593f24b-8986-df5f-e2ba-5358360939df@gmail.com> User-Agent: NeoMutt/20170113 (1.7.2) Sender: Martin Kaiser Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Michael, Thus wrote Michael Straube (straube.linux@gmail.com): > On 8/21/21 6:48 PM, Martin Kaiser wrote: > > Remove unnecessary variables, check the length. > > Signed-off-by: Martin Kaiser > > --- > > drivers/staging/r8188eu/hal/usb_ops_linux.c | 15 +++++---------- > > 1 file changed, 5 insertions(+), 10 deletions(-) > > diff --git a/drivers/staging/r8188eu/hal/usb_ops_linux.c b/drivers/staging/r8188eu/hal/usb_ops_linux.c > > index e01f1ac19596..5408383ccec3 100644 > > --- a/drivers/staging/r8188eu/hal/usb_ops_linux.c > > +++ b/drivers/staging/r8188eu/hal/usb_ops_linux.c > > @@ -151,20 +151,15 @@ static int usb_write32(struct intf_hdl *pintfhdl, u32 addr, u32 val) > > static int usb_writeN(struct intf_hdl *pintfhdl, u32 addr, u32 length, u8 *pdata) > > { > > - u16 wvalue; > > - u16 len; > > + u16 wvalue = (u16)(addr & 0x0000ffff); > > u8 buf[VENDOR_CMD_MAX_DATA_LEN] = {0}; > > - int ret; > > - > > + if (length > VENDOR_CMD_MAX_DATA_LEN) > > + return -EINVAL; > > - wvalue = (u16)(addr & 0x0000ffff); > > - len = length; > > - memcpy(buf, pdata, len); > > + memcpy(buf, pdata, length); > Hi Martin, shouldn't this be > memcpy(buf, pdata, (length & 0xffff)); I don't think this makes any difference. I've already checked that length <= VENDOR_CMD_MAX_DATA_LEN, which is 254. memcpy takes a size_t parameter for the number of bytes to copy. length will not overflow this. Best regards, Martin