From: "Verma, Vishal L" <vishal.l.verma@intel.com>
To: "Williams, Dan J" <dan.j.williams@intel.com>,
"linux-nvdimm@lists.01.org" <linux-nvdimm@lists.01.org>
Cc: "efremov@linux.com" <efremov@linux.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
lkp <lkp@intel.com>,
"julia.lawall@inria.fr" <julia.lawall@inria.fr>,
"linux-acpi@vger.kernel.org" <linux-acpi@vger.kernel.org>
Subject: Re: [PATCH] ACPI: NFIT: Fix flexible_array.cocci warnings
Date: Tue, 5 Jan 2021 21:28:45 +0000 [thread overview]
Message-ID: <3c31c3328f569f15f03de9eb8d1b6a9ae4862893.camel@intel.com> (raw)
In-Reply-To: <160988059854.2071197.11821323682102566548.stgit@dwillia2-desk3.amr.corp.intel.com>
On Tue, 2021-01-05 at 13:03 -0800, Dan Williams wrote:
> Julia and 0day report:
>
> Zero-length and one-element arrays are deprecated, see
> Documentation/process/deprecated.rst
> Flexible-array members should be used instead.
>
> However, a straight conversion to flexible arrays yields:
>
> drivers/acpi/nfit/core.c:2276:4: error: flexible array member in a struct with no named members
> drivers/acpi/nfit/core.c:2287:4: error: flexible array member in a struct with no named members
>
> Instead, just use plain arrays not embedded a flexible arrays.
This reads a bit awkwardly, maybe:
"Just use plain arrays instead of embedded flexible arrays."
Other than that, the patch looks looks good:
Reviewed-by: Vishal Verma <vishal.l.verma@intel.com>
>
> Cc: Denis Efremov <efremov@linux.com>
> Reported-by: kernel test robot <lkp@intel.com>
> Reported-by: Julia Lawall <julia.lawall@inria.fr>
> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
> ---
> drivers/acpi/nfit/core.c | 75 +++++++++++++++++-----------------------------
> 1 file changed, 28 insertions(+), 47 deletions(-)
>
> diff --git a/drivers/acpi/nfit/core.c b/drivers/acpi/nfit/core.c
> index b11b08a60684..8c5dde628405 100644
> --- a/drivers/acpi/nfit/core.c
> +++ b/drivers/acpi/nfit/core.c
> @@ -2269,40 +2269,24 @@ static const struct attribute_group *acpi_nfit_region_attribute_groups[] = {
>
>
>
>
> /* enough info to uniquely specify an interleave set */
> struct nfit_set_info {
> - struct nfit_set_info_map {
> - u64 region_offset;
> - u32 serial_number;
> - u32 pad;
> - } mapping[0];
> + u64 region_offset;
> + u32 serial_number;
> + u32 pad;
> };
>
>
>
>
> struct nfit_set_info2 {
> - struct nfit_set_info_map2 {
> - u64 region_offset;
> - u32 serial_number;
> - u16 vendor_id;
> - u16 manufacturing_date;
> - u8 manufacturing_location;
> - u8 reserved[31];
> - } mapping[0];
> + u64 region_offset;
> + u32 serial_number;
> + u16 vendor_id;
> + u16 manufacturing_date;
> + u8 manufacturing_location;
> + u8 reserved[31];
> };
>
>
>
>
> -static size_t sizeof_nfit_set_info(int num_mappings)
> -{
> - return sizeof(struct nfit_set_info)
> - + num_mappings * sizeof(struct nfit_set_info_map);
> -}
> -
> -static size_t sizeof_nfit_set_info2(int num_mappings)
> -{
> - return sizeof(struct nfit_set_info2)
> - + num_mappings * sizeof(struct nfit_set_info_map2);
> -}
> -
> static int cmp_map_compat(const void *m0, const void *m1)
> {
> - const struct nfit_set_info_map *map0 = m0;
> - const struct nfit_set_info_map *map1 = m1;
> + const struct nfit_set_info *map0 = m0;
> + const struct nfit_set_info *map1 = m1;
>
>
>
>
> return memcmp(&map0->region_offset, &map1->region_offset,
> sizeof(u64));
> @@ -2310,8 +2294,8 @@ static int cmp_map_compat(const void *m0, const void *m1)
>
>
>
>
> static int cmp_map(const void *m0, const void *m1)
> {
> - const struct nfit_set_info_map *map0 = m0;
> - const struct nfit_set_info_map *map1 = m1;
> + const struct nfit_set_info *map0 = m0;
> + const struct nfit_set_info *map1 = m1;
>
>
>
>
> if (map0->region_offset < map1->region_offset)
> return -1;
> @@ -2322,8 +2306,8 @@ static int cmp_map(const void *m0, const void *m1)
>
>
>
>
> static int cmp_map2(const void *m0, const void *m1)
> {
> - const struct nfit_set_info_map2 *map0 = m0;
> - const struct nfit_set_info_map2 *map1 = m1;
> + const struct nfit_set_info2 *map0 = m0;
> + const struct nfit_set_info2 *map1 = m1;
>
>
>
>
> if (map0->region_offset < map1->region_offset)
> return -1;
> @@ -2361,22 +2345,22 @@ static int acpi_nfit_init_interleave_set(struct acpi_nfit_desc *acpi_desc,
> return -ENOMEM;
> import_guid(&nd_set->type_guid, spa->range_guid);
>
>
>
>
> - info = devm_kzalloc(dev, sizeof_nfit_set_info(nr), GFP_KERNEL);
> + info = devm_kcalloc(dev, nr, sizeof(*info), GFP_KERNEL);
> if (!info)
> return -ENOMEM;
>
>
>
>
> - info2 = devm_kzalloc(dev, sizeof_nfit_set_info2(nr), GFP_KERNEL);
> + info2 = devm_kcalloc(dev, nr, sizeof(*info2), GFP_KERNEL);
> if (!info2)
> return -ENOMEM;
>
>
>
>
> for (i = 0; i < nr; i++) {
> struct nd_mapping_desc *mapping = &ndr_desc->mapping[i];
> - struct nfit_set_info_map *map = &info->mapping[i];
> - struct nfit_set_info_map2 *map2 = &info2->mapping[i];
> struct nvdimm *nvdimm = mapping->nvdimm;
> struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
> - struct acpi_nfit_memory_map *memdev = memdev_from_spa(acpi_desc,
> - spa->range_index, i);
> + struct nfit_set_info *map = &info[i];
> + struct nfit_set_info2 *map2 = &info2[i];
> + struct acpi_nfit_memory_map *memdev =
> + memdev_from_spa(acpi_desc, spa->range_index, i);
> struct acpi_nfit_control_region *dcr = nfit_mem->dcr;
>
>
>
>
> if (!memdev || !nfit_mem->dcr) {
> @@ -2395,23 +2379,20 @@ static int acpi_nfit_init_interleave_set(struct acpi_nfit_desc *acpi_desc,
> }
>
>
>
>
> /* v1.1 namespaces */
> - sort(&info->mapping[0], nr, sizeof(struct nfit_set_info_map),
> - cmp_map, NULL);
> - nd_set->cookie1 = nd_fletcher64(info, sizeof_nfit_set_info(nr), 0);
> + sort(info, nr, sizeof(*info), cmp_map, NULL);
> + nd_set->cookie1 = nd_fletcher64(info, sizeof(*info) * nr, 0);
>
>
>
>
> /* v1.2 namespaces */
> - sort(&info2->mapping[0], nr, sizeof(struct nfit_set_info_map2),
> - cmp_map2, NULL);
> - nd_set->cookie2 = nd_fletcher64(info2, sizeof_nfit_set_info2(nr), 0);
> + sort(info2, nr, sizeof(*info2), cmp_map2, NULL);
> + nd_set->cookie2 = nd_fletcher64(info2, sizeof(*info2) * nr, 0);
>
>
>
>
> /* support v1.1 namespaces created with the wrong sort order */
> - sort(&info->mapping[0], nr, sizeof(struct nfit_set_info_map),
> - cmp_map_compat, NULL);
> - nd_set->altcookie = nd_fletcher64(info, sizeof_nfit_set_info(nr), 0);
> + sort(info, nr, sizeof(*info), cmp_map_compat, NULL);
> + nd_set->altcookie = nd_fletcher64(info, sizeof(*info) * nr, 0);
>
>
>
>
> /* record the result of the sort for the mapping position */
> for (i = 0; i < nr; i++) {
> - struct nfit_set_info_map2 *map2 = &info2->mapping[i];
> + struct nfit_set_info2 *map2 = &info2[i];
> int j;
>
>
>
>
> for (j = 0; j < nr; j++) {
> _______________________________________________
> Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
> To unsubscribe send an email to linux-nvdimm-leave@lists.01.org
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org
next prev parent reply other threads:[~2021-01-05 21:28 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-05 21:03 [PATCH] ACPI: NFIT: Fix flexible_array.cocci warnings Dan Williams
2021-01-05 21:28 ` Verma, Vishal L [this message]
2021-01-05 21:51 ` Dan Williams
-- strict thread matches above, loose matches on Subject: below --
2020-12-22 21:09 [PATCH] ACPI: NFIT: fix " Julia Lawall
2020-12-24 18:12 ` 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=3c31c3328f569f15f03de9eb8d1b6a9ae4862893.camel@intel.com \
--to=vishal.l.verma@intel.com \
--cc=dan.j.williams@intel.com \
--cc=efremov@linux.com \
--cc=julia.lawall@inria.fr \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nvdimm@lists.01.org \
--cc=lkp@intel.com \
/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