Received: by 10.223.185.116 with SMTP id b49csp1136425wrg; Fri, 16 Feb 2018 13:09:25 -0800 (PST) X-Google-Smtp-Source: AH8x224RuQ2MZTqV77AbcqeBqtwxkqhfICVXbNQLaJ9QGg5weeByl59GNNE9HjQwE49++FUo6Wvu X-Received: by 2002:a17:902:6bc9:: with SMTP id m9-v6mr2142271plt.273.1518815365662; Fri, 16 Feb 2018 13:09:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518815365; cv=none; d=google.com; s=arc-20160816; b=fe6kTs+WthXo5Xa38kpOD8yBCq8m92bQ1St7fdX/TfB9bLqTY6leLBSawXPR3US5sj TgWEwZzFAvu10BlL/7krui+s841NFbq4tmlLknvU9ug93BV8pqt38MUA7RNkIhkx9Ug9 yuBZu8rFRF/fOe8wNiBvtBdpOSvdx4WcsBmu67gRg8l6ItAdbZhcWbxvQMvW5lzyP8sx SYKMQGh1NyFp2BBg+OirY3lD6aLt2MiH/RVxYnAuDMU0qxNXGNY4zj7CQPh654vLrhUm UnW4x+XDxkLL/KTkq5pt8d1l2W3JSOtoYN9EozIdeObOunjijY2AiwudgxUznSxYJLKN g87Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=j4+fv8QiRN0Jf0T69fGPs+53P+B96ei/zsQACTAVLWE=; b=RCtih/0bmjCBe8e7y4nyzvu2v0F0zSBTrZrhFP8OoYnKm5wZxQJ/hiWkiYGOJzWB92 6YszUPicVRQ2yyRysi0DGJ/ajF+kQ60SRVfY8RzDD9gAN5yNuHHtLGhEt/jwWym0HKi3 T8lDoasqJ0cIkgaqsx6tVWDTbgfjQS23CFyAHFIvhg8Pt8d0pCDM1QmxUnsnlNv4Xx1t 1cx+4Ow6BslMO32sLCk6eyDyiQuCs2b0YK4xJ0efgWe1S9gOJo5ZL+lOgnEBBjy5Ne9e 6ixa2uP+u/sZ/+wWF1H28+rqF+kYyUGMkH9Cv59jFvWntV7wTXKu5rc++RWKNkny5XOy G3Og== 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 f1-v6si1889986pld.744.2018.02.16.13.09.11; Fri, 16 Feb 2018 13:09:25 -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 S1751073AbeBPVHw (ORCPT + 99 others); Fri, 16 Feb 2018 16:07:52 -0500 Received: from mga06.intel.com ([134.134.136.31]:23771 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750897AbeBPVHT (ORCPT ); Fri, 16 Feb 2018 16:07:19 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Feb 2018 13:07:18 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,520,1511856000"; d="scan'208";a="18754917" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga008.jf.intel.com with ESMTP; 16 Feb 2018 13:07:16 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 3BEFD139; Fri, 16 Feb 2018 23:07:13 +0200 (EET) From: Andy Shevchenko To: "Tobin C . Harding" , linux@rasmusvillemoes.dk, Petr Mladek , Joe Perches , linux-kernel@vger.kernel.org, Andrew Morton Cc: Andy Shevchenko Subject: [PATCH v2 6/9] lib/vsprintf: Deduplicate pointer_string() Date: Fri, 16 Feb 2018 23:07:08 +0200 Message-Id: <20180216210711.79901-6-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180216210711.79901-1-andriy.shevchenko@linux.intel.com> References: <20180216210711.79901-1-andriy.shevchenko@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There is an exact code at the end of ptr_to_id(). Replace it by calling pointer_string() directly. This is followup to the commit ad67b74d2469 ("printk: hash addresses printed with %p"). Cc: Tobin C. Harding Signed-off-by: Andy Shevchenko --- lib/vsprintf.c | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 87dbced51b1a..9004bbb3d84d 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -1367,13 +1367,6 @@ static noinline_for_stack char *restricted_pointer(char *buf, char *end, const void *ptr, struct printf_spec spec) { - spec.base = 16; - spec.flags |= SMALL; - if (spec.field_width == -1) { - spec.field_width = 2 * sizeof(ptr); - spec.flags |= ZEROPAD; - } - switch (kptr_restrict) { case 0: /* Always print %pK values */ @@ -1385,8 +1378,11 @@ char *restricted_pointer(char *buf, char *end, const void *ptr, * kptr_restrict==1 cannot be used in IRQ context * because its test for CAP_SYSLOG would be meaningless. */ - if (in_irq() || in_serving_softirq() || in_nmi()) + if (in_irq() || in_serving_softirq() || in_nmi()) { + if (spec.field_width == -1) + spec.field_width = 2 * sizeof(ptr); return string(buf, end, "pK-error", spec); + } /* * Only print the real pointer value if the current @@ -1411,7 +1407,7 @@ char *restricted_pointer(char *buf, char *end, const void *ptr, break; } - return number(buf, end, (unsigned long)ptr, spec); + return pointer_string(buf, end, ptr, spec); } static noinline_for_stack @@ -1686,10 +1682,9 @@ early_initcall(initialize_ptr_random); static char *ptr_to_id(char *buf, char *end, void *ptr, struct printf_spec spec) { unsigned long hashval; - const int default_width = 2 * sizeof(ptr); if (unlikely(!have_filled_random_ptr_key)) { - spec.field_width = default_width; + spec.field_width = 2 * sizeof(ptr); /* string length must be less than default_width */ return string(buf, end, "(ptrval)", spec); } @@ -1704,15 +1699,7 @@ static char *ptr_to_id(char *buf, char *end, void *ptr, struct printf_spec spec) #else hashval = (unsigned long)siphash_1u32((u32)ptr, &ptr_key); #endif - - spec.flags |= SMALL; - if (spec.field_width == -1) { - spec.field_width = default_width; - spec.flags |= ZEROPAD; - } - spec.base = 16; - - return number(buf, end, hashval, spec); + return pointer_string(buf, end, (const void *)hashval, spec); } /* -- 2.15.1