David rightly points out that, although GCC lets us get away with it,
using offsetof() with a non-constant member designator is not compliant
with the C standard. I'm responsible for a couple of those misuses, but
both in circumstances for which we now have a specific helper, so we can
use that to put things straight.

Suggested-by: David Laight <david.lai...@aculab.com>
Signed-off-by: Robin Murphy <robin.mur...@arm.com>
---
 drivers/iommu/arm-smmu.c | 3 +--
 drivers/iommu/iommu.c    | 2 +-
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
index 74e944bd4a8d..81d449451494 100644
--- a/drivers/iommu/arm-smmu.c
+++ b/drivers/iommu/arm-smmu.c
@@ -1484,8 +1484,7 @@ static int arm_smmu_add_device(struct device *dev)
        }
 
        ret = -ENOMEM;
-       cfg = kzalloc(offsetof(struct arm_smmu_master_cfg, smendx[i]),
-                     GFP_KERNEL);
+       cfg = kzalloc(struct_size(cfg, smendx, i), GFP_KERNEL);
        if (!cfg)
                goto out_free;
 
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 33a982e33716..ad28919e1452 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -2021,7 +2021,7 @@ int iommu_fwspec_add_ids(struct device *dev, u32 *ids, 
int num_ids)
        if (!fwspec)
                return -EINVAL;
 
-       size = offsetof(struct iommu_fwspec, ids[fwspec->num_ids + num_ids]);
+       size = struct_size(fwspec, ids, fwspec->num_ids + num_ids);
        if (size > sizeof(*fwspec)) {
                fwspec = krealloc(fwspec, size, GFP_KERNEL);
                if (!fwspec)
-- 
2.21.0.dirty

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

Reply via email to