kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch] dma-debug: debugfs_create_bool() takes a u32 pointer
@ 2012-03-02  6:58 Dan Carpenter
  2012-03-02 11:22 ` Neil Horman
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2012-03-02  6:58 UTC (permalink / raw)
  To: Joerg Roedel
  Cc: Stanislaw Gruszka, Paul Gortmaker, Neil Horman, Alan Stern,
	linux-kernel, kernel-janitors

Even though it has "bool" in the name, you have pass a u32 pointer to
debugfs_create_bool().  Otherwise you get memory corruption in
write_file_bool().  Fortunately in this case the corruption happens in
an alignment hole between variables so it doesn't cause any problems.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/lib/dma-debug.c b/lib/dma-debug.c
index 13ef233..08cd5a6 100644
--- a/lib/dma-debug.c
+++ b/lib/dma-debug.c
@@ -78,7 +78,7 @@ static LIST_HEAD(free_entries);
 static DEFINE_SPINLOCK(free_entries_lock);
 
 /* Global disable flag - will be set in case of an error */
-static bool global_disable __read_mostly;
+static u32 global_disable __read_mostly;
 
 /* Global error count */
 static u32 error_count;
@@ -657,7 +657,7 @@ static int dma_debug_fs_init(void)
 
 	global_disable_dent = debugfs_create_bool("disabled", 0444,
 			dma_debug_dent,
-			(u32 *)&global_disable);
+			&global_disable);
 	if (!global_disable_dent)
 		goto out_err;
 

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

* Re: [patch] dma-debug: debugfs_create_bool() takes a u32 pointer
  2012-03-02  6:58 [patch] dma-debug: debugfs_create_bool() takes a u32 pointer Dan Carpenter
@ 2012-03-02 11:22 ` Neil Horman
  2012-03-02 12:55   ` Dan Carpenter
  0 siblings, 1 reply; 3+ messages in thread
From: Neil Horman @ 2012-03-02 11:22 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Joerg Roedel, Stanislaw Gruszka, Paul Gortmaker, Alan Stern,
	linux-kernel, kernel-janitors

On Fri, Mar 02, 2012 at 09:58:32AM +0300, Dan Carpenter wrote:
> Even though it has "bool" in the name, you have pass a u32 pointer to
> debugfs_create_bool().  Otherwise you get memory corruption in
> write_file_bool().  Fortunately in this case the corruption happens in
> an alignment hole between variables so it doesn't cause any problems.
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> diff --git a/lib/dma-debug.c b/lib/dma-debug.c
> index 13ef233..08cd5a6 100644
> --- a/lib/dma-debug.c
> +++ b/lib/dma-debug.c
> @@ -78,7 +78,7 @@ static LIST_HEAD(free_entries);
>  static DEFINE_SPINLOCK(free_entries_lock);
>  
>  /* Global disable flag - will be set in case of an error */
> -static bool global_disable __read_mostly;
> +static u32 global_disable __read_mostly;
>  
>  /* Global error count */
>  static u32 error_count;
> @@ -657,7 +657,7 @@ static int dma_debug_fs_init(void)
>  
>  	global_disable_dent = debugfs_create_bool("disabled", 0444,
>  			dma_debug_dent,
> -			(u32 *)&global_disable);
> +			&global_disable);
>  	if (!global_disable_dent)
>  		goto out_err;
>  
> 


This certainly works, but a quick search of call sites shows this isn't the only
place someone passes a bool to debugfs_create_bool. I think the better solution
would be to change debugfs_create_bool and its corresponding read/write methods
to actually work with a bool type, and then clean all the call sites to pass in
a bool properly, instead of a u32.

Thanks
Neil


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

* Re: [patch] dma-debug: debugfs_create_bool() takes a u32 pointer
  2012-03-02 11:22 ` Neil Horman
@ 2012-03-02 12:55   ` Dan Carpenter
  0 siblings, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2012-03-02 12:55 UTC (permalink / raw)
  To: Neil Horman
  Cc: Joerg Roedel, Stanislaw Gruszka, Paul Gortmaker, Alan Stern,
	linux-kernel, kernel-janitors

[-- Attachment #1: Type: text/plain, Size: 606 bytes --]

On Fri, Mar 02, 2012 at 06:22:03AM -0500, Neil Horman wrote:
> This certainly works, but a quick search of call sites shows this isn't the only
> place someone passes a bool to debugfs_create_bool. I think the better solution
> would be to change debugfs_create_bool and its corresponding read/write methods
> to actually work with a bool type, and then clean all the call sites to pass in
> a bool properly, instead of a u32.

There is only one other call site which gets this wrong, and I sent
a fix for that today as well.  But yes, you're probably right that
would be cleaner.

regards,
dan carpenter


[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

end of thread, other threads:[~2012-03-02 12:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-02  6:58 [patch] dma-debug: debugfs_create_bool() takes a u32 pointer Dan Carpenter
2012-03-02 11:22 ` Neil Horman
2012-03-02 12:55   ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).