Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp463800pxj; Fri, 11 Jun 2021 03:41:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwUALfU7mqxAqhF+hqG1alcFwydWGQedJdxy8NSh+9x4EHu3dKVcJD2lvUMCpa7T2TVQ4yM X-Received: by 2002:a17:906:b84f:: with SMTP id ga15mr2987362ejb.372.1623408110668; Fri, 11 Jun 2021 03:41:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623408110; cv=none; d=google.com; s=arc-20160816; b=GejNi+wHx+43Fs+iCUxlzULH8uVQDWAgOtYDEgBFeZtdaC0NW/Q88Zo8qcwqO8Ul2c oSHz1pM/uX3FyuXZ852rZVR554KIHjr1GvUdZSqhcrCovyyha6SuUh86qfVm3V1Nc7jx T+tPYZ/pNeXgq6/QlCnzadSZTBbF4d0TH9ns7Pj/UunuEIHoMWm0aMWWRMUu4DOjgqm2 9Cs4iYgveJ/32tJf3hUGprYmjoZ4ajw0Xnqe9mvlvD080qC6iSVWIXzSfTR7VW79YGBQ JH2875F1x5eyNwBStD+1o9aDUutlWyCtISYWiBBUM0c9RXTo0g3KWkZ2kRA77kl7K8+K YTbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=1AdfyW6DxpraGwc8KyU3P/JHtnfbz+CtgKJFeZtdB8k=; b=iUSS8+mIvGdTJqUNpvJUeE9jgno5iKml5K5G7L3Bhfn+NcKtYFsPhm5lpFhlotjkWn 0/sxsxGMcBo+aTLt+dxDjMPG48Dqopx5U/oBAYZku2dTuW2vFFBPwJNDjKSzDjYIimHI qa/2VPARs4MIVbtkLK6sO5gNpC9su6aMyliNp8zHE4SiJxO3uPexUXPfWVDkP9nmYAh3 0xuoy/8WWaZmx1S/aBiAfg7qqw4DCmNdSoR17OfwdR0sIHX7az4eM0YAcV/C+amxjybI dR0LFJiI76T4aobWRxXLTJ16znmwtLegTQXqEcVh92Df8o+19ypQ2nIHHtaUBB3JF1rN M2lQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="1taqFB/t"; 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=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f2si4401311edu.428.2021.06.11.03.41.27; Fri, 11 Jun 2021 03:41:50 -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=@linuxfoundation.org header.s=korg header.b="1taqFB/t"; 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=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230382AbhFKKmP (ORCPT + 99 others); Fri, 11 Jun 2021 06:42:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:56624 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229633AbhFKKmP (ORCPT ); Fri, 11 Jun 2021 06:42:15 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id AEC61613E9; Fri, 11 Jun 2021 10:40:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623408002; bh=MYUJWhPp3HEvERW7H4uZGlgJHlDtwi5x6YdmBFvAfpw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=1taqFB/tgZcFpWEA3vdD/fsQbxQZfPuJSfBqFyoB3bDZv8hZdfH3e9gBOHDylsu8j 7YFtTlLaaB67dBP4AG8lt2D/fLLRjpAQ1dRcMZtjt8xhD1uqfy+m6Z6euxmQuQMqeQ DPXlw2SEwaw23jqSGwiOrZYZspvTZN4NAMjO45k8= Date: Fri, 11 Jun 2021 12:39:59 +0200 From: Greg KH To: Jiapeng Chong Cc: valentina.manea.m@gmail.com, shuah@kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] usbip: tools: usbipd: use ARRAY_SIZE for sockfdlist Message-ID: References: <1623406510-50900-1-git-send-email-jiapeng.chong@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1623406510-50900-1-git-send-email-jiapeng.chong@linux.alibaba.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 11, 2021 at 06:15:10PM +0800, Jiapeng Chong wrote: > Use ARRAY_SIZE instead of dividing sizeof array with sizeof an > element. > > Clean up the following coccicheck warning: > > ./tools/usb/usbip/src/usbipd.c:536:19-20: WARNING: Use ARRAY_SIZE. Why are you assuming that coccicheck should be run on userspace code? > > Reported-by: Abaci Robot > Signed-off-by: Jiapeng Chong > --- > Changes in v2: > -Add ARRAY_SIZE definition to usbip_common.h file. > > tools/usb/usbip/libsrc/usbip_common.h | 2 ++ > tools/usb/usbip/src/usbipd.c | 3 +-- > 2 files changed, 3 insertions(+), 2 deletions(-) > > diff --git a/tools/usb/usbip/libsrc/usbip_common.h b/tools/usb/usbip/libsrc/usbip_common.h > index 73a367a..4e12dc4 100644 > --- a/tools/usb/usbip/libsrc/usbip_common.h > +++ b/tools/usb/usbip/libsrc/usbip_common.h > @@ -101,6 +101,8 @@ > abort(); \ > } while (0) > > +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) Why is this needed? And if it really really is, why not define it in a way that ALL tools can use it. And then fix it up be correct for cases when you might call this when it is not an array. This is a very naive implementation. > + > struct usbip_usb_interface { > uint8_t bInterfaceClass; > uint8_t bInterfaceSubClass; > diff --git a/tools/usb/usbip/src/usbipd.c b/tools/usb/usbip/src/usbipd.c > index 48398a7..4826d13 100644 > --- a/tools/usb/usbip/src/usbipd.c > +++ b/tools/usb/usbip/src/usbipd.c > @@ -532,8 +532,7 @@ static int do_standalone_mode(int daemonize, int ipv4, int ipv6) > usbip_driver_close(driver); > return -1; > } > - nsockfd = listen_all_addrinfo(ai_head, sockfdlist, > - sizeof(sockfdlist) / sizeof(*sockfdlist)); > + nsockfd = listen_all_addrinfo(ai_head, sockfdlist, ARRAY_SIZE(sockfdlist)); The code here is correct, right? So this is not necessary unless you do this for all in-tree userspace tools at the same time. thanks, greg k-h