From patchwork Mon Aug 21 22:28:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hauke Mehrtens X-Patchwork-Id: 9913901 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id ED6ED603FF for ; Mon, 21 Aug 2017 22:28:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CDAD9286AA for ; Mon, 21 Aug 2017 22:28:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C2D52286B8; Mon, 21 Aug 2017 22:28:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 69B8C286AB for ; Mon, 21 Aug 2017 22:28:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754409AbdHUW2r (ORCPT ); Mon, 21 Aug 2017 18:28:47 -0400 Received: from mx2.mailbox.org ([80.241.60.215]:42942 "EHLO mx2.mailbox.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754260AbdHUW2q (ORCPT ); Mon, 21 Aug 2017 18:28:46 -0400 Received: from smtp1.mailbox.org (smtp1.mailbox.org [80.241.60.240]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx2.mailbox.org (Postfix) with ESMTPS id 4D377469EA; Tue, 22 Aug 2017 00:28:45 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp1.mailbox.org ([80.241.60.240]) by spamfilter02.heinlein-hosting.de (spamfilter02.heinlein-hosting.de [80.241.56.116]) (amavisd-new, port 10030) with ESMTP id gdSdcPpQG9y8; Tue, 22 Aug 2017 00:28:43 +0200 (CEST) From: Hauke Mehrtens To: johannes@sipsolutions.net Cc: backports@vger.kernel.org, Hauke Mehrtens Subject: [PATCH 11/21] backport: add __print_array() Date: Tue, 22 Aug 2017 00:28:07 +0200 Message-Id: <20170821222817.17376-12-hauke@hauke-m.de> In-Reply-To: <20170821222817.17376-1-hauke@hauke-m.de> References: <20170821222817.17376-1-hauke@hauke-m.de> Sender: backports-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: backports@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This is used in the tracing system and needed by wireless now, it was introduced in commit 6ea22486ba46bc ("tracing: Add array printing helper"). This code is copied from kernel 4.0. Signed-off-by: Hauke Mehrtens --- backport/backport-include/linux/ftrace_event.h | 10 ++++++ backport/backport-include/trace/ftrace.h | 9 +++++ backport/compat/backport-4.0.c | 46 ++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 backport/backport-include/linux/ftrace_event.h create mode 100644 backport/backport-include/trace/ftrace.h diff --git a/backport/backport-include/linux/ftrace_event.h b/backport/backport-include/linux/ftrace_event.h new file mode 100644 index 00000000..edea21ee --- /dev/null +++ b/backport/backport-include/linux/ftrace_event.h @@ -0,0 +1,10 @@ +#ifndef __BACKPORT_LINUX_FTRACE_EVENT_H +#define __BACKPORT_LINUX_FTRACE_EVENT_H +#include_next + +#if LINUX_VERSION_IS_LESS(4,0,0) +const char *ftrace_print_array_seq(struct trace_seq *p, + const void *buf, int buf_len, + size_t el_size); +#endif +#endif /* __BACKPORT_LINUX_FTRACE_EVENT_H */ diff --git a/backport/backport-include/trace/ftrace.h b/backport/backport-include/trace/ftrace.h new file mode 100644 index 00000000..5fda0ce5 --- /dev/null +++ b/backport/backport-include/trace/ftrace.h @@ -0,0 +1,9 @@ +#undef __print_array +#define __print_array(array, count, el_size) \ + ({ \ + BUILD_BUG_ON(el_size != 1 && el_size != 2 && \ + el_size != 4 && el_size != 8); \ + ftrace_print_array_seq(p, array, count, el_size); \ + }) + +#include_next diff --git a/backport/compat/backport-4.0.c b/backport/compat/backport-4.0.c index 8ae16115..71095f19 100644 --- a/backport/compat/backport-4.0.c +++ b/backport/compat/backport-4.0.c @@ -14,6 +14,8 @@ #include #include #include +#include +#include #include static __always_inline long __get_user_pages_locked(struct task_struct *tsk, @@ -321,3 +323,47 @@ overflow1: return ascii ? ascii_column + len : (groupsize * 2 + 1) * ngroups - 1; } EXPORT_SYMBOL_GPL(hex_dump_to_buffer); + +const char * +ftrace_print_array_seq(struct trace_seq *p, const void *buf, int buf_len, + size_t el_size) +{ + const char *ret = trace_seq_buffer_ptr(p); + const char *prefix = ""; + void *ptr = (void *)buf; + + trace_seq_putc(p, '{'); + + while (ptr < buf + buf_len) { + switch (el_size) { + case 1: + trace_seq_printf(p, "%s0x%x", prefix, + *(u8 *)ptr); + break; + case 2: + trace_seq_printf(p, "%s0x%x", prefix, + *(u16 *)ptr); + break; + case 4: + trace_seq_printf(p, "%s0x%x", prefix, + *(u32 *)ptr); + break; + case 8: + trace_seq_printf(p, "%s0x%llx", prefix, + *(u64 *)ptr); + break; + default: + trace_seq_printf(p, "BAD SIZE:%zu 0x%x", el_size, + *(u8 *)ptr); + el_size = 1; + } + prefix = ","; + ptr += el_size; + } + + trace_seq_putc(p, '}'); + trace_seq_putc(p, 0); + + return ret; +} +EXPORT_SYMBOL(ftrace_print_array_seq);