From patchwork Tue May 16 23:14:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 13243986 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 659B3C77B75 for ; Tue, 16 May 2023 23:14:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231368AbjEPXOM (ORCPT ); Tue, 16 May 2023 19:14:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231324AbjEPXOJ (ORCPT ); Tue, 16 May 2023 19:14:09 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32D0776B7; Tue, 16 May 2023 16:14:02 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 779596353D; Tue, 16 May 2023 23:14:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9E049C433D2; Tue, 16 May 2023 23:13:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684278840; bh=qaUrBJYyxwwKBd2OY03a0I58URs2kzWjK7mA8MAbaNs=; h=Date:From:To:Subject:References:In-Reply-To:From; b=We6kEj/iS+wYQuFQ6YbadjiFGSz9PNkVtATeks2aNWZ4b/s0nHpOeYGVdeB+QoMv/ ZEgm8y7BP/0iYJeGUlWyGq9RkwgpL2eyi/1Pzd6+Q5g+AQIZRV77yQCv+kibn+wEFo YOYe6qZacSRxylsteDg3/DS5GFbuoUFdVjl9x9ptW44T1yxoSuJaKXnViTFzJq4sTP vcC5B/qvpuUMLdEPw4rgt8YyRuzN2I2hxgbwseyaoU1XpgMYO5FJaqsWF0BzDiljXp kK77kxVG0irXdy1iDpoKix2jzzE8awrzLmQM2o9nvVVZXL5htSBVBr2RKhwcqnOk4Q G4zGPIQHjJdnw== Date: Tue, 16 May 2023 17:14:49 -0600 From: "Gustavo A. R. Silva" To: Stanimir Varbanov , Vikash Garodia , Andy Gross , Bjorn Andersson , Konrad Dybcio , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH 2/2][next] media: venus: hfi_cmds: Use struct_size() helper Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org Prefer struct_size() over open-coded versions of idiom: sizeof(struct-with-flex-array) + sizeof(typeof-flex-array-elements) * count where count is the max number of items the flexible array is supposed to contain. Link: https://github.com/KSPP/linux/issues/160 Signed-off-by: Gustavo A. R. Silva Reviewed-by: Kees Cook --- drivers/media/platform/qcom/venus/hfi_cmds.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/media/platform/qcom/venus/hfi_cmds.c b/drivers/media/platform/qcom/venus/hfi_cmds.c index 21d1b3c90dc0..3f74d518ad08 100644 --- a/drivers/media/platform/qcom/venus/hfi_cmds.c +++ b/drivers/media/platform/qcom/venus/hfi_cmds.c @@ -209,8 +209,8 @@ int pkt_session_set_buffers(struct hfi_session_set_buffers_pkt *pkt, } } else { pkt->extradata_size = 0; - pkt->shdr.hdr.size = sizeof(*pkt) + - bd->num_buffers * sizeof(u32); + pkt->shdr.hdr.size = struct_size(pkt, buffer_info, + bd->num_buffers); for (i = 0; i < pkt->num_buffers; i++) pkt->buffer_info[i] = bd->device_addr; } @@ -251,8 +251,8 @@ int pkt_session_unset_buffers(struct hfi_session_release_buffer_pkt *pkt, pkt->extradata_size = 0; pkt->shdr.hdr.size = - sizeof(struct hfi_session_set_buffers_pkt) + - bd->num_buffers * sizeof(u32); + struct_size((struct hfi_session_set_buffers_pkt *)0, + buffer_info, bd->num_buffers); } pkt->response_req = bd->response_required;