From patchwork Wed Jul 12 20:42:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 119334 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp1418003vqm; Wed, 12 Jul 2023 14:12:07 -0700 (PDT) X-Google-Smtp-Source: APBJJlH6rhmt/VH+DuTiy3SmCUDWwQKFpjierDPWbQlMAfSJRoLT1h5jF7NigEKdwVJZS9b1nXu1 X-Received: by 2002:a05:6a00:2e09:b0:676:20f8:be41 with SMTP id fc9-20020a056a002e0900b0067620f8be41mr18802990pfb.16.1689196327405; Wed, 12 Jul 2023 14:12:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689196327; cv=none; d=google.com; s=arc-20160816; b=spBIzePZGJSAks7IHa28p+UWWOjXSZ3hdKIt26OWcLAiP8Ldets9iiHnYA9+2vNKim Wdz5nQJ41Qbaomtv/VC8hh3pcypZJSKSAMyQwMv7u3yeddxQ+rSzjPERfEFvLVBb2IZM hOL/NRB4N4frVYGUTNtMlhewugQ8aAN7V52Eth+mX8OIN/2ROgS3XHd9RNdygjoWWXLn pzdA+W6HMJl/enwr/yE35ybTyxDMOXn77IKXrKyOyVmdSUiPr24HCW8COiK3ghuKGrPW UqWYicj1haYhnbPipp+U6z2TwGwifw4mLBs6Sh1y/2PLTZB6gmhZmipnDs/K+XsWUyi0 nF6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=v9j0m2cKfHRT+pm9joHgv4l8r7uaiOqt0NGOeHOYA8M=; fh=i3fqh/KAe/chuhDhfVBJ+00B6irw1xrc3UjmkDDWJFA=; b=yibxPx2J8NGaqqN89crn7qwmu3wuNCMGAOm8WWmRbgwBK411m1/aj3qjwbo2FhkR1Q pwxydUphERIiuW+iNX25ChheYEzK4Mnx8m2WTP37kexSVP0TnFYsOWoI2yEG8DzwsuAc Em1wQMOWpjQogr3g7aU9ByEPUDlDl6p9fzObYk6dDdgmDBbCKBmwOV4fyB+Bi+nBtUck JHjKCWL9HWiQhUbplFRW9zmGsXyvUX4o1zOa6RH3QtlE5CmWhSkWPAIWn7Q9h+mWIICL dKtv6vqr6BDmKZ9i1h+rPuDtUUKRukX5WiBT/f62UOWyV8mJa4+BlZ2vPWXjg38fJ4zx xrwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=sa5XFfPa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g22-20020a056a0023d600b0067b2f265d2fsi3820409pfc.83.2023.07.12.14.11.54; Wed, 12 Jul 2023 14:12:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=sa5XFfPa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232476AbjGLUm0 (ORCPT + 99 others); Wed, 12 Jul 2023 16:42:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231979AbjGLUmY (ORCPT ); Wed, 12 Jul 2023 16:42:24 -0400 Received: from smtp.smtpout.orange.fr (smtp-24.smtpout.orange.fr [80.12.242.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD908C0 for ; Wed, 12 Jul 2023 13:42:22 -0700 (PDT) Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id JgfAqVIqQFZ5SJgfBq4nYd; Wed, 12 Jul 2023 22:42:20 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1689194540; bh=v9j0m2cKfHRT+pm9joHgv4l8r7uaiOqt0NGOeHOYA8M=; h=From:To:Cc:Subject:Date; b=sa5XFfPaI2fZWc9fzGFbfzFz57NPBZt7bmu3cVXQNTnJ0tOv812lXxhxWpzLXRB6Z +GZyzSaUURGY6jEncLTqqkyI+Y+At6p3l2z/i8/PJp4icbGp5D6jVNv9vgmb2NNjM/ it/DMR3K7AH20nBNYGqsYV0IEVFLALMopwSANLhFydgpkFA6RcoIOsjZn98lj6+hMa Owo2Wb9j6LcpcqBlbeRsfvo2ZsPGvHp+bf1p2HDRxruSAR87CqcQFMNBnURb+2p1Bj rRp/hJRJymKNul+fSK75UYrM8zqGLtI8rdX7qGlfakx1QaIorIzFrXmbQ3ZAP1d73o TqTiDX+rMQNtw== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Wed, 12 Jul 2023 22:42:20 +0200 X-ME-IP: 86.243.2.178 From: Christophe JAILLET To: keescook@chromium.org, Andy Gross , Bjorn Andersson , Konrad Dybcio Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , linux-arm-msm@vger.kernel.org Subject: [PATCH] soc: qcom: smem: Use struct_size() Date: Wed, 12 Jul 2023 22:42:15 +0200 Message-Id: X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771250728119400371 X-GMAIL-MSGID: 1771250728119400371 Use struct_size() instead of hand-writing it, when allocating a structure with a flex array. This is less verbose. Signed-off-by: Christophe JAILLET Reviewed-by: Kees Cook --- It will also be helpful if the __counted_by() annotation is added with a Coccinelle script such as: https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git/commit/?h=devel/counted_by&id=adc5b3cb48a049563dc673f348eab7b6beba8a9b --- drivers/soc/qcom/smem.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/soc/qcom/smem.c b/drivers/soc/qcom/smem.c index b0d59e815c3b..776096b2e965 100644 --- a/drivers/soc/qcom/smem.c +++ b/drivers/soc/qcom/smem.c @@ -1059,7 +1059,6 @@ static int qcom_smem_probe(struct platform_device *pdev) struct reserved_mem *rmem; struct qcom_smem *smem; unsigned long flags; - size_t array_size; int num_regions; int hwlock_id; u32 version; @@ -1071,8 +1070,8 @@ static int qcom_smem_probe(struct platform_device *pdev) if (of_property_present(pdev->dev.of_node, "qcom,rpm-msg-ram")) num_regions++; - array_size = num_regions * sizeof(struct smem_region); - smem = devm_kzalloc(&pdev->dev, sizeof(*smem) + array_size, GFP_KERNEL); + smem = devm_kzalloc(&pdev->dev, struct_size(smem, regions, num_regions), + GFP_KERNEL); if (!smem) return -ENOMEM;