public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 1/1] signal: Use %*ph for printing hexdump of a small buffer
@ 2023-06-12 22:03 Andy Shevchenko
  2023-06-13 13:19 ` David Laight
  0 siblings, 1 reply; 2+ messages in thread
From: Andy Shevchenko @ 2023-06-12 22:03 UTC (permalink / raw)
  To: linux-kernel; +Cc: Dave Hansen, Andy Shevchenko

The kernel already has a helper to print a hexdump of a small
buffer via pointer extension. Use that instead of open coded
variant.

In long term it helps to kill pr_cont() or at least narrow down
its use.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 kernel/signal.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/kernel/signal.c b/kernel/signal.c
index b5370fe5c198..6be2df76f0b4 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -1259,18 +1259,17 @@ static void print_fatal_signal(int signr)
 	pr_info("potentially unexpected fatal signal %d.\n", signr);
 
 #if defined(__i386__) && !defined(__arch_um__)
-	pr_info("code at %08lx: ", regs->ip);
 	{
+		unsigned char insn[16];
 		int i;
+
 		for (i = 0; i < 16; i++) {
-			unsigned char insn;
-
-			if (get_user(insn, (unsigned char *)(regs->ip + i)))
+			if (get_user(insn[i], (unsigned char __user *)(regs->ip + i)))
 				break;
-			pr_cont("%02x ", insn);
 		}
+
+		pr_info("code at %08lx: %*ph\n", regs->ip, i, insn);
 	}
-	pr_cont("\n");
 #endif
 	preempt_disable();
 	show_regs(regs);
-- 
2.40.0.1.gaa8946217a0b


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* RE: [PATCH v1 1/1] signal: Use %*ph for printing hexdump of a small buffer
  2023-06-12 22:03 [PATCH v1 1/1] signal: Use %*ph for printing hexdump of a small buffer Andy Shevchenko
@ 2023-06-13 13:19 ` David Laight
  0 siblings, 0 replies; 2+ messages in thread
From: David Laight @ 2023-06-13 13:19 UTC (permalink / raw)
  To: 'Andy Shevchenko', linux-kernel@vger.kernel.org; +Cc: Dave Hansen

From: Andy Shevchenko
> Sent: 12 June 2023 23:04
> 
> The kernel already has a helper to print a hexdump of a small
> buffer via pointer extension. Use that instead of open coded
> variant.
> 
> In long term it helps to kill pr_cont() or at least narrow down
> its use.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  kernel/signal.c | 11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/kernel/signal.c b/kernel/signal.c
> index b5370fe5c198..6be2df76f0b4 100644
> --- a/kernel/signal.c
> +++ b/kernel/signal.c
> @@ -1259,18 +1259,17 @@ static void print_fatal_signal(int signr)
>  	pr_info("potentially unexpected fatal signal %d.\n", signr);
> 
>  #if defined(__i386__) && !defined(__arch_um__)
> -	pr_info("code at %08lx: ", regs->ip);
>  	{
> +		unsigned char insn[16];
>  		int i;
> +
>  		for (i = 0; i < 16; i++) {
> -			unsigned char insn;
> -
> -			if (get_user(insn, (unsigned char *)(regs->ip + i)))
> +			if (get_user(insn[i], (unsigned char __user *)(regs->ip + i)))
>  				break;
> -			pr_cont("%02x ", insn);
>  		}

Isn't that just:
		i = 16 - copy_from_user(insn, (unsigned char __user *)regs->ip, 16);
(the 16 should be sizeof (insn))

	David

> +
> +		pr_info("code at %08lx: %*ph\n", regs->ip, i, insn);
>  	}
> -	pr_cont("\n");
>  #endif
>  	preempt_disable();
>  	show_regs(regs);
> --
> 2.40.0.1.gaa8946217a0b

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-06-13 13:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-12 22:03 [PATCH v1 1/1] signal: Use %*ph for printing hexdump of a small buffer Andy Shevchenko
2023-06-13 13:19 ` David Laight

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox