Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp422578ybj; Tue, 5 May 2020 00:53:24 -0700 (PDT) X-Google-Smtp-Source: APiQypJ1yHzVzAjcq10TNYutjExWn05mh0vvOrQXWG9DgYzp6JyAMh/hDw4Mwp+kucQ2ae3/XQzp X-Received: by 2002:a05:6402:c84:: with SMTP id cm4mr1358857edb.316.1588665204273; Tue, 05 May 2020 00:53:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588665204; cv=none; d=google.com; s=arc-20160816; b=pH+rnZ6u5kzykILv+M55FSSpUgSsnct71ukEhn7cdDnbDriW4Fy9HdNQiZiGwsvTUN fupvBGK8gw4Q+MpcqqoF2B9i6qmq0BRXForM7ZF58Zd9AF+Fp53ad68PuKFn4yFthcOs hNutzfxeyMgeH3vyK0JBZZprZPAGSUG4zwWNS370GRm3NHfz2wYMZJ3U+upQ/JW9qMkD n7YCFvQvgdMeVg7DZHKhpVT11YzOaxinspFe5qHkH0tYLCl+aFU6uCTAzqII76PdpLTg hotDuNdYtfcLYcQfbc3hvD6t5IjbM6D7A8kFnaBUFTDGVnU3zianQgvet+yRYEGBFRFV EInw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=69oQPU6GliJUu7T0uYir9SmPoAiPGlVXtQ2aCpEoPDY=; b=Rn77PSd+6ZcGWmG7IDG1rHgZ6g6ARXycceRjgPkPK9CoEgwV7viXXMas2K4NPlQU2o n4wWqUeBM2WYfKlzCTU6VWaubSUWQrOzAj/FYSQkagx6czoZsB3YXTYbt+FDX3ISQdXE esAr4+gFsiRcFkN19JnWEAcdse1hkvxlhBQbZGh6l9PAbk1Z5ZVyTGEA4e1aAiMukGjJ fHC0fsRAEler+1owngt1OIjCS2bl9D7nYdOFRAbyl0Y8mfAQA9UDzOXlyQPbf9fBcPfT d4yBO7VJZ35Ad++eNRtcmvpc8K7g8HHfO7NQ58ZtGopTcXNTR0HhueBRh4ydsCsLeBTv AoxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="dT/T1VRC"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d17si593963ejw.87.2020.05.05.00.53.01; Tue, 05 May 2020 00:53:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="dT/T1VRC"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1728479AbgEEHvL (ORCPT + 99 others); Tue, 5 May 2020 03:51:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:43648 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727784AbgEEHvK (ORCPT ); Tue, 5 May 2020 03:51:10 -0400 Received: from mail-il1-f179.google.com (mail-il1-f179.google.com [209.85.166.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A992E2075A; Tue, 5 May 2020 07:51:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588665069; bh=jc+H61N9vNsq7z6RWa8sVHyNz5abdZOteKU9Ks7UD2o=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=dT/T1VRCyX6urOLpGh8Qqe/AGU8FLYkvpxCqNRT3e/RZpEq7ubRnwEbK6KLodRQfK rOeKTs2jOdGGJdtH2s5GSKH/adp6pSYpLR0DwLWszmd07GamjXiYb1VSaezS7ILqNj tOHWJcBalmMJtTg35IVKzDL4yBMonGgY+JMCs38E= Received: by mail-il1-f179.google.com with SMTP id x2so147572ilp.13; Tue, 05 May 2020 00:51:09 -0700 (PDT) X-Gm-Message-State: AGi0PuYFMrKZurVXdPr5nxygwduwmXzp/n9EvKDd3j9mE1YCVxew4gFu nbQ+eHZHivmePQVnFEHLnNyTF8Ns22mz338miyY= X-Received: by 2002:a92:405:: with SMTP id 5mr2256629ile.279.1588665069102; Tue, 05 May 2020 00:51:09 -0700 (PDT) MIME-Version: 1.0 References: <091e3fc3bdbc5f480af7d3b3ac096d174a4480d0.1588273612.git.joe@perches.com> In-Reply-To: From: Ard Biesheuvel Date: Tue, 5 May 2020 09:50:58 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [trivial PATCH] efi/libstub: Reduce efi_printk object size To: Joe Perches Cc: Arvind Sankar , Linux Kernel Mailing List , linux-efi , X86 ML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 4 May 2020 at 20:29, Joe Perches wrote: > > Use a few more common kernel styles. > > Trivially reduce efi_printk object size by using a dereference to > a temporary instead of multiple dereferences of the same object. > > Use efi_printk(const char *str) and static or static const for its > internal variables. > > Use the more common form of while instead of a for loop. > > Change efi_char16_printk argument to const. > > Signed-off-by: Joe Perches Thanks Joe. > --- > drivers/firmware/efi/libstub/efi-stub-helper.c | 16 ++++++++-------- > drivers/firmware/efi/libstub/efistub.h | 6 +++--- > 2 files changed, 11 insertions(+), 11 deletions(-) > > diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c > index 1c92ac231f94..dfd72a4360ac 100644 > --- a/drivers/firmware/efi/libstub/efi-stub-helper.c > +++ b/drivers/firmware/efi/libstub/efi-stub-helper.c > @@ -26,19 +26,19 @@ bool __pure __efi_soft_reserve_enabled(void) > return !efi_nosoftreserve; > } > > -void efi_printk(char *str) > +void efi_printk(const char *str) > { > - char *s8; > + char s8; > > - for (s8 = str; *s8; s8++) { > - efi_char16_t ch[2] = { 0 }; > + while ((s8 = *str++)) { I'm not sure I prefer the assignment-as-truth-value construct over the original for () tbh > + static efi_char16_t ch[2] = {0, 0}; > UEFI code could potentially be reentrant, so this should not be static. > - ch[0] = *s8; > - if (*s8 == '\n') { > - efi_char16_t nl[2] = { '\r', 0 }; > + if (s8 == '\n') { > + static const efi_char16_t nl[2] = { '\r', 0 }; > efi_char16_printk(nl); We cannot make this const, unfortunately (see below). But we can clean this up by using L"\r" as the initializer. > } > > + ch[0] = s8; > efi_char16_printk(ch); > } > } > @@ -284,7 +284,7 @@ void *get_efi_config_table(efi_guid_t guid) > return NULL; > } > > -void efi_char16_printk(efi_char16_t *str) > +void efi_char16_printk(const efi_char16_t *str) > { > efi_call_proto(efi_table_attr(efi_system_table, con_out), > output_string, str); > diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h > index 5ff63230a1f1..a03a92c665f0 100644 > --- a/drivers/firmware/efi/libstub/efistub.h > +++ b/drivers/firmware/efi/libstub/efistub.h > @@ -251,7 +251,7 @@ union efi_simple_text_output_protocol { > struct { > void *reset; > efi_status_t (__efiapi *output_string)(efi_simple_text_output_protocol_t *, > - efi_char16_t *); > + const efi_char16_t *); This prototype comes straight from the UEFI specification, and even though it is dumb that they forgot about const-qualified pointers entirely, I would prefer not to deviate from this. > void *test_string; > }; > struct { > @@ -599,7 +599,7 @@ efi_status_t efi_exit_boot_services(void *handle, > void *priv, > efi_exit_boot_map_processing priv_func); > > -void efi_char16_printk(efi_char16_t *); > +void efi_char16_printk(const efi_char16_t *str); > > efi_status_t allocate_new_fdt_and_exit_boot(void *handle, > unsigned long *new_fdt_addr, > @@ -624,7 +624,7 @@ efi_status_t check_platform_features(void); > > void *get_efi_config_table(efi_guid_t guid); > > -void efi_printk(char *str); > +void efi_printk(const char *str); > > void efi_free(unsigned long size, unsigned long addr); > >