[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 1/6] firmware-qemu_fw_cfg: Use kmalloc_array() in fw
From: |
SF Markus Elfring |
Subject: |
[Qemu-devel] [PATCH 1/6] firmware-qemu_fw_cfg: Use kmalloc_array() in fw_cfg_register_dir_entries() |
Date: |
Sun, 18 Sep 2016 14:50:56 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 |
From: Markus Elfring <address@hidden>
Date: Sun, 18 Sep 2016 09:39:31 +0200
* A multiplication for the size determination of a memory allocation
indicated that an array data structure should be processed.
Thus use the corresponding function "kmalloc_array".
This issue was detected by using the Coccinelle software.
* Replace the specification of a data structure by a pointer dereference
to make the corresponding size determination a bit safer according to
the Linux coding style convention.
* Delete the local variable "dir_size" which became unnecessary with
this refactoring.
Signed-off-by: Markus Elfring <address@hidden>
---
drivers/firmware/qemu_fw_cfg.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/firmware/qemu_fw_cfg.c b/drivers/firmware/qemu_fw_cfg.c
index 0e20116..e69653e 100644
--- a/drivers/firmware/qemu_fw_cfg.c
+++ b/drivers/firmware/qemu_fw_cfg.c
@@ -491,17 +491,17 @@ static int fw_cfg_register_dir_entries(void)
int ret = 0;
u32 count, i;
struct fw_cfg_file *dir;
- size_t dir_size;
fw_cfg_read_blob(FW_CFG_FILE_DIR, &count, 0, sizeof(count));
count = be32_to_cpu(count);
- dir_size = count * sizeof(struct fw_cfg_file);
-
- dir = kmalloc(dir_size, GFP_KERNEL);
+ dir = kmalloc_array(count, sizeof(*dir), GFP_KERNEL);
if (!dir)
return -ENOMEM;
- fw_cfg_read_blob(FW_CFG_FILE_DIR, dir, sizeof(count), dir_size);
+ fw_cfg_read_blob(FW_CFG_FILE_DIR,
+ dir,
+ sizeof(count),
+ sizeof(*dir) * count);
for (i = 0; i < count; i++) {
dir[i].size = be32_to_cpu(dir[i].size);
--
2.10.0
- [Qemu-devel] [PATCH 0/6] firmware-qemu_fw_cfg: Fine-tuning for four function implementations, SF Markus Elfring, 2016/09/18
- [Qemu-devel] [PATCH 1/6] firmware-qemu_fw_cfg: Use kmalloc_array() in fw_cfg_register_dir_entries(),
SF Markus Elfring <=
- [Qemu-devel] [PATCH 2/6] firmware-qemu_fw_cfg: Improve a size determination in fw_cfg_register_file(), SF Markus Elfring, 2016/09/18
- [Qemu-devel] [PATCH 3/6] firmware-qemu_fw_cfg: Rename jump labels in fw_cfg_register_file(), SF Markus Elfring, 2016/09/18
- [Qemu-devel] [PATCH 4/6] firmware-qemu_fw_cfg: Improve a size determination in fw_cfg_build_symlink(), SF Markus Elfring, 2016/09/18
- [Qemu-devel] [PATCH 5/6] firmware-qemu_fw_cfg: Rename jump labels in fw_cfg_sysfs_probe(), SF Markus Elfring, 2016/09/18
- [Qemu-devel] [PATCH 6/6] firmware-qemu_fw_cfg: Move a variable assignment in fw_cfg_sysfs_probe(), SF Markus Elfring, 2016/09/18
- Re: [Qemu-devel] [PATCH 0/6] firmware-qemu_fw_cfg: Fine-tuning for four function implementations, Gabriel L. Somlo, 2016/09/20