Skip to contentSkip to conversation

iommu/dmar: Use struct_size() helper

PATCH Applied Gustavo A. R. Silva 2 participants 3 messages Apr 18, 2019 – Apr 26, 2019 IOMMU

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iommu/dmar: 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, in particular in the context in which this code is being used.

So, replace code of the following form:

size = sizeof(*info) + level * sizeof(info->path[0]);

with:

size = struct_size(info, path, level);

---
 drivers/iommu/dmar.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/dmar.c +1 -1
index 9c49300e9fb7..6d969a172fbb 100644
@@ -145,7 +145,7 @@ dmar_alloc_pci_notify_info(struct pci_dev *dev, unsigned long event)
 		for (tmp = dev; tmp; tmp = tmp->bus->self)
 			level++;
 
-	size = sizeof(*info) + level * sizeof(info->path[0]);
+	size = struct_size(info, path, level);
 	if (size <= sizeof(dmar_pci_notify_info_buf)) {
 		info = (struct dmar_pci_notify_info *)dmar_pci_notify_info_buf;
 	} else {
Signature · 1 line
2.21.0
maintainer Applied
#1 lore raw
Quoted 6 lines · Gustavo A. R. Silva

Make use of the struct_size() helper instead of an open-coded version in order to avoid any potential type mistakes, in particular in the context in which this code is being used.

So, replace code of the following form:

Quoted 7 lines

size = sizeof(*info) + level * sizeof(info->path[0]);

with:

size = struct_size(info, path, level);

Applied, thanks.

#2 lore raw
Quoted 9 lines · Joerg Roedel
Quoted 8 lines · Gustavo A. R. Silva

Make use of the struct_size() helper instead of an open-coded version in order to avoid any potential type mistakes, in particular in the context in which this code is being used.

So, replace code of the following form:

size = sizeof(*info) + level * sizeof(info->path[0]);

Quoted 8 lines
Quoted 5 lines

with:

size = struct_size(info, path, level);

Applied, thanks.

Great. :)

Thanks, Joerg.
--
Gustavo