From mboxrd@z Thu Jan 1 00:00:00 1970 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=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 42D31C433DB for ; Thu, 14 Jan 2021 10:56:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E08E1239CF for ; Thu, 14 Jan 2021 10:56:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728735AbhANK4G (ORCPT ); Thu, 14 Jan 2021 05:56:06 -0500 Received: from smtprelay0007.hostedemail.com ([216.40.44.7]:59406 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726416AbhANK4A (ORCPT ); Thu, 14 Jan 2021 05:56:00 -0500 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay07.hostedemail.com (Postfix) with ESMTP id 2FC50181D3025; Thu, 14 Jan 2021 10:55:18 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-HE-Tag: rake95_1e0310527526 X-Filterd-Recvd-Size: 3103 Received: from [192.168.1.159] (unknown [47.151.137.21]) (Authenticated sender: joe@perches.com) by omf20.hostedemail.com (Postfix) with ESMTPA; Thu, 14 Jan 2021 10:55:15 +0000 (UTC) Message-ID: Subject: Re: [Intel-wired-lan] [net-next] net: iavf: Use the ARRAY_SIZE macro for aq_to_posix From: Joe Perches To: "Jankowski, Konrad0" , Wei Xu , "netdev@vger.kernel.org" Cc: "salil.mehta@huawei.com" , "jinying@hisilicon.com" , "tangkunshan@huawei.com" , "huangdaode@hisilicon.com" , "john.garry@huawei.com" , "linux-kernel@vger.kernel.org" , "linuxarm@huawei.com" , "shameerali.kolothum.thodi@huawei.com" , "zhangyi.ac@huawei.com" , "intel-wired-lan@lists.osuosl.org" , "jonathan.cameron@huawei.com" , Jakub Kicinski , "liguozhu@hisilicon.com" , "davem@davemloft.net" , "shiju.jose@huawei.com" Date: Thu, 14 Jan 2021 02:55:13 -0800 In-Reply-To: References: <1599641471-204919-1-git-send-email-xuwei5@hisilicon.com> Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.38.1-1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Thu, 2021-01-14 at 09:57 +0000, Jankowski, Konrad0 wrote: > > -----Original Message----- > > From: Intel-wired-lan On Behalf Of Wei Xu [] > > Use the ARRAY_SIZE macro to calculate the size of an array. > > This code was detected with the help of Coccinelle. [] > > diff --git a/drivers/net/ethernet/intel/iavf/iavf_adminq.h [] > > @@ -120,7 +120,7 @@ static inline int iavf_aq_rc_to_posix(int aq_ret, int aq_rc) > >   if (aq_ret == IAVF_ERR_ADMIN_QUEUE_TIMEOUT) > >   return -EAGAIN; > > > > - if (!((u32)aq_rc < (sizeof(aq_to_posix) / sizeof((aq_to_posix)[0])))) > > + if (!((u32)aq_rc < ARRAY_SIZE(aq_to_posix))) > >   return -ERANGE; > > > >   return aq_to_posix[aq_rc]; > > Tested-by: Konrad Jankowski I think several things are poor here. This function shouldn't really be a static inline as it would just bloat whatever uses it and should just be a typical function in a utility .c file. And it doesn't seem this function is used at all so it should be deleted. aq_to_posix should be static const. And if it's really necessary, I think it would be simpler to read using code without the cast and negation. if (aq_rc < 0 || aq_rc >= ARRAY_SIZE(aq_to_posix)) return -ERANGE;