lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20190605202024.GA20848@embeddedor>
Date:   Wed, 5 Jun 2019 15:20:24 -0500
From:   "Gustavo A. R. Silva" <gustavo@...eddedor.com>
To:     Robert Moore <robert.moore@...el.com>,
        Erik Schmauss <erik.schmauss@...el.com>,
        "Rafael J. Wysocki" <rafael.j.wysocki@...el.com>,
        Len Brown <lenb@...nel.org>
Cc:     linux-acpi@...r.kernel.org, devel@...ica.org,
        linux-kernel@...r.kernel.org,
        "Gustavo A. R. Silva" <gustavo@...eddedor.com>
Subject: [PATCH] ACPICA: utids: Use struct_size() helper

One of the more common cases of allocation size calculations is finding
the size of a structure that has a zero-sized array at the end, along
with memory for some number of elements for that array. For example:

struct acpi_pnp_device_id_list {
	...
        struct acpi_pnp_device_id ids[1];       /* ID array */
};

Make use of the struct_size() helper instead of an open-coded version
in order to avoid any potential type mistakes.

So, replace the following form:

sizeof(struct acpi_pnp_device_id_list) + ((count - 1) * sizeof(struct acpi_pnp_device_id))

with:

struct_size(cid_list, ids, count - 1)

Signed-off-by: Gustavo A. R. Silva <gustavo@...eddedor.com>
---
Notice that checkpatch reports the following warning:

WARNING: line over 80 characters
#54: FILE: drivers/acpi/acpica/utids.c:265:
+	cid_list_size = struct_size(cid_list, ids, count - 1) + string_area_size;

The line above is 81-character long. So, I think we should be fine
with that, instead of split it into two lines.

Thanks

 Gustavo

 drivers/acpi/acpica/utids.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/acpi/acpica/utids.c b/drivers/acpi/acpica/utids.c
index e805abdd95b8..737aa6a8f362 100644
--- a/drivers/acpi/acpica/utids.c
+++ b/drivers/acpi/acpica/utids.c
@@ -202,7 +202,7 @@ acpi_ut_execute_CID(struct acpi_namespace_node *device_node,
 	char *next_id_string;
 	u32 string_area_size;
 	u32 length;
-	u32 cid_list_size;
+	size_t cid_list_size;
 	acpi_status status;
 	u32 count;
 	u32 i;
@@ -262,10 +262,7 @@ acpi_ut_execute_CID(struct acpi_namespace_node *device_node,
 	 * 2) Size of the CID PNP_DEVICE_ID array +
 	 * 3) Size of the actual CID strings
 	 */
-	cid_list_size = sizeof(struct acpi_pnp_device_id_list) +
-	    ((count - 1) * sizeof(struct acpi_pnp_device_id)) +
-	    string_area_size;
-
+	cid_list_size = struct_size(cid_list, ids, count - 1) + string_area_size;
 	cid_list = ACPI_ALLOCATE_ZEROED(cid_list_size);
 	if (!cid_list) {
 		status = AE_NO_MEMORY;
-- 
2.21.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ