Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2219900pxp; Sun, 13 Mar 2022 12:07:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy5dT0GKleY3MTwMGQANsvw8qKmOqqDMboT6/j5qjZmO/COqUH8aebXAY9dKaJWOusuMoYo X-Received: by 2002:a17:906:fc10:b0:6cd:84e:7248 with SMTP id ov16-20020a170906fc1000b006cd084e7248mr16534085ejb.281.1647198433492; Sun, 13 Mar 2022 12:07:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647198433; cv=none; d=google.com; s=arc-20160816; b=n1Sk9eW3WK+zTZKC9CmH397bpUV2OAS1Fj156YCk19ozauYj1x+R+kXg7Uk3pPtp9U KW/crstHtLvt993qJpJBM3NlmcBnbgki/LquI76OhDfFM4LyLq6mJFb41CmKIc3PNE7+ GkreD7qiLhMnBGQ5W0DP5VuMntult/WBxEMOsYEdtRMiCHzOmF9UQZUlDtpL+Od/DGsw TLRbHaLxXa5OrsdC1H67q8Lm/y1kGh0oxSXzK6BY7F9CzFzr5nHqhWNuHzDRMk40SnWt fZ3qTCdlZDp1KojMYRVt9vJYQzdhjoWVJYB7GH2P4jwoc/vZjWvHGCpxT7OFDN2HNHEU tMwg== 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 :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id; bh=bsPM0az/PSDnfhJRcD5R1BMovTqsWpvY/Sn5RUTlmEM=; b=w2XMAU0r5LVJXi/WYJtPgiSramrboIQzLvX6wS0eHz3ssEVj+9VDqPQdxdL0GJO195 9MQkVed9MN1CQE7Hm9Ae/3fw13lAxYskHR5GJ3B4B3PJqtYpX6YMhtDm85rKof9YKWuW VxlsNtHE7t6tgt6Nx5mhD5FhRSIxwhcMONTjdaidXT4yXE69hj/PPz1VZwJdAcJmh8Gb D6Bew9P43gPwClCh3NcYzujZFj7xqIFR5sIIsGzTPmPJAJWRnL14q26XqFW+ICr+pCBm 9adWt+5Qi75Kp4/jGPROjnE3ns3mk8r9p0VjqXnqfhiYOlsFfKBsRzcpA6r87MnYrer2 2chQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w1-20020a056402268100b00416a905fde2si8329302edd.406.2022.03.13.12.06.48; Sun, 13 Mar 2022 12:07:13 -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; 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 S231786AbiCMAPq (ORCPT + 99 others); Sat, 12 Mar 2022 19:15:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230318AbiCMAPp (ORCPT ); Sat, 12 Mar 2022 19:15:45 -0500 Received: from relay3.hostedemail.com (relay3.hostedemail.com [64.99.140.33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 262B036167 for ; Sat, 12 Mar 2022 16:14:37 -0800 (PST) Received: from omf01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id A96AF20452; Sun, 13 Mar 2022 00:14:36 +0000 (UTC) Received: from [HIDDEN] (Authenticated sender: joe@perches.com) by omf01.hostedemail.com (Postfix) with ESMTPA id DFC4F6000C; Sun, 13 Mar 2022 00:14:34 +0000 (UTC) Message-ID: Subject: Re: [PATCH 1/5] x86/alternative: simplify DUMP_BYTES macro From: Joe Perches To: Alexey Dobriyan , x86@kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, linux-kernel@vger.kernel.org Date: Sat, 12 Mar 2022 16:14:34 -0800 In-Reply-To: References: <20220311144312.88466-1-adobriyan@gmail.com> Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.40.4-1ubuntu2 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_MSPIKE_H2, SPF_HELO_PASS,SPF_NONE,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Stat-Signature: s6p8qtricqpmirccbm8yjiq5fhyd9dho X-Rspamd-Server: rspamout03 X-Rspamd-Queue-Id: DFC4F6000C X-Session-Marker: 6A6F6540706572636865732E636F6D X-Session-ID: U2FsdGVkX1/KvNf4V32GdJ6G9fIYnHBb22DHcUWmwvc= X-HE-Tag: 1647130474-731585 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 Sat, 2022-03-12 at 08:36 -0800, Joe Perches wrote: > On Fri, 2022-03-11 at 17:43 +0300, Alexey Dobriyan wrote: > > Avoid zero length check with clever whitespace placement in the format > > string. > [] > > diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c > [] > > @@ -66,13 +66,10 @@ do { \ > > if (unlikely(debug_alternative)) { \ > > int j; \ > > \ > > - if (!(len)) \ > > - break; \ > > - \ > > printk(KERN_DEBUG pr_fmt(fmt), ##args); \ > > - for (j = 0; j < (len) - 1; j++) \ > > - printk(KERN_CONT "%02hhx ", buf[j]); \ > > - printk(KERN_CONT "%02hhx\n", buf[j]); \ > > + for (j = 0; j < (len); j++) \ > > + printk(KERN_CONT " %02hhx", buf[j]); \ > > + printk(KERN_CONT "\n"); \ > > } \ > > This could also use %02x and not %02hhx > > And MAX_PATCH_LEN is 255 but is that really possible? > > Maybe if the actual patch length is always <= 64 this could use > printk(KERN_CONT "%*ph\n", (int)len, buf); > instead and avoid all possible interleaving? Another possibility would be to raise the arbitrary 64 byte limit on %*ph to 256. --- Documentation/core-api/printk-formats.rst | 6 +++--- lib/vsprintf.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Documentation/core-api/printk-formats.rst b/Documentation/core-api/printk-formats.rst index 5e89497ba314e..39f787e9b26e1 100644 --- a/Documentation/core-api/printk-formats.rst +++ b/Documentation/core-api/printk-formats.rst @@ -289,9 +289,9 @@ Raw buffer as a hex string %*phD 00-01-02- ... -3f %*phN 000102 ... 3f -For printing small buffers (up to 64 bytes long) as a hex string with a -certain separator. For larger buffers consider using -:c:func:`print_hex_dump`. +For printing small buffers (up to 256 bytes long) as a hex string with a +certain separator. For buffers larger than 64 bytes consider using +:c:func:`print_hex_dump` as its output can be more easily counted. MAC/FDDI addresses ------------------ diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 2a6c767cc2709..be6fa9fab1be8 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -1194,7 +1194,7 @@ char *hex_string(char *buf, char *end, u8 *addr, struct printf_spec spec, } if (spec.field_width > 0) - len = min_t(int, spec.field_width, 64); + len = min_t(int, spec.field_width, 256); for (i = 0; i < len; ++i) { if (buf < end)