RE: [PATCH 2/4] lib/hexdump.c: Optionally suppress lines of filler bytes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> -----Original Message-----
> From: Petr Mladek <pmladek@xxxxxxxx>
> Sent: Saturday, 13 April 2019 12:04 AM
> To: Alastair D'Silva <alastair@xxxxxxxxxxx>
> Cc: alastair@xxxxxxxxxxx; Jani Nikula <jani.nikula@xxxxxxxxxxxxxxx>;
Joonas
> Lahtinen <joonas.lahtinen@xxxxxxxxxxxxxxx>; Rodrigo Vivi
> <rodrigo.vivi@xxxxxxxxx>; David Airlie <airlied@xxxxxxxx>; Daniel Vetter
> <daniel@xxxxxxxx>; Karsten Keil <isdn@xxxxxxxxxxxxxx>; Jassi Brar
> <jassisinghbrar@xxxxxxxxx>; Tom Lendacky <thomas.lendacky@xxxxxxx>;
> David S. Miller <davem@xxxxxxxxxxxxx>; Jose Abreu
> <Jose.Abreu@xxxxxxxxxxxx>; Kalle Valo <kvalo@xxxxxxxxxxxxxx>;
> Stanislaw Gruszka <sgruszka@xxxxxxxxxx>; Benson Leung
> <bleung@xxxxxxxxxxxx>; Enric Balletbo i Serra
> <enric.balletbo@xxxxxxxxxxxxx>; James E.J. Bottomley
> <jejb@xxxxxxxxxxxxx>; Martin K. Petersen <martin.petersen@xxxxxxxxxx>;
> Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>; Alexander Viro
> <viro@xxxxxxxxxxxxxxxxxx>; Sergey Senozhatsky
> <sergey.senozhatsky@xxxxxxxxx>; Steven Rostedt <rostedt@xxxxxxxxxxx>;
> Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>; intel-
> gfx@xxxxxxxxxxxxxxxxxxxxx; dri-devel@xxxxxxxxxxxxxxxxxxxxx; linux-
> kernel@xxxxxxxxxxxxxxx; netdev@xxxxxxxxxxxxxxx;
> ath10k@xxxxxxxxxxxxxxxxxxx; linux-wireless@xxxxxxxxxxxxxxx; linux-
> scsi@xxxxxxxxxxxxxxx; linux-fbdev@xxxxxxxxxxxxxxx;
> devel@xxxxxxxxxxxxxxxxxxxx; linux-fsdevel@xxxxxxxxxxxxxxx
> Subject: Re: [PATCH 2/4] lib/hexdump.c: Optionally suppress lines of
filler
> bytes
> 
> On Wed 2019-04-10 13:17:18, Alastair D'Silva wrote:
> > From: Alastair D'Silva <alastair@xxxxxxxxxxx>
> >
> > Some buffers may only be partially filled with useful data, while the
> > rest is padded (typically with 0x00 or 0xff).
> >
> > This patch introduces flags which allow lines of padding bytes to be
> > suppressed, making the output easier to interpret:
> > HEXDUMP_SUPPRESS_0X00, HEXDUMP_SUPPRESS_0XFF
> >
> > The first and last lines are not suppressed by default, so the
> > function always outputs something. This behaviour can be further
> > controlled with the HEXDUMP_SUPPRESS_FIRST &
> HEXDUMP_SUPPRESS_LAST flags.
> >
> > An inline wrapper function is provided for backwards compatibility
> > with existing code, which maintains the original behaviour.
> >
> 
> > diff --git a/lib/hexdump.c b/lib/hexdump.c index
> > b8a164814744..2f3bafb55a44 100644
> > --- a/lib/hexdump.c
> > +++ b/lib/hexdump.c
> > +void print_hex_dump_ext(const char *level, const char *prefix_str,
> > +			int prefix_type, int rowsize, int groupsize,
> > +			const void *buf, size_t len, u64 flags)
> >  {
> >  	const u8 *ptr = buf;
> > -	int i, linelen, remaining = len;
> > +	int i, remaining = len;
> >  	unsigned char linebuf[64 * 3 + 2 + 64 + 1];
> > +	bool first_line = true;
> >
> >  	if (rowsize != 16 && rowsize != 32 && rowsize != 64)
> >  		rowsize = 16;
> >
> >  	for (i = 0; i < len; i += rowsize) {
> > -		linelen = min(remaining, rowsize);
> > +		bool skip = false;
> > +		int linelen = min(remaining, rowsize);
> > +
> >  		remaining -= rowsize;
> >
> > +		if (flags & HEXDUMP_SUPPRESS_0X00)
> > +			skip = buf_is_all(ptr + i, linelen, 0x00);
> > +
> > +		if (!skip && (flags & HEXDUMP_SUPPRESS_0XFF))
> > +			skip = buf_is_all(ptr + i, linelen, 0xff);
> > +
> > +		if (first_line && !(flags & HEXDUMP_SUPPRESS_FIRST))
> > +			skip = false;
> > +
> > +		if (remaining <= 0 && !(flags & HEXDUMP_SUPPRESS_LAST))
> > +			skip = false;
> > +
> > +		if (skip)
> > +			continue;
> 
> IMHO, quietly skipping lines could cause a lot of confusion, espcially
when
> the address is not printed.
>
It's up to the caller to decide how they want it displayed.

> I wonder how it would look like when we print something like:
> 
>     --- skipped XX lines full of 0x00 ---

This could be added as a later enhancement, with a new flag (eg.
HEXDUMP_SUPPRESS_VERBOSE).

> 
> Then we might even remove the SUPPRESS_FIRST, SUPPRESS_LAST and the
> ambiguous QUIET flags.
> 
> > +
> > +		first_line = false;
> 
> This should be above the if (skip).
> 
> > +
> >  		hex_dump_to_buffer(ptr + i, linelen, rowsize, groupsize,
> > -				   linebuf, sizeof(linebuf), ascii);
> > +				   linebuf, sizeof(linebuf),
> > +				   flags & HEXDUMP_ASCII);
> >
> >  		switch (prefix_type) {
> >  		case DUMP_PREFIX_ADDRESS:
> > @@ -272,7 +316,7 @@ void print_hex_dump(const char *level, const char
> *prefix_str, int prefix_type,
> >  		}
> >  	}
> >  }
> > -EXPORT_SYMBOL(print_hex_dump);
> > +EXPORT_SYMBOL(print_hex_dump_ext);
> 
> We should still export even the original function that is still used
everywhere.

It's replaced with an inline wrapper function, there's no need to export it.

-- 
Alastair D'Silva           mob: 0423 762 819
skype: alastair_dsilva     msn: alastair@xxxxxxxxxxx
blog: http://alastair.d-silva.org    Twitter: @EvilDeece



_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel



[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux