[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230826071654.564372-2-liaoyu15@huawei.com>
Date: Sat, 26 Aug 2023 15:16:54 +0800
From: Yu Liao <liaoyu15@...wei.com>
To: <dan.j.williams@...el.com>, <vishal.l.verma@...el.com>,
<dave.jiang@...el.com>, <ira.weiny@...el.com>, <rafael@...nel.org>
CC: <liaoyu15@...wei.com>, <liwei391@...wei.com>, <lenb@...nel.org>,
<robert.moore@...el.com>, <linux-acpi@...r.kernel.org>,
<nvdimm@...ts.linux.dev>, <linux-kernel@...r.kernel.org>
Subject: [PATCH v2 2/2] ACPI: NFIT: use struct_size() helper
Make use of the struct_size() helper instead of an open-coded version,
in order to avoid any potential type mistakes or integer overflows that,
in the worst scenario, could lead to heap overflows.
Signed-off-by: Yu Liao <liaoyu15@...wei.com>
Reviewed-by: Dave Jiang <dave.jiang@...el.com>
---
drivers/acpi/nfit/core.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/drivers/acpi/nfit/core.c b/drivers/acpi/nfit/core.c
index 305f590c54a8..2f7217600307 100644
--- a/drivers/acpi/nfit/core.c
+++ b/drivers/acpi/nfit/core.c
@@ -712,8 +712,7 @@ static bool add_spa(struct acpi_nfit_desc *acpi_desc,
}
}
- nfit_spa = devm_kzalloc(dev, sizeof(*nfit_spa) + sizeof_spa(spa),
- GFP_KERNEL);
+ nfit_spa = devm_kzalloc(dev, struct_size(nfit_spa, spa, 1), GFP_KERNEL);
if (!nfit_spa)
return false;
INIT_LIST_HEAD(&nfit_spa->list);
@@ -741,7 +740,7 @@ static bool add_memdev(struct acpi_nfit_desc *acpi_desc,
return true;
}
- nfit_memdev = devm_kzalloc(dev, sizeof(*nfit_memdev) + sizeof(*memdev),
+ nfit_memdev = devm_kzalloc(dev, struct_size(nfit_memdev, memdev, 1),
GFP_KERNEL);
if (!nfit_memdev)
return false;
@@ -812,8 +811,7 @@ static bool add_dcr(struct acpi_nfit_desc *acpi_desc,
return true;
}
- nfit_dcr = devm_kzalloc(dev, sizeof(*nfit_dcr) + sizeof(*dcr),
- GFP_KERNEL);
+ nfit_dcr = devm_kzalloc(dev, struct_size(nfit_dcr, dcr, 1), GFP_KERNEL);
if (!nfit_dcr)
return false;
INIT_LIST_HEAD(&nfit_dcr->list);
@@ -855,7 +853,7 @@ static size_t sizeof_idt(struct acpi_nfit_interleave *idt)
{
if (idt->header.length < sizeof(*idt))
return 0;
- return sizeof(*idt) + sizeof(u32) * idt->line_count;
+ return struct_size(idt, line_offset, idt->line_count);
}
static bool add_idt(struct acpi_nfit_desc *acpi_desc,
--
2.25.1
Powered by blists - more mailing lists