Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1088153rwd; Thu, 25 May 2023 07:55:50 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4OHZZh+BflJtY+s0/vZz6bc3f4cCupbXT9PwKbCZDOmy6SUsJovMhWoHJSQ9PSNUMjwrkv X-Received: by 2002:a17:902:d50f:b0:1ab:8f4:af2b with SMTP id b15-20020a170902d50f00b001ab08f4af2bmr2254644plg.38.1685026549729; Thu, 25 May 2023 07:55:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685026549; cv=none; d=google.com; s=arc-20160816; b=Lr0HESpvSyDC2OyzLn6uvamMgwToiI1LWYqEUWYJBPZIdvy8c6uFcHz4wG0Scaiu+2 XkcpjkXrwvrIrjICjpE0bit+H27i1U1z3QqETgpzgwsvdq92U3P4r85QjUuQge1lCUeC ByXRznFIp2X/hHsovQKh6deXYUBzQ1l/KlaCCri63gagtfI672qWRYB3L1EU086b4vX4 8Do77rDDWhjFpz85/kl1CXGdeLKXDtFFtRGw6wK+AL12tDq+YgcTx8cP7IkVyipz+mCH kN1yvea/B+aNZhrLdVLw4FaQi9/qb6WT0ONWR7fLUsirs6vkf6iSXaZsxhZuWfo+F2ED G1ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:message-id:content-transfer-encoding :mime-version:subject:date:from:dkim-signature; bh=Ck5uj4k2+vcrKb67HFT55OfKY8H9WsE2VDHVtJwCPgY=; b=ChSHxikigtkDpSEd2e+/7UwPGuTqNialz/4KcCJknv//7bQm3sFGQHgDefmPQBMVsL PegzBCHjkgc4nbYyi0RsG/hJm7hwiRmh42gaxVDu1Pz937HMCRYRHd8LjGBxnhReStEj zaznTrXj8DPjgXabfYh3nV9AxdxDjbJwO/m3BohQldoFOxWXzxYCD/oKb2JdT/t0mMBx i3eGLG3dZLBsFU69abbykLLjKcrqNYkgPzWCfQYDzyLfiL264+iGL+Tqra4p+TTxoZFs F864w9LMdMLopQJjPr+fxpTCawM9nBSuN1khiaAzaqt3z9l5+SbcckEIxj4r38yhqJDa 9seQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="SSYfx3l/"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c24-20020a170902b69800b001a63889512csi1548221pls.135.2023.05.25.07.55.37; Thu, 25 May 2023 07:55:49 -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=@kernel.org header.s=k20201202 header.b="SSYfx3l/"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241622AbjEYO0e (ORCPT + 99 others); Thu, 25 May 2023 10:26:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241569AbjEYO0c (ORCPT ); Thu, 25 May 2023 10:26:32 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E345189 for ; Thu, 25 May 2023 07:26:31 -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 2602364635 for ; Thu, 25 May 2023 14:26:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6FB6FC433EF; Thu, 25 May 2023 14:26:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685024790; bh=JwGEFsVAytpbnNTBcy9sEez5APaywOmU9QISh6P6Aw4=; h=From:Date:Subject:To:Cc:From; b=SSYfx3l/xw++zk8yHiFZKMnV7NCo0yZ0o6m+PMrdb4g+bxcEF2Xb8II2nZB5HwnlE //N4HEtbd2P90fo6T89Ow23UxAy6hnJWoubiLOsoX6IfBK3FQsxoS5jqm/vEakQj8D ucHrj3f8a0AY6755FV6ZY9Unf/tjsJx5xaKlwPlTYfKUDoroiT3U1Hrnnxk7JRNOwf Fh2rJZgfLXN7pJYOhJaEn3Lt3br5bnBpWxzy/sk2oTJvLzl6LKIZ7IiXuJWsOossA5 9WTt7Dkty72DAJPBa0tjU9X3zb87r97sDdEaqv9IltfqOXJmryr5vVcO4PdZCr/Qle ybqFL8jhtWflg== From: Simon Horman Date: Thu, 25 May 2023 16:26:25 +0200 Subject: [PATCH] kexec: Avoid calculating array size twice MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230525-kexec-array_size-v1-1-8b4bf4f7500a@kernel.org> X-B4-Tracking: v=1; b=H4sIABBwb2QC/x2N0QrCMAwAf2Xk2UCtrQ/+ioikXeaCo0qCMjf27 ws+3sFxKxirsMGlW0H5Kyav5nA8dFBHag9G6Z0hhngKOWZ88swVSZV+d5OFsT/nGiilkmgAzwo ZY1FqdfSwfabJ5Vt5kPn/ud62bQcbFtZsdwAAAA== To: Andrew Morton Cc: Eric Biederman , Baoquan He , "Leizhen (ThunderTown)" , kexec@lists.infradead.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 Avoid calculating array size twice in kexec_purgatory_setup_sechdrs(). Once using array_size(), and once open-coded. Flagged by Coccinelle: .../kexec_file.c:881:8-25: WARNING: array_size is already used (line 877) to compute the same size No functional change intended. Compile tested only. Signed-off-by: Simon Horman --- kernel/kexec_file.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index f989f5f1933b..3f5677679744 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -867,6 +867,7 @@ static int kexec_purgatory_setup_sechdrs(struct purgatory_info *pi, { unsigned long bss_addr; unsigned long offset; + size_t sechdrs_size; Elf_Shdr *sechdrs; int i; @@ -874,11 +875,11 @@ static int kexec_purgatory_setup_sechdrs(struct purgatory_info *pi, * The section headers in kexec_purgatory are read-only. In order to * have them modifiable make a temporary copy. */ - sechdrs = vzalloc(array_size(sizeof(Elf_Shdr), pi->ehdr->e_shnum)); + sechdrs_size = array_size(sizeof(Elf_Shdr), pi->ehdr->e_shnum); + sechdrs = vzalloc(sechdrs_size); if (!sechdrs) return -ENOMEM; - memcpy(sechdrs, (void *)pi->ehdr + pi->ehdr->e_shoff, - pi->ehdr->e_shnum * sizeof(Elf_Shdr)); + memcpy(sechdrs, (void *)pi->ehdr + pi->ehdr->e_shoff, sechdrs_size); pi->sechdrs = sechdrs; offset = 0;