Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A5E08C433F5 for ; Wed, 10 Nov 2021 18:47:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8AA02611AD for ; Wed, 10 Nov 2021 18:47:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233500AbhKJSuR (ORCPT ); Wed, 10 Nov 2021 13:50:17 -0500 Received: from mail.kernel.org ([198.145.29.99]:47598 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232960AbhKJSsz (ORCPT ); Wed, 10 Nov 2021 13:48:55 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id DAB2F61211; Wed, 10 Nov 2021 18:46:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1636569967; bh=/fTmYjv0NMcHwpgQTRMHv5+sOyo5hbKetklmzTtChyc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xflUFcbPIcsLDFeEQ7Dnuc+k++yDKXielYOvCX59gtegWDky8xRDvsDw2we30KYM4 IRj1Wx1QDpgSEQATlsveDKk8lDwjT1KMKAuSXfYajlpKKpzHHwf7CIUsAilhrjb8KZ AdRYVXL2y/9lCePXPQY+KQA0Odj4jPsx8bHOY9/M= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Gustavo A. R. Silva" , Dennis Dalessandro , Jason Gunthorpe , Mike Marciniszyn Subject: [PATCH 4.14 06/22] IB/qib: Use struct_size() helper Date: Wed, 10 Nov 2021 19:43:26 +0100 Message-Id: <20211110182002.874158603@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211110182002.666244094@linuxfoundation.org> References: <20211110182002.666244094@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Gustavo A. R. Silva commit 829ca44ecf60e9b6f83d0161a6ef10c1304c5060 upstream. 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 the following form: sizeof(*pkt) + sizeof(pkt->addr[0])*n with: struct_size(pkt, addr, n) Also, notice that variable size is unnecessary, hence it is removed. This code was detected with the help of Coccinelle. Signed-off-by: Gustavo A. R. Silva Reviewed-by: Dennis Dalessandro Signed-off-by: Jason Gunthorpe Signed-off-by: Mike Marciniszyn Signed-off-by: Greg Kroah-Hartman --- drivers/infiniband/hw/qib/qib_user_sdma.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/drivers/infiniband/hw/qib/qib_user_sdma.c +++ b/drivers/infiniband/hw/qib/qib_user_sdma.c @@ -41,6 +41,7 @@ #include #include #include +#include #include "qib.h" #include "qib_user_sdma.h" @@ -908,10 +909,11 @@ static int qib_user_sdma_queue_pkts(cons } if (frag_size) { - int pktsize, tidsmsize, n; + int tidsmsize, n; + size_t pktsize; n = npages*((2*PAGE_SIZE/frag_size)+1); - pktsize = sizeof(*pkt) + sizeof(pkt->addr[0])*n; + pktsize = struct_size(pkt, addr, n); /* * Determine if this is tid-sdma or just sdma.