From patchwork Wed Jul 9 15:24:26 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 4517561 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 71381BEEAA for ; Wed, 9 Jul 2014 15:28:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9E81A202F0 for ; Wed, 9 Jul 2014 15:28:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B5EB62024C for ; Wed, 9 Jul 2014 15:28:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932620AbaGIPYr (ORCPT ); Wed, 9 Jul 2014 11:24:47 -0400 Received: from mga03.intel.com ([143.182.124.21]:22124 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932591AbaGIPYp (ORCPT ); Wed, 9 Jul 2014 11:24:45 -0400 Received: from azsmga001.ch.intel.com ([10.2.17.19]) by azsmga101.ch.intel.com with ESMTP; 09 Jul 2014 08:24:42 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.01,631,1400050800"; d="scan'208";a="455005950" Received: from smile.fi.intel.com ([10.237.72.73]) by azsmga001.ch.intel.com with ESMTP; 09 Jul 2014 08:24:33 -0700 Received: from andy by smile.fi.intel.com with local (Exim 4.82_1-5b7a7c0-XX) (envelope-from ) id 1X4tjT-0006xN-LO; Wed, 09 Jul 2014 18:24:31 +0300 From: Andy Shevchenko To: Tadeusz Struk , Herbert Xu , Mauro Carvalho Chehab , Helge Deller , Ingo Tuchscherer , linux390@de.ibm.com, Alexander Viro , qat-linux@intel.com, linux-crypto@vger.kernel.org, linux-media@vger.kernel.org, linux-s390@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Andy Shevchenko Subject: [PATCH v1 1/5] seq_file: provide an analogue of print_hex_dump() Date: Wed, 9 Jul 2014 18:24:26 +0300 Message-Id: <1404919470-26668-2-git-send-email-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.0.1 In-Reply-To: <1404919470-26668-1-git-send-email-andriy.shevchenko@linux.intel.com> References: <1404919470-26668-1-git-send-email-andriy.shevchenko@linux.intel.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The new seq_hex_dump() is a complete analogue of print_hex_dump(). We have few users of this functionality already. It allows to reduce their codebase. Signed-off-by: Andy Shevchenko --- fs/seq_file.c | 35 +++++++++++++++++++++++++++++++++++ include/linux/seq_file.h | 4 ++++ 2 files changed, 39 insertions(+) diff --git a/fs/seq_file.c b/fs/seq_file.c index 3857b72..fec4a6b 100644 --- a/fs/seq_file.c +++ b/fs/seq_file.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -794,6 +795,40 @@ void seq_pad(struct seq_file *m, char c) } EXPORT_SYMBOL(seq_pad); +/* Analogue of print_hex_dump() */ +void seq_hex_dump(struct seq_file *m, const char *prefix_str, int prefix_type, + int rowsize, int groupsize, const void *buf, size_t len, + bool ascii) +{ + const u8 *ptr = buf; + int i, linelen, remaining = len; + unsigned char linebuf[32 * 3 + 2 + 32 + 1]; + + if (rowsize != 16 && rowsize != 32) + rowsize = 16; + + for (i = 0; i < len; i += rowsize) { + linelen = min(remaining, rowsize); + remaining -= rowsize; + + hex_dump_to_buffer(ptr + i, linelen, rowsize, groupsize, + linebuf, sizeof(linebuf), ascii); + + switch (prefix_type) { + case DUMP_PREFIX_ADDRESS: + seq_printf(m, "%s%p: %s\n", prefix_str, ptr + i, linebuf); + break; + case DUMP_PREFIX_OFFSET: + seq_printf(m, "%s%.8x: %s\n", prefix_str, i, linebuf); + break; + default: + seq_printf(m, "%s%s\n", prefix_str, linebuf); + break; + } + } +} +EXPORT_SYMBOL(seq_hex_dump); + struct list_head *seq_list_start(struct list_head *head, loff_t pos) { struct list_head *lh; diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h index 52e0097..6a8be4c 100644 --- a/include/linux/seq_file.h +++ b/include/linux/seq_file.h @@ -107,6 +107,10 @@ int seq_write(struct seq_file *seq, const void *data, size_t len); __printf(2, 3) int seq_printf(struct seq_file *, const char *, ...); __printf(2, 0) int seq_vprintf(struct seq_file *, const char *, va_list args); +void seq_hex_dump(struct seq_file *m, const char *prefix_str, int prefix_type, + int rowsize, int groupsize, const void *buf, size_t len, + bool ascii); + int seq_path(struct seq_file *, const struct path *, const char *); int seq_dentry(struct seq_file *, struct dentry *, const char *); int seq_path_root(struct seq_file *m, const struct path *path,