drivers/iommu: use struct_size over open coded arithmetic
Subsystems (2)
PATCH 1/1 drivers/iommu: use struct_size over open coded arithmetic
From: Minghao Chi (CGEL ZTE) <[email protected]>
Replace zero-length array with flexible-array member and make use of the struct_size() helper in kzalloc(). For example:
struct viommu_request {
...
unsigned int len;
char buf[];
};Make use of the struct_size() helper instead of an open-coded version in order to avoid any potential type mistakes.
Reported-by Zeal Robot <[email protected]>
Signed-off-by Minghao Chi (CGEL ZTE) <[email protected]>
--- drivers/iommu/virtio-iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/virtio-iommu.c +1 -1
@@ -231,7 +231,7 @@ static int __viommu_add_req(struct viommu_dev *viommu, void *buf, size_t len,if (write_offset <=0 )return -EINVAL ; - req =kzalloc (sizeof (*req) + len,GFP_ATOMIC ); + req =kzalloc (struct_size (req, buf, len),GFP_ATOMIC );if (!req)return -ENOMEM ;
Signature · 1 line
2.25.1