Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1382651

[PATCH 10/14] perf jit: memset() variable 'st' using the correct size

Path csiph.com!news.freedyn.net!newsfeed.datemas.de!weretis.net!feeder4.news.weretis.net!storethat.news.telefonica.de!telefonica.de!news.panservice.it!bofh.it!news.nic.it!robomod
From Arnaldo Carvalho de Melo <acme@kernel.org>
Newsgroups linux.kernel
Subject [PATCH 10/14] perf jit: memset() variable 'st' using the correct size
Date Tue, 19 Apr 2016 18:00:05 +0200
Message-ID <rpGeh-KT-59@gated-at.bofh.it> (permalink)
References <rpGee-KT-7@gated-at.bofh.it>
X-Original-To Ingo Molnar <mingo@kernel.org>
X-Mailer git-send-email 2.5.5
MIME-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 8bit
X-Srs-Rewrite SMTP reverse-path rewritten from <acme@infradead.org> by merlin.infradead.org. See http://www.infradead.org/rpr.html
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 77
Organization linux.* mail to news gateway
X-Original-Cc linux-kernel@vger.kernel.org, Colin Ian King <colin.king@canonical.com>, Adrian Hunter <adrian.hunter@intel.com>, Alexander Shishkin <alexander.shishkin@linux.intel.com>, Peter Zijlstra <peterz@infradead.org>, Stephane Eranian <eranian@google.com>, Arnaldo Carvalho de Melo <acme@redhat.com>
X-Original-Date Tue, 19 Apr 2016 12:50:37 -0300
X-Original-Message-ID <1461081041-10580-11-git-send-email-acme@kernel.org>
X-Original-References <1461081041-10580-1-git-send-email-acme@kernel.org>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1382651

Show key headers only | View raw


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'.

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 52fcef3074fe..86afe9618bb0 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.5.5

Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

[GIT PULL 00/14] perf/core improvements and fixes Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-19 18:00 +0200
  [PATCH 08/14] perf top: Use callchain_param.enabled instead of symbol_conf.use_callchain Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-19 18:00 +0200
  [PATCH 09/14] perf script: Fix postgresql ubuntu install instructions Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-19 18:00 +0200
  [PATCH 10/14] perf jit: memset() variable 'st' using the correct size Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-19 18:00 +0200
  [PATCH 05/14] perf report: Use callchain_param.enabled instead of tool specific knob Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-19 18:00 +0200
  Re: [GIT PULL 00/14] perf/core improvements and fixes Ingo Molnar <mingo@kernel.org> - 2016-04-19 21:10 +0200

csiph-web