linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Kees Cook <keescook@chromium.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Kees Cook <keescook@chromium.org>,
	Dan Williams <dan.j.williams@intel.com>,
	Alex Sierra <alex.sierra@amd.com>,
	Felix Kuehling <Felix.Kuehling@amd.com>,
	"Matthew Wilcox (Oracle)" <willy@infradead.org>,
	Shiyang Ruan <ruansy.fnst@fujitsu.com>,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>,
	linux-mm@kvack.org, Alistair Popple <apopple@nvidia.com>,
	Joao Martins <joao.m.martins@oracle.com>,
	Mike Rapoport <rppt@kernel.org>,
	linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org
Subject: [PATCH] memremap: Replace 0-length array with flexible array
Date: Thu,  5 Jan 2023 14:01:53 -0800	[thread overview]
Message-ID: <20230105220151.never.343-kees@kernel.org> (raw)

Zero-length arrays are deprecated[1]. Replace struct ethtool_rxnfc's
"rule_locs" 0-length array with a flexible array. Detected with GCC 13,
using -fstrict-flex-arrays=3:

In file included from include/asm-generic/memory_model.h:5,
                 from arch/x86/include/asm/page.h:86,
                 from arch/x86/include/asm/thread_info.h:12,
                 from include/linux/thread_info.h:60,
                 from arch/x86/include/asm/preempt.h:9,
                 from include/linux/preempt.h:78,
                 from include/linux/spinlock.h:56,
                 from include/linux/mmzone.h:8,
                 from include/linux/gfp.h:7,
                 from include/linux/mm.h:7,
                 from mm/sparse-vmemmap.c:21:
In function 'reuse_compound_section',
    inlined from 'vmemmap_populate_compound_pages' at mm/sparse-vmemmap.c:407:6,
    inlined from '__populate_section_memmap' at mm/sparse-vmemmap.c:463:7:
mm/sparse-vmemmap.c:376:39: warning: array subscript <unknown> is outside array bounds of 'struct range[0]' [-Warray-bounds=]
  376 |                 PHYS_PFN(pgmap->ranges[pgmap->nr_range].start);
      |                          ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
include/linux/pfn.h:22:43: note: in definition of macro 'PHYS_PFN'
   22 | #define PHYS_PFN(x)     ((unsigned long)((x) >> PAGE_SHIFT))
      |                                           ^
In file included from include/linux/mm.h:31:
include/linux/memremap.h: In function '__populate_section_memmap':
include/linux/memremap.h:138:30: note: while referencing 'ranges'
  138 |                 struct range ranges[0];
      |                              ^~~~~~

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays

Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Alex Sierra <alex.sierra@amd.com>
Cc: Felix Kuehling <Felix.Kuehling@amd.com>
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>
Cc: Shiyang Ruan <ruansy.fnst@fujitsu.com>
Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: linux-mm@kvack.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 include/linux/memremap.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/memremap.h b/include/linux/memremap.h
index 7fcaf3180a5b..1314d9c5f05b 100644
--- a/include/linux/memremap.h
+++ b/include/linux/memremap.h
@@ -135,7 +135,7 @@ struct dev_pagemap {
 	int nr_range;
 	union {
 		struct range range;
-		struct range ranges[0];
+		DECLARE_FLEX_ARRAY(struct range, ranges);
 	};
 };
 
-- 
2.34.1



             reply	other threads:[~2023-01-05 22:02 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-05 22:01 Kees Cook [this message]
2023-01-05 22:14 ` Gustavo A. R. Silva
2023-01-05 22:39   ` Kees Cook
2023-01-05 22:41   ` Kees Cook
2023-01-05 23:14     ` Gustavo A. R. Silva
2023-01-05 23:37       ` Kees Cook
2023-01-06  0:02         ` Gustavo A. R. Silva
2023-01-05 22:14 ` Dan Williams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230105220151.never.343-kees@kernel.org \
    --to=keescook@chromium.org \
    --cc=Felix.Kuehling@amd.com \
    --cc=akpm@linux-foundation.org \
    --cc=alex.sierra@amd.com \
    --cc=apopple@nvidia.com \
    --cc=dan.j.williams@intel.com \
    --cc=gustavoars@kernel.org \
    --cc=joao.m.martins@oracle.com \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=rppt@kernel.org \
    --cc=ruansy.fnst@fujitsu.com \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox