All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf jit: memset variable st using the correct size
@ 2016-04-18 23:07 Colin King
  2016-04-19 13:47 ` rnaldo Carvalho de Melo
  2016-04-23 13:04 ` [tip:perf/core] perf jit: memset() variable 'st' " tip-bot for Colin Ian King
  0 siblings, 2 replies; 4+ messages in thread
From: Colin King @ 2016-04-18 23:07 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, rnaldo Carvalho de Melo,
	Alexander Shishkin, Adrian Hunter, Stephane Eranian
  Cc: linux-kernel

From: Colin Ian King <colin.king@canonical.com>

The current code is memsetting the struct stat variable st with
the size of stat (which turns out to be 1 byte) rather than the
size of variable sz.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 tools/perf/util/jitdump.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/jitdump.c b/tools/perf/util/jitdump.c
index 52fcef3..86afe96 100644
--- a/tools/perf/util/jitdump.c
+++ b/tools/perf/util/jitdump.c
@@ -412,7 +412,7 @@ static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr)
 		return -1;
 	}
 	if (stat(filename, &st))
-		memset(&st, 0, sizeof(stat));
+		memset(&st, 0, sizeof(st));
 
 	event->mmap2.header.type = PERF_RECORD_MMAP2;
 	event->mmap2.header.misc = PERF_RECORD_MISC_USER;
@@ -500,7 +500,7 @@ static int jit_repipe_code_move(struct jit_buf_desc *jd, union jr_entry *jr)
 	size++; /* for \0 */
 
 	if (stat(filename, &st))
-		memset(&st, 0, sizeof(stat));
+		memset(&st, 0, sizeof(st));
 
 	size = PERF_ALIGN(size, sizeof(u64));
 
-- 
2.7.4

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

* Re: [PATCH] perf jit: memset variable st using the correct size
  2016-04-18 23:07 [PATCH] perf jit: memset variable st using the correct size Colin King
@ 2016-04-19 13:47 ` rnaldo Carvalho de Melo
  2016-04-19 13:52   ` rnaldo Carvalho de Melo
  2016-04-23 13:04 ` [tip:perf/core] perf jit: memset() variable 'st' " tip-bot for Colin Ian King
  1 sibling, 1 reply; 4+ messages in thread
From: rnaldo Carvalho de Melo @ 2016-04-19 13:47 UTC (permalink / raw)
  To: Colin King
  Cc: Peter Zijlstra, Ingo Molnar, Alexander Shishkin, Adrian Hunter,
	Stephane Eranian, linux-kernel

Em Tue, Apr 19, 2016 at 12:07:18AM +0100, Colin King escreveu:
> From: Colin Ian King <colin.king@canonical.com>
> 
> The current code is memsetting the struct stat variable st with
> the size of stat (which turns out to be 1 byte) rather than the
> size of variable sz.

Thanks, applied.

- Arnaldo
 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  tools/perf/util/jitdump.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/perf/util/jitdump.c b/tools/perf/util/jitdump.c
> index 52fcef3..86afe96 100644
> --- a/tools/perf/util/jitdump.c
> +++ b/tools/perf/util/jitdump.c
> @@ -412,7 +412,7 @@ static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr)
>  		return -1;
>  	}
>  	if (stat(filename, &st))
> -		memset(&st, 0, sizeof(stat));
> +		memset(&st, 0, sizeof(st));
>  
>  	event->mmap2.header.type = PERF_RECORD_MMAP2;
>  	event->mmap2.header.misc = PERF_RECORD_MISC_USER;
> @@ -500,7 +500,7 @@ static int jit_repipe_code_move(struct jit_buf_desc *jd, union jr_entry *jr)
>  	size++; /* for \0 */
>  
>  	if (stat(filename, &st))
> -		memset(&st, 0, sizeof(stat));
> +		memset(&st, 0, sizeof(st));
>  
>  	size = PERF_ALIGN(size, sizeof(u64));
>  
> -- 
> 2.7.4

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

* Re: [PATCH] perf jit: memset variable st using the correct size
  2016-04-19 13:47 ` rnaldo Carvalho de Melo
@ 2016-04-19 13:52   ` rnaldo Carvalho de Melo
  0 siblings, 0 replies; 4+ messages in thread
From: rnaldo Carvalho de Melo @ 2016-04-19 13:52 UTC (permalink / raw)
  To: Colin King
  Cc: Peter Zijlstra, Ingo Molnar, Alexander Shishkin, Adrian Hunter,
	Stephane Eranian, linux-kernel

Em Tue, Apr 19, 2016 at 10:47:41AM -0300, rnaldo Carvalho de Melo escreveu:
> Em Tue, Apr 19, 2016 at 12:07:18AM +0100, Colin King escreveu:
> > From: Colin Ian King <colin.king@canonical.com>
> > 
> > The current code is memsetting the struct stat variable st with
> > the size of stat (which turns out to be 1 byte) rather than the
> > size of variable sz.
> 
> Thanks, applied.

BTW, its a obvious bug, but I'll add this to the changeset log to
enlighten others ;-)

  [acme@jouet c]$ cc -pedantic sizeof_function.c -o sizeof_function
  sizeof_function.c: In function ‘main’:
  sizeof_function.c:8:46: warning: invalid application of ‘sizeof’ to a function type [-Wpointer-arith]
    printf("sizeof(stat)=%zd, stat=%p\n", sizeof(stat), stat);
                                              ^
  [acme@jouet c]$ ./sizeof_function 
  sizeof(stat)=1, stat=0x40063

As my expectation was for this to return sizeof(void *) :-\

- Arnaldo
 
> - Arnaldo
>  
> > Signed-off-by: Colin Ian King <colin.king@canonical.com>
> > ---
> >  tools/perf/util/jitdump.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/tools/perf/util/jitdump.c b/tools/perf/util/jitdump.c
> > index 52fcef3..86afe96 100644
> > --- a/tools/perf/util/jitdump.c
> > +++ b/tools/perf/util/jitdump.c
> > @@ -412,7 +412,7 @@ static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr)
> >  		return -1;
> >  	}
> >  	if (stat(filename, &st))
> > -		memset(&st, 0, sizeof(stat));
> > +		memset(&st, 0, sizeof(st));
> >  
> >  	event->mmap2.header.type = PERF_RECORD_MMAP2;
> >  	event->mmap2.header.misc = PERF_RECORD_MISC_USER;
> > @@ -500,7 +500,7 @@ static int jit_repipe_code_move(struct jit_buf_desc *jd, union jr_entry *jr)
> >  	size++; /* for \0 */
> >  
> >  	if (stat(filename, &st))
> > -		memset(&st, 0, sizeof(stat));
> > +		memset(&st, 0, sizeof(st));
> >  
> >  	size = PERF_ALIGN(size, sizeof(u64));
> >  
> > -- 
> > 2.7.4

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

* [tip:perf/core] perf jit: memset() variable 'st' using the correct size
  2016-04-18 23:07 [PATCH] perf jit: memset variable st using the correct size Colin King
  2016-04-19 13:47 ` rnaldo Carvalho de Melo
@ 2016-04-23 13:04 ` tip-bot for Colin Ian King
  1 sibling, 0 replies; 4+ messages in thread
From: tip-bot for Colin Ian King @ 2016-04-23 13:04 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: peterz, hpa, eranian, adrian.hunter, linux-kernel, acme,
	alexander.shishkin, tglx, colin.king, mingo

Commit-ID:  f56ebf20d0f535f5da7cfcf0000ab3e0af133f81
Gitweb:     http://git.kernel.org/tip/f56ebf20d0f535f5da7cfcf0000ab3e0af133f81
Author:     Colin Ian King <colin.king@canonical.com>
AuthorDate: Tue, 19 Apr 2016 00:07:18 +0100
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 19 Apr 2016 12:37:01 -0300

perf jit: memset() variable 'st' using the correct size

The current code is memsetting the 'struct stat' variable 'st' with the size of
'stat' (which turns out to be 1 byte) rather than the size of variable 'sz'.

Committer notes:

sizeof(function) isn't valid, the result depends on the compiler used, with
gcc, enabling pedantic warnings we get:

  $ cat sizeof_function.c
  #include <sys/types.h>
  #include <sys/stat.h>
  #include <unistd.h>
  #include <stdio.h>

  int main(void)
  {
	  printf("sizeof(stat)=%zd, stat=%p\n", sizeof(stat), stat);
	  return 0;
  }
  $ readelf -sW sizeof_function | grep -w stat
      49: 0000000000400630    16 FUNC    WEAK   HIDDEN    13 stat
  $ cc -pedantic sizeof_function.c   -o sizeof_function
  sizeof_function.c: In function ‘main’:
  sizeof_function.c:8:46: warning: invalid application of ‘sizeof’ to a function type [-Wpointer-arith]
    printf("sizeof(stat)=%zd, stat=%p\n", sizeof(stat), stat);
                                              ^
  $ ./sizeof_function
  sizeof(stat)=1, stat=0x400630
  $

  Standard C, section 6.5.3.4:

  "The sizeof operator shall not be applied to an expression that has function
   type or an incomplete type, to the parenthesized name of such a type,
   or to an expression that designates a bit-field member."

  http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf

Signed-off-by: Colin Ian King <colin.king@canonical.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Fixes: 9b07e27f88b9 ("perf inject: Add jitdump mmap injection support")
Link: http://lkml.kernel.org/r/1461020838-9260-1-git-send-email-colin.king@canonical.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/jitdump.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/jitdump.c b/tools/perf/util/jitdump.c
index 52fcef3..86afe96 100644
--- a/tools/perf/util/jitdump.c
+++ b/tools/perf/util/jitdump.c
@@ -412,7 +412,7 @@ static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr)
 		return -1;
 	}
 	if (stat(filename, &st))
-		memset(&st, 0, sizeof(stat));
+		memset(&st, 0, sizeof(st));
 
 	event->mmap2.header.type = PERF_RECORD_MMAP2;
 	event->mmap2.header.misc = PERF_RECORD_MISC_USER;
@@ -500,7 +500,7 @@ static int jit_repipe_code_move(struct jit_buf_desc *jd, union jr_entry *jr)
 	size++; /* for \0 */
 
 	if (stat(filename, &st))
-		memset(&st, 0, sizeof(stat));
+		memset(&st, 0, sizeof(st));
 
 	size = PERF_ALIGN(size, sizeof(u64));
 

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

end of thread, other threads:[~2016-04-23 13:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-18 23:07 [PATCH] perf jit: memset variable st using the correct size Colin King
2016-04-19 13:47 ` rnaldo Carvalho de Melo
2016-04-19 13:52   ` rnaldo Carvalho de Melo
2016-04-23 13:04 ` [tip:perf/core] perf jit: memset() variable 'st' " tip-bot for Colin Ian King

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.