17 Oct, 2020

1 commit

  • kernel.h is being used as a dump for all kinds of stuff for a long time.
    Here is the attempt to start cleaning it up by splitting out min()/max()
    et al. helpers.

    At the same time convert users in header and lib folder to use new header.
    Though for time being include new header back to kernel.h to avoid
    twisted indirected includes for other existing users.

    Signed-off-by: Andy Shevchenko
    Signed-off-by: Andrew Morton
    Cc: "Rafael J. Wysocki"
    Cc: Steven Rostedt
    Cc: Rasmus Villemoes
    Cc: Joe Perches
    Cc: Linus Torvalds
    Link: https://lkml.kernel.org/r/20200910164152.GA1891694@smile.fi.intel.com
    Signed-off-by: Linus Torvalds

    Andy Shevchenko
     

26 Sep, 2019

1 commit

  • I'm seeing a bunch of debug prints from a user of print_hex_dump_bytes()
    in my kernel logs, but I don't have CONFIG_DYNAMIC_DEBUG enabled nor do I
    have DEBUG defined in my build. The problem is that
    print_hex_dump_bytes() calls a wrapper function in lib/hexdump.c that
    calls print_hex_dump() with KERN_DEBUG level. There are three cases to
    consider here

    1. CONFIG_DYNAMIC_DEBUG=y --> call dynamic_hex_dum()
    2. CONFIG_DYNAMIC_DEBUG=n && DEBUG --> call print_hex_dump()
    3. CONFIG_DYNAMIC_DEBUG=n && !DEBUG --> stub it out

    Right now, that last case isn't detected and we still call
    print_hex_dump() from the stub wrapper.

    Let's make print_hex_dump_bytes() only call print_hex_dump_debug() so that
    it works properly in all cases.

    Case #1, print_hex_dump_debug() calls dynamic_hex_dump() and we get same
    behavior. Case #2, print_hex_dump_debug() calls print_hex_dump() with
    KERN_DEBUG and we get the same behavior. Case #3, print_hex_dump_debug()
    is a nop, changing behavior to what we want, i.e. print nothing.

    Link: http://lkml.kernel.org/r/20190816235624.115280-1-swboyd@chromium.org
    Signed-off-by: Stephen Boyd
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Stephen Boyd
     

19 Jun, 2019

1 commit

  • Based on 1 normalized pattern(s):

    this program is free software you can redistribute it and or modify
    it under the terms of the gnu general public license version 2 as
    published by the free software foundation see readme and copying for
    more details

    extracted by the scancode license scanner the SPDX license identifier

    GPL-2.0-only

    has been chosen to replace the boilerplate/reference in 9 file(s).

    Signed-off-by: Thomas Gleixner
    Reviewed-by: Kate Stewart
    Reviewed-by: Enrico Weigelt
    Reviewed-by: Allison Randal
    Cc: linux-spdx@vger.kernel.org
    Link: https://lkml.kernel.org/r/20190604081207.060259192@linutronix.de
    Signed-off-by: Greg Kroah-Hartman

    Thomas Gleixner
     

09 Sep, 2017

1 commit

  • In some cases caller would like to use error code directly without
    shadowing.

    -EINVAL feels a rightful code to return in case of error in hex2bin().

    Link: http://lkml.kernel.org/r/20170731135510.68023-1-andriy.shevchenko@linux.intel.com
    Signed-off-by: Andy Shevchenko
    Cc: Arnd Bergmann
    Cc: Rasmus Villemoes
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Andy Shevchenko
     

07 Nov, 2015

1 commit

  • There is a classical off-by-one error in case when we try to place, for
    example, 1+1 bytes as hex in the buffer of size 6. The expected result is
    to get an output truncated, but in the reality we get 6 bytes filed
    followed by terminating NUL.

    Change the logic how we fill the output in case of byte dumping into
    limited space. This will follow the snprintf() behaviour by truncating
    output even on half bytes.

    Fixes: 114fc1afb2de (hexdump: make it return number of bytes placed in buffer)
    Signed-off-by: Andy Shevchenko
    Reported-by: Aaro Koskinen
    Tested-by: Aaro Koskinen
    Cc: Al Viro
    Cc: Catalin Marinas
    Cc:
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Andy Shevchenko
     

18 Jul, 2015

1 commit

  • A hexdump with a buf not aligned to the groupsize causes
    non-naturally-aligned memory accesses. This was causing a kernel panic
    on the processor BlackFin BF527, when such an unaligned buffer was fed
    by the function ubifs_scanned_corruption in fs/ubifs/scan.c .

    To fix this, change accesses to the contents of the buffer so they go
    through get_unaligned(). This change should be harmless to unaligned-
    access-capable architectures, and any performance hit should be anyway
    dwarfed by the snprintf() processing time.

    Signed-off-by: Horacio Mijail Antón Quiles
    Cc: Andy Shevchenko
    Cc: David Howells
    Cc: Vivek Goyal
    Cc: Joe Perches
    Acked-by: Geert Uytterhoeven
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Horacio Mijail Anton Quiles
     

13 Feb, 2015

3 commits

  • This patch makes hexdump return the number of bytes placed in the buffer
    excluding trailing NUL. In the case of overflow it returns the desired
    amount of bytes to produce the entire dump. Thus, it mimics snprintf().

    This will be useful for users that would like to repeat with a bigger
    buffer.

    [akpm@linux-foundation.org: fix printk warning]
    Signed-off-by: Andy Shevchenko
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Andy Shevchenko
     
  • Instead of doing calculations in each case of different groupsize let's do
    them beforehand. While there, change the switch to an if-else-if
    construction.

    Signed-off-by: Andy Shevchenko
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Andy Shevchenko
     
  • In the current implementation we have a floating ascii column in the tail
    of the dump.

    For example, for row size equal to 16 the ascii column as in following
    table

    group size \ length 8 12 16
    1 50 50 50
    2 22 32 42
    4 20 29 38
    8 19 - 36

    This patch makes it the same independently of amount of bytes dumped.

    The change is safe since all current users, which use ASCII part of the
    dump, rely on the group size equal to 1. The patch doesn't change
    behaviour for such group size (see the table above).

    Signed-off-by: Andy Shevchenko
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Andy Shevchenko
     

17 Sep, 2014

1 commit


21 Sep, 2013

1 commit


18 Jan, 2013

1 commit

  • Introduce print_hex_dump_debug() that can be dynamically controlled, similar to
    pr_debug.

    Also, make print_hex_dump_bytes() dynamically controlled

    Implement only 'p' flag (_DPRINTK_FLAGS_PRINT) to keep it simple since hex dump prints
    multiple lines and long prefix would impact readability.
    To provide line/file etc. information, use pr_debug or similar
    before/after print_hex_dump_debug()

    Signed-off-by: Vladimir Kondratiev
    Signed-off-by: Jason Baron
    Signed-off-by: Greg Kroah-Hartman

    Vladimir Kondratiev
     

08 Mar, 2012

1 commit


21 Sep, 2011

1 commit

  • hex2bin converts a hexadecimal string to its binary representation.
    The original version of hex2bin did not do any error checking. This
    patch adds error checking and returns the result.

    Changelog v1:
    - removed unpack_hex_byte()
    - changed return code from boolean to int

    Changelog:
    - use the new unpack_hex_byte()
    - add __must_check compiler option (Andy Shevchenko's suggestion)
    - change function API to return error checking result
    (based on Tetsuo Handa's initial patch)

    Signed-off-by: Mimi Zohar
    Acked-by: Andy Shevchenko

    Mimi Zohar
     

14 Jan, 2011

1 commit


29 Nov, 2010

1 commit

  • Similar to the kgdb_hex2mem() code, hex2bin converts a string
    to binary using the hex_to_bin() library call.

    Changelog:
    - Replace parameter names with src/dst (based on David Howell's comment)
    - Add 'const' where needed (based on David Howell's comment)
    - Replace int with size_t (based on David Howell's comment)

    Signed-off-by: Mimi Zohar
    Acked-by: Serge E. Hallyn
    Acked-by: David Howells
    Signed-off-by: James Morris

    Mimi Zohar
     

25 May, 2010

2 commits

  • hex_to_bin() is a little method which converts hex digit to its actual
    value. There are plenty of places where such functionality is needed.

    [akpm@linux-foundation.org: use tolower(), saving 3 bytes, test the more common case first - it's quicker]
    [akpm@linux-foundation.org: relocate tolower to make it even faster! (Joe)]
    Signed-off-by: Andy Shevchenko
    Cc: Tilman Schmidt
    Cc: Duncan Sands
    Cc: Eric W. Biederman
    Cc: Greg Kroah-Hartman
    Cc: "Richard Russon (FlatCap)"
    Cc: John W. Linville
    Cc: Len Brown
    Cc: Joe Perches
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Andy Shevchenko
     
  • Reduce char linebuf[200] to the actual size required., which is 32 * 3 + 2
    + 32 + 1, ie: linebuf[131].

    Change examples to use bool true not int 1.

    Align multiline argument indentation to open parenthesis.

    Use temporary for ptr[j] so trigraph fits on single line.

    Convert printk ptr from %*p, (int)(2 * sizeof(void *)) to %p as %p uses
    the same calculation for size.

    Signed-off-by: Joe Perches
    Cc: Randy Dunlap
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Joe Perches
     

17 Jun, 2009

1 commit

  • For example:
    hex_dump_to_buffer("AB", 2, 16, 1, buf, 100, 0);
    pr_info("[%s]\n", buf);

    I'd expect the output to be "[41 42]", but actually it's "[41 42 ]"

    This patch also makes the required buf to be minimum. To print the hex
    format of "AB", a buf with size 6 should be sufficient, but
    hex_dump_to_buffer() required at least 8.

    Signed-off-by: Li Zefan
    Acked-by: Randy Dunlap
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Li Zefan
     

15 May, 2008

1 commit

  • Add a common hex array in hexdump.c so everyone can use it.

    Add a common hi/lo helper to avoid the shifting masking that is
    done to get the upper and lower nibbles of a byte value.

    Pull the pack_hex_byte helper from kgdb as it is opencoded many
    places in the tree that will be consolidated.

    Signed-off-by: Harvey Harrison
    Acked-by: Paul Mundt
    Cc: Jason Wessel
    Cc: Ingo Molnar
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Harvey Harrison
     

30 Nov, 2007

1 commit

  • As Herbert Xu pointed out, bytes (chars) with bit 7 (0x80) set are true
    with isprint() but they may not be isascii() but be Unicode instead, so
    don't try to print them in hex dumps.

    Signed-off-by: Randy Dunlap
    Cc: Herbert Xu
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Randy Dunlap
     

12 Aug, 2007

1 commit

  • Add missing "const" qualifiers to the print_hex_dump_bytes() library routines.

    (akpm: rumoured to fix some compile warning somewhere)

    Signed-off-by: Alan Stern
    Cc: Artem Bityutskiy
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Alan Stern
     

09 Aug, 2007

1 commit

  • Trivial fix: mark the buffer to hexdump as const so callers could avoid
    casting their const buffers when calling print_hex_dump().

    The patch is really trivial and I suggest to consider it as a fix
    (it fixes GCC warnings) and push it to current tree.

    Signed-off-by: Artem Bityutskiy
    Signed-off-by: Linus Torvalds

    Artem Bityutskiy
     

09 Jun, 2007

1 commit

  • Add a prefix string parameter. Callers are responsible for any string
    length/alignment that they want to see in the output. I.e., callers should
    pad strings to achieve alignment if they want that.

    Add rowsize parameter. This is the number of raw data bytes to be printed
    per line. Must be 16 or 32.

    Add a groupsize parameter. This allows callers to dump values as 1-byte,
    2-byte, 4-byte, or 8-byte numbers. Default is 1-byte numbers. If the
    total length is not an even multiple of groupsize, 1-byte numbers are
    printed.

    Add an "ascii" output parameter. This causes ASCII data output following
    the hex data output.

    Clean up some doc examples.

    Align the ASCII output on all lines that are produced by one call.

    Add a new interface, print_hex_dump_bytes(), that is a shortcut to
    print_hex_dump(), using default parameter values to print 16 bytes in
    byte-size chunks of hex + ASCII output, using printk level KERN_DEBUG.

    Signed-off-by: Randy Dunlap
    Cc: Christoph Lameter
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Randy Dunlap
     

11 May, 2007

1 commit

  • Based on ace_dump_mem() from Grant Likely for the Xilinx SystemACE
    CompactFlash interface.

    Add print_hex_dump() & hex_dumper() to lib/hexdump.c and linux/kernel.h.

    This patch adds the functions print_hex_dump() & hex_dumper().
    print_hex_dump() can be used to perform a hex + ASCII dump of data to
    syslog, in an easily viewable format, thus providing a common text hex dump
    format.

    hex_dumper() provides a dump-to-memory function. It converts one "line" of
    output (16 bytes of input) at a time.

    Example usages:
    print_hex_dump(KERN_DEBUG, DUMP_PREFIX_ADDRESS, frame->data, frame->len);
    hex_dumper(frame->data, frame->len, linebuf, sizeof(linebuf));

    Example output using %DUMP_PREFIX_OFFSET:
    0009ab42: 40414243 44454647 48494a4b 4c4d4e4f-@ABCDEFG HIJKLMNO
    Example output using %DUMP_PREFIX_ADDRESS:
    ffffffff88089af0: 70717273 74757677 78797a7b 7c7d7e7f-pqrstuvw xyz{|}~.

    [akpm@linux-foundation.org: cleanups, add export]
    Signed-off-by: Randy Dunlap
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Randy Dunlap