Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp555390rwd; Thu, 1 Jun 2023 03:59:28 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ59J6azxcpv2t+LyM3Ka8oCmrIiT4RaWjAwuu0dXpKePBjcnwfwoZg4fkzIWfsu/pdmP4x4 X-Received: by 2002:a05:6a00:22c9:b0:63b:4313:f8c4 with SMTP id f9-20020a056a0022c900b0063b4313f8c4mr10546112pfj.9.1685617168485; Thu, 01 Jun 2023 03:59:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685617168; cv=none; d=google.com; s=arc-20160816; b=gEWwfLbJzBj9cRd/LMmyTcJ5fke0B64vz+NFUjgER0iYPRTTCJflvl7pajzCLP/91n Yti4SLTUQpLh/oO4AbAH86KM7pViHPz6UaAkPsoVklMiWd3zpSEoIkPWTH9mDxpKb3JE VlqrKvy3mFCDOOIRoyMz9DyfzUu5ydOfxTFCvNxZdZ23hhrWgieG5SiRuNWKcUnRDZ1n iy41KWua/8X2g5l9Om7y7hHa2gjQk5KFv+WBEK1AdNGGq9X4kGEBszclSTwiRVL64JEx clMrlqXkNa49sfY2qfC3uXtGhTzdviJr2HRZNVIfQJK9INhzkuP8X6BAN8PURPiVHgh6 fJpA== 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=YbR9CXr6tf+W2x5hw6RwEAlyQOocli6uAUnQNn0VL3M=; b=kXQH5HTH5mNApbw6wKALu+qt2HiwaJMMUUMPBylgQJm2ZdYZPyLRWdEHnjBkT1lLuE jtv004ob3qoDmkQluc1M9p7GhCn/VYzu7Y4GOFAohZx3e1Ua9GfL79iaBKK9bt5StwVu JpqgRmb1M0T5ohO5AHVTi6tVXWxbQOPh844nZglDMdEhcwgt+RHhrCSHGZ5OYTHsShxF gqTPUxT4/E3TEbfcHa9hr7k5vDd6Ha6gafDUd6O1I1pmYbUWq3o0Pp1WFOXrs5mx0I7J 61SQpazNuWydjKf8+YDUo+RlHlJL/iyRmvRwX1Mjsxu+QiSfJsEVBNNWEHfVpP7PhgEN +Xyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FoMcLCEp; 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 az9-20020a056a02004900b0053efd7561e1si2666651pgb.287.2023.06.01.03.59.14; Thu, 01 Jun 2023 03:59:28 -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=FoMcLCEp; 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 S233109AbjFAKul (ORCPT + 99 others); Thu, 1 Jun 2023 06:50:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232821AbjFAKu2 (ORCPT ); Thu, 1 Jun 2023 06:50:28 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 160D49D for ; Thu, 1 Jun 2023 03:49:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685616579; 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=YbR9CXr6tf+W2x5hw6RwEAlyQOocli6uAUnQNn0VL3M=; b=FoMcLCEpTEiKc0BzN+0lcmycaA3EsTTUrDV3+e5Qa71jHdPl2ZZSuxXcMQqNoDe5uMTGza kIfIyR7koBsujpjOpcPsiDl5OSAumGlSzC4KA6w7vysyeQM9CTlAiS8lA2pv2xmja3bruh 0w7NfC2kdDoH64FpVXaQjH9tJ1SsjVo= 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-491-SxdGd6MvNq2cNu63Kpr6Xg-1; Thu, 01 Jun 2023 06:49:36 -0400 X-MC-Unique: SxdGd6MvNq2cNu63Kpr6Xg-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 854C41C04327; Thu, 1 Jun 2023 10:49:35 +0000 (UTC) Received: from localhost (ovpn-12-54.pek2.redhat.com [10.72.12.54]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 98AE4492B0A; Thu, 1 Jun 2023 10:49:34 +0000 (UTC) Date: Thu, 1 Jun 2023 18:49:31 +0800 From: Baoquan He To: Simon Horman , Andrew Morton Cc: 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: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 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 06/01/23 at 06:40pm, Baoquan He wrote: > 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 Just noticed Andrew has picked this one, please ignore this. > > > > > 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; > > >