Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp556845rwd; Thu, 1 Jun 2023 04:00:32 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7A3xZyCmFydmID/1e5wrZLUUtrkU5a6FMz4A+dWNxtucmqO4fHN/4xgLgKNM/KO1UmqAbU X-Received: by 2002:a92:d6ca:0:b0:33b:6cc0:ee6b with SMTP id z10-20020a92d6ca000000b0033b6cc0ee6bmr5405187ilp.13.1685617232147; Thu, 01 Jun 2023 04:00:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685617232; cv=none; d=google.com; s=arc-20160816; b=w5TqhmL6IBk3TqLUJAC5sJ4yEZYIlljFeI6zFlfFaDAHkE6tyY7YYyWpOji/4fs2kq LQS2fH/ml8kxB3kaSaIQg+FxApIFbdoJ73GNq5eUtrccNRxBBc3mASkOkyUDxR3Rp4jH dBwM276HpE8BbKiICDejYrYFb2JPXAqZ7Ti+V+IKNa2FdEpM9x7L+MolX2nSpTEEaFDo Qm0SBK41ilCFuXXArlMcL9AxP9skmMAZWq1WctmAIC13k1qj2Zv3thXsf888axI1YURl 9MYIiA00Ly23CMBs7C9t1+alpYee/xqmg+tg5TXf8hXa66iPigHG4qTkIR/0DRZebhFU 32Mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=UiSS9nj6xH+Um2NERpCFyQMVz8ELBfz4b0zRoYrjHKU=; b=RQAXZfjWheRz4o7nXtO5+yY4WMblxyQfY47XVWsDD2BCX9FUYIpoQmUgmE/wt2ERPI facfKIt+aHuqN9Y2YUA4EpSSZ3poOyb1sXGEqt0JSiar4Yxf35rvwX5yf17JWHCTnDIG f7EzuwUjkPm+ngSyH4Kq8Y4DiVueH4/g2t8QWsqTpRHj7VdQxm4KwjyAstC1PfHdhI5A YjoHuTc7ZTrHGTW50XAeUDpbwhZhDSnzbS3StvXpeiFRJRmTBQ+Vb2UdVfsACk/Kqu/c eIGj+YnsemfOWJ6zo/Z/gClQsC759T+vPmg9YkKaY0ibQt0AIVXKo7NfzYBfQE8zdZ8F up2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=P9nPDrIX; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y20-20020a63b514000000b0053439c1712esi2574303pge.713.2023.06.01.04.00.17; Thu, 01 Jun 2023 04:00:32 -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=@redhat.com header.s=mimecast20190719 header.b=P9nPDrIX; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232311AbjFAKlN (ORCPT + 99 others); Thu, 1 Jun 2023 06:41:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232124AbjFAKlL (ORCPT ); Thu, 1 Jun 2023 06:41:11 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1733CC0 for ; Thu, 1 Jun 2023 03:40:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685616025; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=UiSS9nj6xH+Um2NERpCFyQMVz8ELBfz4b0zRoYrjHKU=; b=P9nPDrIXVP9qko8mrhwHnsObBr1I3TO9UPBF0gJuHk+esnvOAMWORtdU7h2mn3H7GQP25i ZxQR2vzBBlzR0hye4Yp1PQrwZA0m6i+hTu5NlOv3ZeztbrNhsqC+4rw+rtQhSDCMq1MlhN PJJcFRQVW8WbIPyk7UsHG7MCW0UuSRY= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-590-CsHaACKPPbm9rtHrH7kkMw-1; Thu, 01 Jun 2023 06:40:21 -0400 X-MC-Unique: CsHaACKPPbm9rtHrH7kkMw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CD136280AA26; Thu, 1 Jun 2023 10:40:20 +0000 (UTC) Received: from localhost (ovpn-12-54.pek2.redhat.com [10.72.12.54]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 01D0A8162; Thu, 1 Jun 2023 10:40:19 +0000 (UTC) Date: Thu, 1 Jun 2023 18:40:16 +0800 From: Baoquan He To: Simon Horman Cc: Andrew Morton , Eric Biederman , "Leizhen (ThunderTown)" , kexec@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] kexec: Avoid calculating array size twice Message-ID: References: <20230525-kexec-array_size-v1-1-8b4bf4f7500a@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230525-kexec-array_size-v1-1-8b4bf4f7500a@kernel.org> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,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 On 05/25/23 at 04:26pm, Simon Horman wrote: > 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 Amazingly smart. Thanks. Acked-by: Baoquan He > > 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; >