mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Re: [PATCH 1/1] kernel/trace: gcc warning: uninitialized variable.
       [not found] <CADeC0sNq41kGWw6JbASu6WE-SkTHihf9SnKCTaBTSyas4TJoMg@mail.gmail.com>
@ 2012-05-12  3:08 ` Steven Rostedt
  2012-05-12  3:27   ` Steven Rostedt
  0 siblings, 1 reply; 2+ messages in thread
From: Steven Rostedt @ 2012-05-12  3:08 UTC (permalink / raw)
  To: Raphael Santana carvalho; +Cc: fweisbec, mingo, linux-kernel

On Fri, 2012-05-11 at 23:26 -0300, Raphael Santana carvalho wrote:
> >From 2f1490c5e8e2a393d9376d959e2ff6836757f51a Mon Sep 17 00:00:00 2001
> From: Raphael S.Carvalho <utroz@oakcoders.com>
> Date: Fri, 11 May 2012 22:58:43 -0300
> Subject: [PATCH 1/1] kernel/trace: gcc warning: uninitialized variable.
> 
> I've received a problem in this file when I was compiling my own kernel.
> It's a simple uninitialized variable, so that gcc is warning about it.
> 
> The function is actually working correctly, because it's impossible to use the
> variable(page2) uninitialized because it's only referenced if nr_pages == 2,
> and we will have previously set it in that case.

Correct.

> 
> gcc version 4.5.2 (GCC) - Follows the warning:

It's a bug in gcc. If you use gcc 4.6 or later it does not warn.

As this code may change in the future, I don't want to hide errors that
gcc 4.6 could catch. Thus I'm not going to take this patch.

Don't feel bad, you're probably the 5th person I declined this change
from. At least you noticed that it was just gcc complaining and did not
blindly set the variable to NULL.

-- Steve

> kernel/trace/trace.c:3755:8 warning: 'page2': may be used uninitialized in this function
> 
> Signed-off-by: Raphael S.Carvalho <utroz@oakcoders.com>
> ---
>  kernel/trace/trace.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
> index 2a22255..4ffff83 100644
> --- a/kernel/trace/trace.c
> +++ b/kernel/trace/trace.c
> @@ -3752,7 +3752,7 @@ tracing_mark_write(struct file *filp, const char __user *ubuf,
>      int nr_pages = 1;
>      ssize_t written;
>      void *page1;
> -    void *page2;
> +    void *uninitialized_var(page2);
>      int offset;
>      int size;
>      int len;



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

* Re: [PATCH 1/1] kernel/trace: gcc warning: uninitialized variable.
  2012-05-12  3:08 ` [PATCH 1/1] kernel/trace: gcc warning: uninitialized variable Steven Rostedt
@ 2012-05-12  3:27   ` Steven Rostedt
  0 siblings, 0 replies; 2+ messages in thread
From: Steven Rostedt @ 2012-05-12  3:27 UTC (permalink / raw)
  To: Raphael Santana carvalho; +Cc: fweisbec, mingo, linux-kernel

On Fri, 2012-05-11 at 23:08 -0400, Steven Rostedt wrote:
> On Fri, 2012-05-11 at 23:26 -0300, Raphael Santana carvalho wrote:
> > >From 2f1490c5e8e2a393d9376d959e2ff6836757f51a Mon Sep 17 00:00:00 2001
> > From: Raphael S.Carvalho <utroz@oakcoders.com>
> > Date: Fri, 11 May 2012 22:58:43 -0300
> > Subject: [PATCH 1/1] kernel/trace: gcc warning: uninitialized variable.
> > 
> > I've received a problem in this file when I was compiling my own kernel.
> > It's a simple uninitialized variable, so that gcc is warning about it.
> > 
> > The function is actually working correctly, because it's impossible to use the
> > variable(page2) uninitialized because it's only referenced if nr_pages == 2,
> > and we will have previously set it in that case.
> 
> Correct.
> 
> > 
> > gcc version 4.5.2 (GCC) - Follows the warning:
> 
> It's a bug in gcc. If you use gcc 4.6 or later it does not warn.
> 
> As this code may change in the future, I don't want to hide errors that
> gcc 4.6 could catch. Thus I'm not going to take this patch.
> 
> Don't feel bad, you're probably the 5th person I declined this change
> from. At least you noticed that it was just gcc complaining and did not
> blindly set the variable to NULL.


Although, this patch here cleans up the code slightly and should get rid
of the warning.

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 2a22255..d77b481 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -3749,14 +3749,14 @@ tracing_mark_write(struct file *filp, const char __user *ubuf,
 	struct print_entry *entry;
 	unsigned long irq_flags;
 	struct page *pages[2];
+	void *map_page[2];
 	int nr_pages = 1;
 	ssize_t written;
-	void *page1;
-	void *page2;
 	int offset;
 	int size;
 	int len;
 	int ret;
+	int i;
 
 	if (tracing_disabled)
 		return -EINVAL;
@@ -3795,9 +3795,8 @@ tracing_mark_write(struct file *filp, const char __user *ubuf,
 		goto out;
 	}
 
-	page1 = kmap_atomic(pages[0]);
-	if (nr_pages == 2)
-		page2 = kmap_atomic(pages[1]);
+	for (i = 0; i < nr_pages; i++)
+		map_page[i] = kmap_atomic(pages[i]);
 
 	local_save_flags(irq_flags);
 	size = sizeof(*entry) + cnt + 2; /* possible \n added */
@@ -3815,10 +3814,10 @@ tracing_mark_write(struct file *filp, const char __user *ubuf,
 
 	if (nr_pages == 2) {
 		len = PAGE_SIZE - offset;
-		memcpy(&entry->buf, page1 + offset, len);
-		memcpy(&entry->buf[len], page2, cnt - len);
+		memcpy(&entry->buf, map_page[0] + offset, len);
+		memcpy(&entry->buf[len], map_page[1], cnt - len);
 	} else
-		memcpy(&entry->buf, page1 + offset, cnt);
+		memcpy(&entry->buf, map_page[0] + offset, cnt);
 
 	if (entry->buf[cnt - 1] != '\n') {
 		entry->buf[cnt] = '\n';
@@ -3833,11 +3832,10 @@ tracing_mark_write(struct file *filp, const char __user *ubuf,
 	*fpos += written;
 
  out_unlock:
-	if (nr_pages == 2)
-		kunmap_atomic(page2);
-	kunmap_atomic(page1);
-	while (nr_pages > 0)
-		put_page(pages[--nr_pages]);
+	for (i = 0; i < nr_pages; i++){
+		kunmap_atomic(map_page[i]);
+		put_page(pages[i]);
+	}
  out:
 	return written;
 }



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

end of thread, other threads:[~2012-05-12  3:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CADeC0sNq41kGWw6JbASu6WE-SkTHihf9SnKCTaBTSyas4TJoMg@mail.gmail.com>
2012-05-12  3:08 ` [PATCH 1/1] kernel/trace: gcc warning: uninitialized variable Steven Rostedt
2012-05-12  3:27   ` Steven Rostedt

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

all inboxes | Powered by JetHome®