mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Devendra Naga <devendra.aaru@gmail.com>
Cc: fweisbec@gmail.com, mingo@redhat.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/1] Fix Compilation Warning in kernel/trace/trace.c
Date: Fri, 16 Dec 2011 07:40:59 -0500	[thread overview]
Message-ID: <1324039259.23971.127.camel@gandalf.stny.rr.com> (raw)
In-Reply-To: <1324019724-3422-1-git-send-email-devendra.aaru@gmail.com>

On Fri, 2011-12-16 at 02:15 -0500, Devendra Naga wrote:
> there was a compilation warning saying
> kernel/trace/trace.c:3644:8: warning: ‘page2’ may be used uninitialized in this function

Nacked-by: Steven Rostedt <rostedt@goodmis.org>

And I also nacked this same fix here:

https://lkml.org/lkml/2011/11/28/287


> 
> The page2 pointer is used only when nr_pages = 2.
> 
> Assigned a null value to the page2 to get rid of warning.


Please please please, do not just fix warnings without actually looking
at the code.

1) this is a bug in the compiler, which happens to be fixed in newer
compilers (which does not produce this warning). It just happens that
gcc couldn't tell the simple usage of:

	if (nr_pages == 2)
		page2 = kmap_atomic(pages[1]);

and later:

	if (nr_pages == 2) {
		len = PAGE_SIZE - offset;
		memcpy(&entry->buf, page1 + offset, len);
		memcpy(&entry->buf[len], page2, cnt - len);

and finally:

	if (nr_pages == 2)
		kunmap_atomic(page2);

nr_pages never changes during this code. Gcc probably got confused
because on error exit, it does change (to unmap everything).

2) But your fix is still wrong!

Initializing it to NULL is wrong! Because it would hide a kernel bug if
page2 was really used uninitialized. As passing NULL as the source of
memcpy will panic the kernel.

Again, do not just randomly post fixes to gcc warnings without
understanding the real fix.

Thanks,

-- Steve



> 
> Signed-off-by: Devendra Naga <devendra.aaru@gmail.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 f2bd275..80dfd92 100644
> --- a/kernel/trace/trace.c
> +++ b/kernel/trace/trace.c
> @@ -3641,7 +3641,7 @@ tracing_mark_write(struct file *filp, const char __user *ubuf,
>  	int nr_pages = 1;
>  	ssize_t written;
>  	void *page1;
> -	void *page2;
> +	void *page2 = NULL;
>  	int offset;
>  	int size;
>  	int len;



  reply	other threads:[~2011-12-16 12:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-16  7:15 Devendra Naga
2011-12-16 12:40 ` Steven Rostedt [this message]
     [not found]   ` <CAHdPZaN3KQRqSOMXV7HdJkw_T_J5D3s3pxDXY72V4iT_tR9NBQ@mail.gmail.com>
2011-12-16 15:28     ` Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1324039259.23971.127.camel@gandalf.stny.rr.com \
    --to=rostedt@goodmis.org \
    --cc=devendra.aaru@gmail.com \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®