[2/2] x86/PCI: Slightly simplify pirq_convert_irt_table()
Commit Message
'size' if computed twice. *ir and *it being the same, the result is the
same as well.
While at it, also use struct_size() which is less verbose, more robust and
more informative.
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
arch/x86/pci/irq.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
Comments
On Sat, 6 May 2023, Christophe JAILLET wrote:
> 'size' if computed twice. *ir and *it being the same, the result is the
> same as well.
There is no `it' data object in this function; I presume you meant `rt'.
Then `*ir' and `*rt' are of a different type each, hence the calculations
are not the same. If they were the same, the function wouldn't be needed
at all in the first place. Therefore, NAK.
> While at it, also use struct_size() which is less verbose, more robust and
> more informative.
This might be a valuable clean-up, thank you, please submit separately.
Maciej
@@ -140,14 +140,13 @@ static inline struct irq_routing_table *pirq_convert_irt_table(u8 *addr,
if (ir->signature != IRT_SIGNATURE || !ir->used || entries < ir->used)
return NULL;
- size = sizeof(*ir) + ir->used * sizeof(ir->slots[0]);
+ size = struct_size(ir, slots, ir->used);
if (size > limit - addr)
return NULL;
DBG(KERN_DEBUG "PCI: $IRT Interrupt Routing Table found at 0x%lx\n",
__pa(ir));
- size = sizeof(*rt) + ir->used * sizeof(rt->slots[0]);
rt = kzalloc(size, GFP_KERNEL);
if (!rt)
return NULL;