From patchwork Fri Jun 11 10:15:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiapeng Chong X-Patchwork-Id: 458898 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D727AC48BE0 for ; Fri, 11 Jun 2021 10:15:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BD56261073 for ; Fri, 11 Jun 2021 10:15:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230407AbhFKKRm (ORCPT ); Fri, 11 Jun 2021 06:17:42 -0400 Received: from out30-44.freemail.mail.aliyun.com ([115.124.30.44]:45410 "EHLO out30-44.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230356AbhFKKRk (ORCPT ); Fri, 11 Jun 2021 06:17:40 -0400 X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R831e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=alimailimapcm10staff010182156082; MF=jiapeng.chong@linux.alibaba.com; NM=1; PH=DS; RN=5; SR=0; TI=SMTPD_---0Uc2YY7m_1623406522; Received: from j63c13417.sqa.eu95.tbsite.net(mailfrom:jiapeng.chong@linux.alibaba.com fp:SMTPD_---0Uc2YY7m_1623406522) by smtp.aliyun-inc.com(127.0.0.1); Fri, 11 Jun 2021 18:15:41 +0800 From: Jiapeng Chong To: valentina.manea.m@gmail.com Cc: shuah@kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Jiapeng Chong Subject: [PATCH v2] usbip: tools: usbipd: use ARRAY_SIZE for sockfdlist Date: Fri, 11 Jun 2021 18:15:10 +0800 Message-Id: <1623406510-50900-1-git-send-email-jiapeng.chong@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org 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. 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])) + 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)); freeaddrinfo(ai_head); if (nsockfd <= 0) { err("failed to open a listening socket");