Received: by 10.223.176.46 with SMTP id f43csp365344wra; Thu, 25 Jan 2018 23:42:13 -0800 (PST) X-Google-Smtp-Source: AH8x226w12QwBmj09dU5szVzAN22qT35fJ+h6VHVmAWZbHHcQ83TFbQ6WIXrXFmbOBxeX5WlWZqm X-Received: by 10.99.131.74 with SMTP id h71mr14827005pge.373.1516952533629; Thu, 25 Jan 2018 23:42:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516952533; cv=none; d=google.com; s=arc-20160816; b=HabKFAKo3DBfTMoJeEPrJpW3PVfZKw/J66ts2DCPAjfSv7pBGFrubZhBfFsJlr+6by D2eLjel2Z2+X9iQ2wGzksyBMOt9jE1xxVnlXeY0z3A56JmZcrC8gRqIfBepthc86p/ff OPfYKs49GZRmmkVSDs4WRUNUjzbEsOGJQJmzQ9fW7OKFZABgesCUq8jTEEPPssyee/1B r5W2YUYoKnPbTjCaQ7gFAFBHbJclf+GR8yS+7rNqcHb0vY6sZmr6UfDk4HBtgahPJtrj Ln+3S7wuesKx4eY4xtNcM85GBq1BXurP7vzMnJM2yF4Y9cgVvtJiNySsyL7jbrzg0tn9 QhRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from:arc-authentication-results; bh=IQF7kcfmmjewwPMXVv7LODW3e6NYDqf69oyUtd5JNys=; b=qAyhwI8Z/ipqOHy4Zn2TjOTDY6Zuo/xluy6V5XlarhKJ7IBxDfKy7CbDPCqHjVhEdl 3i0Y/PZlWzdZY2viUbjlap6+SX1F7By4MT12nB1RSnI+6aFLgQ6MUUDS9tVHstUVgrl4 PeDIetNk/dlK25FWgLceBR/NilkbAhWSOGWneL4SIuqtls7ocZYSymp45UrSYKOGfeVP xSEHHKNU2iWe6Lsg7sp2/H4ImwBXXAryAJfkz/30bYVu0VaDHgbRSOEKAnr4E6ZgngkL PRUzObdnh2blfdcULnDeGzUDQIRjeYS3gPIUid1r4vE/Ap0/sGrkMaF28PxZl4+7W/xW AxyQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n14si2658737pgt.469.2018.01.25.23.41.59; Thu, 25 Jan 2018 23:42:13 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752086AbeAZHkm (ORCPT + 99 others); Fri, 26 Jan 2018 02:40:42 -0500 Received: from mx01.hxt-semitech.com.96.203.223.in-addr.arpa ([223.203.96.7]:52729 "EHLO barracuda.hxt-semitech.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751349AbeAZHkk (ORCPT ); Fri, 26 Jan 2018 02:40:40 -0500 X-ASG-Debug-ID: 1516952431-093b7e430523b00001-xx1T2L Received: from HXTBJIDCEMVIW01.hxtcorp.net (localhost [10.128.0.14]) by barracuda.hxt-semitech.com with ESMTP id 8me3DuDA7U7abPFc (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 26 Jan 2018 15:40:31 +0800 (CST) X-Barracuda-Envelope-From: shunyong.yang@hxt-semitech.com Received: from y.localdomain (10.5.21.109) by HXTBJIDCEMVIW01.hxtcorp.net (10.128.0.14) with Microsoft SMTP Server (TLS) id 15.0.847.32; Fri, 26 Jan 2018 15:40:39 +0800 From: Yang Shunyong To: CC: , , , , , , , , Yang Shunyong Subject: [RFC PATCH] vsprintf: add flag ZEROPAD handling before crng is ready Date: Fri, 26 Jan 2018 15:39:56 +0800 X-ASG-Orig-Subj: [RFC PATCH] vsprintf: add flag ZEROPAD handling before crng is ready Message-ID: <1516952396-7423-1-git-send-email-shunyong.yang@hxt-semitech.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.5.21.109] X-ClientProxiedBy: HXTBJIDCEMVIW01.hxtcorp.net (10.128.0.14) To HXTBJIDCEMVIW01.hxtcorp.net (10.128.0.14) X-Barracuda-Connect: localhost[10.128.0.14] X-Barracuda-Start-Time: 1516952431 X-Barracuda-Encrypted: ECDHE-RSA-AES256-SHA X-Barracuda-URL: https://192.168.50.101:443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at hxt-semitech.com X-Barracuda-BRTS-Status: 1 X-Barracuda-Bayes: INNOCENT GLOBAL 0.6188 1.0000 0.8411 X-Barracuda-Spam-Score: 0.84 X-Barracuda-Spam-Status: No, SCORE=0.84 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=9.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.47278 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Before crng is ready, output of "%p" composes of "(ptrval)" and left padding spaces for alignment as no random address can be generated. This seems a little strange sometimes. For example, when irq domain names are built with "%p", the nodes under /sys/kernel/debug/irq/domains like this, [root@y irq]# ls domains/ default irqchip@ (ptrval)-2 irqchip@ (ptrval)-4 \_SB_.TCS0.QIC1 \_SB_.TCS0.QIC3 irqchip@ (ptrval) irqchip@ (ptrval)-3 \_SB_.TCS0.QIC0 \_SB_.TCS0.QIC2 The name "irqchip@ (ptrval)-2" is not so readable in console output. This patch adds ZEROPAD handling in widen_string() and move_right(). When ZEROPAD is set in spec, it will use '0' for padding. If not set, it will use ' '. This patch also sets ZEROPAD in ptr_to_id() before crgn is ready. Following is the output after applying the patch, [root@y irq]# ls domains/ default irqchip@00000000(ptrval)-2 irqchip@00000000(ptrval)-4 \_SB_.TCS0.QIC1 \_SB_.TCS0.QIC3 irqchip@00000000(ptrval) irqchip@00000000(ptrval)-3 \_SB_.TCS0.QIC0 \_SB_.TCS0.QIC2 I am not sure whether crng can get enough random data at very early stage of system startup (eg. before irq system in the case above) and the effort to port current random driver to work at that time. So, this issue may exist some time. I use '0' for padding in this patch. This should be ok because output of "%pK" is all '0's when kptr_restrict = 2. I don't know whether other character, such as 'x', may be more preferable. Signed-off-by: Yang Shunyong --- lib/vsprintf.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 01c3957b2de6..e0b6e1edae31 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -535,14 +535,18 @@ char *special_hex_number(char *buf, char *end, unsigned long long num, int size) return number(buf, end, num, spec); } -static void move_right(char *buf, char *end, unsigned len, unsigned spaces) +static void move_right(char *buf, char *end, unsigned int len, + unsigned int spaces, struct printf_spec spec) { size_t size; + char pad; + + pad = (spec.flags & ZEROPAD) ? '0' : ' '; if (buf >= end) /* nowhere to put anything */ return; size = end - buf; if (size <= spaces) { - memset(buf, ' ', size); + memset(buf, pad, size); return; } if (len) { @@ -550,7 +554,7 @@ static void move_right(char *buf, char *end, unsigned len, unsigned spaces) len = size - spaces; memmove(buf + spaces, buf, len); } - memset(buf, ' ', spaces); + memset(buf, pad, spaces); } /* @@ -565,18 +569,21 @@ static void move_right(char *buf, char *end, unsigned len, unsigned spaces) char *widen_string(char *buf, int n, char *end, struct printf_spec spec) { unsigned spaces; + char pad; if (likely(n >= spec.field_width)) return buf; /* we want to pad the sucker */ spaces = spec.field_width - n; if (!(spec.flags & LEFT)) { - move_right(buf - n, end, n, spaces); + move_right(buf - n, end, n, spaces, spec); return buf + spaces; } + + pad = (spec.flags & ZEROPAD) ? '0' : ' '; while (spaces--) { if (buf < end) - *buf = ' '; + *buf = pad; ++buf; } return buf; @@ -1702,6 +1709,8 @@ static char *ptr_to_id(char *buf, char *end, void *ptr, struct printf_spec spec) if (unlikely(!have_filled_random_ptr_key)) { spec.field_width = default_width; + spec.flags |= ZEROPAD; + /* string length must be less than default_width */ return string(buf, end, "(ptrval)", spec); } -- 1.8.3.1