aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMasami Hiramatsu <mhiramat@kernel.org>2016-05-10 01:47:35 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2016-05-10 10:57:22 -0400
commit642aadaa320bf9466fd12e3c0903977410bcb731 (patch)
treed710d31b976b6e7e9d786842a593e3b45c0eadb6
parent70a6898fdc11272249622f77b034f47f1e9adb35 (diff)
perf header: Make topology checkers to check return value of strbuf
Make topology checkers to check the return value of strbuf APIs so that it can detect errors in it. Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/20160510054735.6158.98650.stgit@devbox Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/util/header.c31
1 files changed, 20 insertions, 11 deletions
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 90680ec9f8b8..c6000d44f98c 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1819,7 +1819,8 @@ static int process_cpu_topology(struct perf_file_section *section,
1819 1819
1820 ph->env.nr_sibling_cores = nr; 1820 ph->env.nr_sibling_cores = nr;
1821 size += sizeof(u32); 1821 size += sizeof(u32);
1822 strbuf_init(&sb, 128); 1822 if (strbuf_init(&sb, 128) < 0)
1823 goto free_cpu;
1823 1824
1824 for (i = 0; i < nr; i++) { 1825 for (i = 0; i < nr; i++) {
1825 str = do_read_string(fd, ph); 1826 str = do_read_string(fd, ph);
@@ -1827,7 +1828,8 @@ static int process_cpu_topology(struct perf_file_section *section,
1827 goto error; 1828 goto error;
1828 1829
1829 /* include a NULL character at the end */ 1830 /* include a NULL character at the end */
1830 strbuf_add(&sb, str, strlen(str) + 1); 1831 if (strbuf_add(&sb, str, strlen(str) + 1) < 0)
1832 goto error;
1831 size += string_size(str); 1833 size += string_size(str);
1832 free(str); 1834 free(str);
1833 } 1835 }
@@ -1849,7 +1851,8 @@ static int process_cpu_topology(struct perf_file_section *section,
1849 goto error; 1851 goto error;
1850 1852
1851 /* include a NULL character at the end */ 1853 /* include a NULL character at the end */
1852 strbuf_add(&sb, str, strlen(str) + 1); 1854 if (strbuf_add(&sb, str, strlen(str) + 1) < 0)
1855 goto error;
1853 size += string_size(str); 1856 size += string_size(str);
1854 free(str); 1857 free(str);
1855 } 1858 }
@@ -1912,13 +1915,14 @@ static int process_numa_topology(struct perf_file_section *section __maybe_unuse
1912 /* nr nodes */ 1915 /* nr nodes */
1913 ret = readn(fd, &nr, sizeof(nr)); 1916 ret = readn(fd, &nr, sizeof(nr));
1914 if (ret != sizeof(nr)) 1917 if (ret != sizeof(nr))
1915 goto error; 1918 return -1;
1916 1919
1917 if (ph->needs_swap) 1920 if (ph->needs_swap)
1918 nr = bswap_32(nr); 1921 nr = bswap_32(nr);
1919 1922
1920 ph->env.nr_numa_nodes = nr; 1923 ph->env.nr_numa_nodes = nr;
1921 strbuf_init(&sb, 256); 1924 if (strbuf_init(&sb, 256) < 0)
1925 return -1;
1922 1926
1923 for (i = 0; i < nr; i++) { 1927 for (i = 0; i < nr; i++) {
1924 /* node number */ 1928 /* node number */
@@ -1940,15 +1944,17 @@ static int process_numa_topology(struct perf_file_section *section __maybe_unuse
1940 mem_free = bswap_64(mem_free); 1944 mem_free = bswap_64(mem_free);
1941 } 1945 }
1942 1946
1943 strbuf_addf(&sb, "%u:%"PRIu64":%"PRIu64":", 1947 if (strbuf_addf(&sb, "%u:%"PRIu64":%"PRIu64":",
1944 node, mem_total, mem_free); 1948 node, mem_total, mem_free) < 0)
1949 goto error;
1945 1950
1946 str = do_read_string(fd, ph); 1951 str = do_read_string(fd, ph);
1947 if (!str) 1952 if (!str)
1948 goto error; 1953 goto error;
1949 1954
1950 /* include a NULL character at the end */ 1955 /* include a NULL character at the end */
1951 strbuf_add(&sb, str, strlen(str) + 1); 1956 if (strbuf_add(&sb, str, strlen(str) + 1) < 0)
1957 goto error;
1952 free(str); 1958 free(str);
1953 } 1959 }
1954 ph->env.numa_nodes = strbuf_detach(&sb, NULL); 1960 ph->env.numa_nodes = strbuf_detach(&sb, NULL);
@@ -1982,7 +1988,8 @@ static int process_pmu_mappings(struct perf_file_section *section __maybe_unused
1982 } 1988 }
1983 1989
1984 ph->env.nr_pmu_mappings = pmu_num; 1990 ph->env.nr_pmu_mappings = pmu_num;
1985 strbuf_init(&sb, 128); 1991 if (strbuf_init(&sb, 128) < 0)
1992 return -1;
1986 1993
1987 while (pmu_num) { 1994 while (pmu_num) {
1988 if (readn(fd, &type, sizeof(type)) != sizeof(type)) 1995 if (readn(fd, &type, sizeof(type)) != sizeof(type))
@@ -1994,9 +2001,11 @@ static int process_pmu_mappings(struct perf_file_section *section __maybe_unused
1994 if (!name) 2001 if (!name)
1995 goto error; 2002 goto error;
1996 2003
1997 strbuf_addf(&sb, "%u:%s", type, name); 2004 if (strbuf_addf(&sb, "%u:%s", type, name) < 0)
2005 goto error;
1998 /* include a NULL character at the end */ 2006 /* include a NULL character at the end */
1999 strbuf_add(&sb, "", 1); 2007 if (strbuf_add(&sb, "", 1) < 0)
2008 goto error;
2000 2009
2001 if (!strcmp(name, "msr")) 2010 if (!strcmp(name, "msr"))
2002 ph->env.msr_pmu_type = type; 2011 ph->env.msr_pmu_type = type;