diff mbox series

x86/PCI: Use struct_size()

Message ID 00a5cc2cd322e7dea26579916ac6dda9c637aa57.1684518118.git.christophe.jaillet@wanadoo.fr
State New
Headers show
Series x86/PCI: Use struct_size() | expand

Commit Message

Christophe JAILLET May 19, 2023, 5:42 p.m. UTC
Use struct_size() instead of hand-writing it. It is less verbose, more
robust and more informative.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 arch/x86/pci/irq.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Bjorn Helgaas July 13, 2023, 4:34 p.m. UTC | #1
On Fri, May 19, 2023 at 07:42:28PM +0200, Christophe JAILLET wrote:
> Use struct_size() instead of hand-writing it. It is less verbose, more
> robust and more informative.
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Applied to pci/misc for v6.6, thanks!

> ---
>  arch/x86/pci/irq.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
> index a498b847d740..0de436316a1d 100644
> --- a/arch/x86/pci/irq.c
> +++ b/arch/x86/pci/irq.c
> @@ -136,14 +136,14 @@ static inline struct irq_routing_table *pirq_convert_irt_table(u8 *addr,
>  	if (ir->signature != IRT_SIGNATURE || !ir->used || ir->size < 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]);
> +	size = struct_size(rt, slots, ir->used);
>  	rt = kzalloc(size, GFP_KERNEL);
>  	if (!rt)
>  		return NULL;
> -- 
> 2.34.1
>
diff mbox series

Patch

diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
index a498b847d740..0de436316a1d 100644
--- a/arch/x86/pci/irq.c
+++ b/arch/x86/pci/irq.c
@@ -136,14 +136,14 @@  static inline struct irq_routing_table *pirq_convert_irt_table(u8 *addr,
 	if (ir->signature != IRT_SIGNATURE || !ir->used || ir->size < 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]);
+	size = struct_size(rt, slots, ir->used);
 	rt = kzalloc(size, GFP_KERNEL);
 	if (!rt)
 		return NULL;