iommu/vt-d: Use struct_size() helper
authorGustavo A. R. Silva <gustavo@embeddedor.com>
Thu, 18 Apr 2019 18:46:24 +0000 (13:46 -0500)
committerJoerg Roedel <jroedel@suse.de>
Fri, 26 Apr 2019 14:43:21 +0000 (16:43 +0200)
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);

Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
drivers/iommu/dmar.c

index 9c49300e9fb76ace67cee9930356794234de81d0..6d969a172fbb3491df6b1d38cc6f3b33cd99a4d0 100644 (file)
@@ -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 {