From patchwork Thu Apr 19 01:34:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 133679 Delivered-To: patch@linaro.org Received: by 10.46.66.142 with SMTP id h14csp88164ljf; Wed, 18 Apr 2018 18:34:46 -0700 (PDT) X-Google-Smtp-Source: AIpwx48/iToJbkHJWNjmjwLByzvxhH/Q+QM9YwxKnTaHKEXeWQCeplbIXVi97U/DED5NXNEIKy7t X-Received: by 10.101.91.73 with SMTP id y9mr3426636pgr.93.1524101686546; Wed, 18 Apr 2018 18:34:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524101686; cv=none; d=google.com; s=arc-20160816; b=piNIT+XfpRorFkWX8IIyjUPnK5O7/7VYVdEZ0oIjrB2kT6+ubj8SZoe6ctFr5IyxNH xkiQvTeDD3XDpnSX5fHq5ot7Vl8CQBhTSyQUTJtOwpEKt9Nn1VbCCYsB6buz7elX0kac WwcZImA5zY83aKZyHnSi6vslQ/udA9raMCT3zPcjX5KlKmTgk9QCVNuWE+t7DfvNVU7B Exxquq5QXFWX/kRWec6MZo/Cn0W7mtdNUzfurV32vg4Rk3bK64ucL3szL8X3BqsSAI3a gdziXOTqrikGv0YRT5V9JajAhG18qsLt7f5Qt10gAPudoNUUkC8NsOh8MvT/bgiijzxY NBxg== 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:dkim-signature:arc-authentication-results; bh=afsRL9gkwOKNylX66mBBa9diOhkIPMbJz9/FrnqwgzU=; b=kPFYpjpU0MV3Ye8SB4hhuru17sKn88sTyA4kT7S6Txzz8buBAcUu8cmevmicF/1rBz LNElE6gyzb1pFI5GBRxLz+vl3VASNwfI2jLc6hNFG6ebBlI0Pb5u28YmtIxkqptw4pB1 /xwUl3DODbB+h29a3htwRZQkK9dcyt6xdD3h47NQ5zxSZ+3LT4X4UpziAe7/R+/B6E53 CZxuohAo5mdYjwBM8w9EESMC3NPYo59Jx9A+eoQrVoaDLSWxjDikP8iOwWVBh7FcrSAi HKV8HiJ6Jy42XjP2ucqVcLriyjDvFo+HHAVBoyW+QssHSk99aFidAHRMpQ/cswY8rYOi vwRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fgTjjZGr; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p12-v6si2399718pls.578.2018.04.18.18.34.46; Wed, 18 Apr 2018 18:34:46 -0700 (PDT) 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; dkim=pass header.i=@linaro.org header.s=google header.b=fgTjjZGr; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753352AbeDSBen (ORCPT + 29 others); Wed, 18 Apr 2018 21:34:43 -0400 Received: from mail-oi0-f66.google.com ([209.85.218.66]:34813 "EHLO mail-oi0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753128AbeDSBel (ORCPT ); Wed, 18 Apr 2018 21:34:41 -0400 Received: by mail-oi0-f66.google.com with SMTP id e23-v6so3406481oiy.1 for ; Wed, 18 Apr 2018 18:34:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=afsRL9gkwOKNylX66mBBa9diOhkIPMbJz9/FrnqwgzU=; b=fgTjjZGrBZ6SQq/TevzkY9op6GlPvF6rasEkuoRs0B7Y3sh7A3TRgh654F1n4nmQeo gLUvLiUrX9ZKGk2hTARmXbDhSL7OoTcPR7JIiniss7kC6dCY8p1+PRihRB/RHbAN1XWN ADrSzCPMQMTCR+0+rIN6fD7/9qMoFJYQ/itfw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=afsRL9gkwOKNylX66mBBa9diOhkIPMbJz9/FrnqwgzU=; b=pTcbak6u7WTWgjyKjseNSS57rpztYM65fiygGvc3vuW9H3y4miAb6qfk0Ks1VNlCf7 0LUoCK6Oy+UdqnzVkj5M1OMA6AM3MykHbb0MFm1sapMXqsBi7toaVgnKUcISX6O7tH4l lnu9VtiNAxhR9uBp4lb3C7qtt+s9Kc7MOED8L+JKCzusVkWk/3uPH6jAWIr9HVzc0rVI JZO8vF7CnIDrW0l8WkU36w6QR7urRLR002/mGocS1ppeGHz92NflFyTgFTrYD+Rl81yl nDotRkDAGx6teT/jrToIQUvvmdgD2hMHrAaxBJRCwaA49D6Q0PTFgNP6Epjb+47Mu/Vz FPYw== X-Gm-Message-State: ALQs6tCjFYSExxfeSiVDHHUYoN8zmme9433Xgc34NsCrK9rG1nqZNHiN 6OMda0oX9bwWzaukLROsUXBNQCCuGb8= X-Received: by 2002:aca:42d5:: with SMTP id p204-v6mr2593201oia.264.1524101680460; Wed, 18 Apr 2018 18:34:40 -0700 (PDT) Received: from localhost.localdomain (li973-238.members.linode.com. [45.33.19.238]) by smtp.gmail.com with ESMTPSA id m84-v6sm1389662oia.1.2018.04.18.18.34.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 18 Apr 2018 18:34:39 -0700 (PDT) From: Leo Yan To: Alexei Starovoitov , Daniel Borkmann , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [PATCH bpf-next 5/5] samples/bpf: Handle NULL pointer returned by ksym_search() Date: Thu, 19 Apr 2018 09:34:06 +0800 Message-Id: <1524101646-6544-6-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1524101646-6544-1-git-send-email-leo.yan@linaro.org> References: <1524101646-6544-1-git-send-email-leo.yan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This commit handles NULL pointer returned by ksym_search() to directly print address hexadecimal value, the change is applied in 'trace_event', 'spintest' and 'offwaketime' programs. Signed-off-by: Leo Yan --- samples/bpf/offwaketime_user.c | 5 +++++ samples/bpf/spintest_user.c | 5 ++++- samples/bpf/trace_event_user.c | 5 +++++ 3 files changed, 14 insertions(+), 1 deletion(-) -- 1.9.1 diff --git a/samples/bpf/offwaketime_user.c b/samples/bpf/offwaketime_user.c index 512f87a..fce2113 100644 --- a/samples/bpf/offwaketime_user.c +++ b/samples/bpf/offwaketime_user.c @@ -27,6 +27,11 @@ static void print_ksym(__u64 addr) if (!addr) return; sym = ksym_search(addr); + if (!sym) { + printf("%llx;", addr); + return; + } + if (PRINT_RAW_ADDR) printf("%s/%llx;", sym->name, addr); else diff --git a/samples/bpf/spintest_user.c b/samples/bpf/spintest_user.c index 3d73621..3140803 100644 --- a/samples/bpf/spintest_user.c +++ b/samples/bpf/spintest_user.c @@ -36,7 +36,10 @@ int main(int ac, char **argv) bpf_map_lookup_elem(map_fd[0], &next_key, &value); assert(next_key == value); sym = ksym_search(value); - printf(" %s", sym->name); + if (!sym) + printf(" %lx", value); + else + printf(" %s", sym->name); key = next_key; } if (key) diff --git a/samples/bpf/trace_event_user.c b/samples/bpf/trace_event_user.c index 56f7a25..d2ab33e 100644 --- a/samples/bpf/trace_event_user.c +++ b/samples/bpf/trace_event_user.c @@ -33,6 +33,11 @@ static void print_ksym(__u64 addr) if (!addr) return; sym = ksym_search(addr); + if (!sym) { + printf("%llx;", addr); + return; + } + printf("%s;", sym->name); if (!strcmp(sym->name, "sys_read")) sys_read_seen = true;