Skip to content

Commit c2b5296

Browse files
acmelgregkh
authored andcommitted
perf bench inject-buildid: Handle writen() errors
[ Upstream commit edf7b4a ] The build on fedora:35 and fedora:rawhide with clang is failing with: 49 41.00 fedora:35 : FAIL clang version 13.0.0 (Fedora 13.0.0~rc1-1.fc35) bench/inject-buildid.c:351:6: error: variable 'len' set but not used [-Werror,-Wunused-but-set-variable] u64 len = 0; ^ 1 error generated. make[3]: *** [/git/perf-5.14.0-rc7/tools/build/Makefile.build:139: bench] Error 2 50 41.11 fedora:rawhide : FAIL clang version 13.0.0 (Fedora 13.0.0~rc1-1.fc35) bench/inject-buildid.c:351:6: error: variable 'len' set but not used [-Werror,-Wunused-but-set-variable] u64 len = 0; ^ 1 error generated. make[3]: *** [/git/perf-5.14.0-rc7/tools/build/Makefile.build:139: bench] Error 2 That 'len' variable is not used at all, so just make sure all the synthesize_RECORD() routines return ssize_t to propagate the writen() return, as it may fail, ditch the 'ret' var and bail out if those routines fail. Fixes: 0bf02a0 ("perf bench: Add build-id injection benchmark") Acked-by: Namhyung Kim <namhyung@kernel.org> Link: http://lore.kernel.org/lkml/CAM9d7cgEZNSor+B+7Y2C+QYGme_v5aH0Zn0RLfxoQ+Fy83EHrg@mail.gmail.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 5a20adc commit c2b5296

1 file changed

Lines changed: 30 additions & 22 deletions

File tree

‎tools/perf/bench/inject-buildid.c‎

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ static u64 dso_map_addr(struct bench_dso *dso)
133133
return 0x400000ULL + dso->ino * 8192ULL;
134134
}
135135

136-
static u32 synthesize_attr(struct bench_data *data)
136+
static ssize_t synthesize_attr(struct bench_data *data)
137137
{
138138
union perf_event event;
139139

@@ -151,7 +151,7 @@ static u32 synthesize_attr(struct bench_data *data)
151151
return writen(data->input_pipe[1], &event, event.header.size);
152152
}
153153

154-
static u32 synthesize_fork(struct bench_data *data)
154+
static ssize_t synthesize_fork(struct bench_data *data)
155155
{
156156
union perf_event event;
157157

@@ -169,8 +169,7 @@ static u32 synthesize_fork(struct bench_data *data)
169169
return writen(data->input_pipe[1], &event, event.header.size);
170170
}
171171

172-
static u32 synthesize_mmap(struct bench_data *data, struct bench_dso *dso,
173-
u64 timestamp)
172+
static ssize_t synthesize_mmap(struct bench_data *data, struct bench_dso *dso, u64 timestamp)
174173
{
175174
union perf_event event;
176175
size_t len = offsetof(struct perf_record_mmap2, filename);
@@ -198,23 +197,25 @@ static u32 synthesize_mmap(struct bench_data *data, struct bench_dso *dso,
198197

199198
if (len > sizeof(event.mmap2)) {
200199
/* write mmap2 event first */
201-
writen(data->input_pipe[1], &event, len - bench_id_hdr_size);
200+
if (writen(data->input_pipe[1], &event, len - bench_id_hdr_size) < 0)
201+
return -1;
202202
/* zero-fill sample id header */
203203
memset(id_hdr_ptr, 0, bench_id_hdr_size);
204204
/* put timestamp in the right position */
205205
ts_idx = (bench_id_hdr_size / sizeof(u64)) - 2;
206206
id_hdr_ptr[ts_idx] = timestamp;
207-
writen(data->input_pipe[1], id_hdr_ptr, bench_id_hdr_size);
208-
} else {
209-
ts_idx = (len / sizeof(u64)) - 2;
210-
id_hdr_ptr[ts_idx] = timestamp;
211-
writen(data->input_pipe[1], &event, len);
207+
if (writen(data->input_pipe[1], id_hdr_ptr, bench_id_hdr_size) < 0)
208+
return -1;
209+
210+
return len;
212211
}
213-
return len;
212+
213+
ts_idx = (len / sizeof(u64)) - 2;
214+
id_hdr_ptr[ts_idx] = timestamp;
215+
return writen(data->input_pipe[1], &event, len);
214216
}
215217

216-
static u32 synthesize_sample(struct bench_data *data, struct bench_dso *dso,
217-
u64 timestamp)
218+
static ssize_t synthesize_sample(struct bench_data *data, struct bench_dso *dso, u64 timestamp)
218219
{
219220
union perf_event event;
220221
struct perf_sample sample = {
@@ -233,7 +234,7 @@ static u32 synthesize_sample(struct bench_data *data, struct bench_dso *dso,
233234
return writen(data->input_pipe[1], &event, event.header.size);
234235
}
235236

236-
static u32 synthesize_flush(struct bench_data *data)
237+
static ssize_t synthesize_flush(struct bench_data *data)
237238
{
238239
struct perf_event_header header = {
239240
.size = sizeof(header),
@@ -348,28 +349,35 @@ static int inject_build_id(struct bench_data *data, u64 *max_rss)
348349
int status;
349350
unsigned int i, k;
350351
struct rusage rusage;
351-
u64 len = 0;
352352

353353
/* this makes the child to run */
354354
if (perf_header__write_pipe(data->input_pipe[1]) < 0)
355355
return -1;
356356

357-
len += synthesize_attr(data);
358-
len += synthesize_fork(data);
357+
if (synthesize_attr(data) < 0)
358+
return -1;
359+
360+
if (synthesize_fork(data) < 0)
361+
return -1;
359362

360363
for (i = 0; i < nr_mmaps; i++) {
361364
int idx = rand() % (nr_dsos - 1);
362365
struct bench_dso *dso = &dsos[idx];
363366
u64 timestamp = rand() % 1000000;
364367

365368
pr_debug2(" [%d] injecting: %s\n", i+1, dso->name);
366-
len += synthesize_mmap(data, dso, timestamp);
369+
if (synthesize_mmap(data, dso, timestamp) < 0)
370+
return -1;
367371

368-
for (k = 0; k < nr_samples; k++)
369-
len += synthesize_sample(data, dso, timestamp + k * 1000);
372+
for (k = 0; k < nr_samples; k++) {
373+
if (synthesize_sample(data, dso, timestamp + k * 1000) < 0)
374+
return -1;
375+
}
370376

371-
if ((i + 1) % 10 == 0)
372-
len += synthesize_flush(data);
377+
if ((i + 1) % 10 == 0) {
378+
if (synthesize_flush(data) < 0)
379+
return -1;
380+
}
373381
}
374382

375383
/* tihs makes the child to finish */

0 commit comments

Comments
 (0)