linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iommu/dmar: Use struct_size() helper
@ 2019-04-18 18:46 Gustavo A. R. Silva
  2019-04-26 14:44 ` Joerg Roedel
  0 siblings, 1 reply; 3+ messages in thread
From: Gustavo A. R. Silva @ 2019-04-18 18:46 UTC (permalink / raw)
  To: Joerg Roedel; +Cc: iommu, linux-kernel, 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]);

with:

size = struct_size(info, path, level);

Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
---
 drivers/iommu/dmar.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iommu/dmar.c b/drivers/iommu/dmar.c
index 9c49300e9fb7..6d969a172fbb 100644
--- a/drivers/iommu/dmar.c
+++ b/drivers/iommu/dmar.c
@@ -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 {
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] iommu/dmar: Use struct_size() helper
  2019-04-18 18:46 [PATCH] iommu/dmar: Use struct_size() helper Gustavo A. R. Silva
@ 2019-04-26 14:44 ` Joerg Roedel
  2019-04-26 14:58   ` Gustavo A. R. Silva
  0 siblings, 1 reply; 3+ messages in thread
From: Joerg Roedel @ 2019-04-26 14:44 UTC (permalink / raw)
  To: Gustavo A. R. Silva; +Cc: iommu, linux-kernel

On Thu, Apr 18, 2019 at 01:46:24PM -0500, Gustavo A. R. Silva wrote:
> 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>

Applied, thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] iommu/dmar: Use struct_size() helper
  2019-04-26 14:44 ` Joerg Roedel
@ 2019-04-26 14:58   ` Gustavo A. R. Silva
  0 siblings, 0 replies; 3+ messages in thread
From: Gustavo A. R. Silva @ 2019-04-26 14:58 UTC (permalink / raw)
  To: Joerg Roedel; +Cc: iommu, linux-kernel



On 4/26/19 9:44 AM, Joerg Roedel wrote:
> On Thu, Apr 18, 2019 at 01:46:24PM -0500, Gustavo A. R. Silva wrote:
>> 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>
> 
> Applied, thanks.
> 

Great. :)

Thanks, Joerg.
--
Gustavo

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-04-26 14:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-18 18:46 [PATCH] iommu/dmar: Use struct_size() helper Gustavo A. R. Silva
2019-04-26 14:44 ` Joerg Roedel
2019-04-26 14:58   ` Gustavo A. R. Silva

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).