From nobody Thu Apr 9 10:44:43 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3984C433F5 for ; Tue, 11 Oct 2022 04:04:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229613AbiJKEE5 (ORCPT ); Tue, 11 Oct 2022 00:04:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229573AbiJKEEw (ORCPT ); Tue, 11 Oct 2022 00:04:52 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03CFFDEC9 for ; Mon, 10 Oct 2022 21:04:49 -0700 (PDT) Received: from dggpeml500022.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Mmhqz1R69zHtrR; Tue, 11 Oct 2022 11:59:42 +0800 (CST) Received: from dggpeml100012.china.huawei.com (7.185.36.121) by dggpeml500022.china.huawei.com (7.185.36.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 11 Oct 2022 12:04:37 +0800 Received: from localhost.localdomain (10.67.175.61) by dggpeml100012.china.huawei.com (7.185.36.121) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 11 Oct 2022 12:04:36 +0800 From: Zheng Yejian To: , , CC: , Subject: [PATCH v2] ftrace: Fix char print issue in print_ip_ins() Date: Tue, 11 Oct 2022 12:03:52 +0000 Message-ID: <20221011120352.1878494-1-zhengyejian1@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.67.175.61] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpeml100012.china.huawei.com (7.185.36.121) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" When ftrace bug happened, following log shows every hex data in problematic ip address: actual: ffffffe8:6b:ffffffd9:01:21 But so many 'f's seem a little confusing, and that is because format '%x' being used to print signed chars in array 'ins'. As suggested by Joe, change to use format "%*phC" to print array 'ins'. After this patch, the log is like: actual: e8:6b:d9:01:21 Fixes: 6c14133d2d3f ("ftrace: Do not blindly read the ip address in ftrace_= bug()") Suggested-by: Joe Perches Signed-off-by: Zheng Yejian --- kernel/trace/ftrace.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) Changes since v1: Use format "%*phC" to print array 'ins' as suggested by Joe. Link: https://lore.kernel.org/lkml/0a9453d94419991aa38d64b7a446eeba1f9c5= a80.camel@perches.com/#t Usage of format "%*phC" can also be found in Documentation/core-api/prin= tk-formats.rst "Raw buffer as a hex string" diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 447d2e2a8549..b838c717037a 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -2016,7 +2016,6 @@ static int ftrace_hash_ipmodify_update(struct ftrace_= ops *ops, static void print_ip_ins(const char *fmt, const unsigned char *p) { char ins[MCOUNT_INSN_SIZE]; - int i; =20 if (copy_from_kernel_nofault(ins, p, MCOUNT_INSN_SIZE)) { printk(KERN_CONT "%s[FAULT] %px\n", fmt, p); @@ -2024,9 +2023,7 @@ static void print_ip_ins(const char *fmt, const unsig= ned char *p) } =20 printk(KERN_CONT "%s", fmt); - - for (i =3D 0; i < MCOUNT_INSN_SIZE; i++) - printk(KERN_CONT "%s%02x", i ? ":" : "", ins[i]); + pr_cont("%*phC", MCOUNT_INSN_SIZE, ins); } =20 enum ftrace_bug_type ftrace_bug_type; --=20 2.25.1