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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B1C6C7EE25 for ; Mon, 12 Jun 2023 10:46:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235238AbjFLKqj (ORCPT ); Mon, 12 Jun 2023 06:46:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235331AbjFLKqO (ORCPT ); Mon, 12 Jun 2023 06:46:14 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCE323FCBC for ; Mon, 12 Jun 2023 03:30:52 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9E4AC623D4 for ; Mon, 12 Jun 2023 10:30:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B3A54C433A0; Mon, 12 Jun 2023 10:30:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1686565852; bh=S6UvpmEoy9EOUjqw9T1r7yj/xYJJ45oAwuCjJHur5WY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yF22U4IsiplpfcnAz7UgGqGVt0Eo2vcPlTXrOlfSCyt2wz5DmLs1erKKWw6P8kP4p Doco6oLm7cHjK7Fnc885fC7NzMNe+46cDMfNl3T/odCLBbh+1GYQQCB9ztJY8G4aFL SEvnFQpv7aez/Ffq5M6UHXQ7dhNBB4rBfZrpfpyw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, "Gustavo A. R. Silva" , "David S. Miller" , Sasha Levin Subject: [PATCH 5.4 06/45] neighbour: Replace zero-length array with flexible-array member Date: Mon, 12 Jun 2023 12:26:00 +0200 Message-ID: <20230612101654.887001240@linuxfoundation.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230612101654.644983109@linuxfoundation.org> References: <20230612101654.644983109@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Gustavo A. R. Silva [ Upstream commit 08ca27d027c238ed3f9b9968d349cebde44d99a6 ] The current codebase makes use of the zero-length array language extension to the C90 standard, but the preferred mechanism to declare variable-length types such as these ones is a flexible array member[1][2], introduced in C99: struct foo { int stuff; struct boo array[]; }; By making use of the mechanism above, we will get a compiler warning in case the flexible array does not occur last in the structure, which will help us prevent some kind of undefined behavior bugs from being inadvertently introduced[3] to the codebase from now on. Also, notice that, dynamic memory allocations won't be affected by this change: "Flexible array members have incomplete type, and so the sizeof operator may not be applied. As a quirk of the original implementation of zero-length arrays, sizeof evaluates to zero."[1] This issue was found with the help of Coccinelle. [1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html [2] https://github.com/KSPP/linux/issues/21 [3] commit 76497732932f ("cxgb3/l2t: Fix undefined behaviour") Signed-off-by: Gustavo A. R. Silva Signed-off-by: David S. Miller Stable-dep-of: ed779fe4c9b5 ("neighbour: fix unaligned access to pneigh_entry") Signed-off-by: Sasha Levin --- include/net/neighbour.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/net/neighbour.h b/include/net/neighbour.h index b6494e87c897c..729bdf710b7e0 100644 --- a/include/net/neighbour.h +++ b/include/net/neighbour.h @@ -174,7 +174,7 @@ struct pneigh_entry { struct net_device *dev; u8 flags; u8 protocol; - u8 key[0]; + u8 key[]; }; /* -- 2.39.2