From patchwork Fri Nov 24 23:08:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sam James X-Patchwork-Id: 13468222 X-Patchwork-Delegate: mkubecek+ethtool@suse.cz Authentication-Results: smtp.subspace.kernel.org; dkim=none Received: from smtp.gentoo.org (mail.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E0011733 for ; Fri, 24 Nov 2023 15:08:19 -0800 (PST) From: Sam James To: netdev@vger.kernel.org Cc: Sam James Subject: [ethtool PATCH] netlink: fix -Walloc-size Date: Fri, 24 Nov 2023 23:08:04 +0000 Message-ID: <20231124230810.1656050-1-sam@gentoo.org> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: mkubecek+ethtool@suse.cz GCC 14 introduces a new -Walloc-size included in -Wextra which gives: ``` netlink/strset.c: In function ‘get_perdev_by_ifindex’: netlink/strset.c:121:16: warning: allocation of insufficient size ‘1’ for type ‘struct perdev_strings’ with size ‘648’ [-Walloc-size] 121 | perdev = calloc(sizeof(*perdev), 1); | ^ ``` The calloc prototype is: ``` void *calloc(size_t nmemb, size_t size); ``` So, just swap the number of members and size arguments to match the prototype, as we're initialising 1 struct of size `sizeof(*perdev)`. GCC then sees we're not doing anything wrong. This is consistent with other use in the codebase too. Signed-off-by: Sam James Reviewed-by: Przemek Kitszel --- netlink/strset.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netlink/strset.c b/netlink/strset.c index fbc9c17..949d597 100644 --- a/netlink/strset.c +++ b/netlink/strset.c @@ -118,7 +118,7 @@ static struct perdev_strings *get_perdev_by_ifindex(int ifindex) return perdev; /* not found, allocate and insert into list */ - perdev = calloc(sizeof(*perdev), 1); + perdev = calloc(1, sizeof(*perdev)); if (!perdev) return NULL; perdev->ifindex = ifindex;