Skip to content

Commit 7a48b58

Browse files
ahunter6namhyung
authored andcommitted
perf dlfilter: Fix use of addr_location__exit() in dlfilter__object_code()
Stop calling addr_location__exit() when addr_location__init() was not called. Fixes: 0dd5041 ("perf addr_location: Add init/exit/copy functions") Cc: stable@vger.kernel.org Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Acked-by: Namhyung Kim <namhyung@kernel.org> Link: https://lore.kernel.org/r/20230928071605.17624-1-adrian.hunter@intel.com Signed-off-by: Namhyung Kim <namhyung@kernel.org>
1 parent 48a3adc commit 7a48b58

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

tools/perf/util/dlfilter.c

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -282,13 +282,21 @@ static struct perf_event_attr *dlfilter__attr(void *ctx)
282282
return &d->evsel->core.attr;
283283
}
284284

285+
static __s32 code_read(__u64 ip, struct map *map, struct machine *machine, void *buf, __u32 len)
286+
{
287+
u64 offset = map__map_ip(map, ip);
288+
289+
if (ip + len >= map__end(map))
290+
len = map__end(map) - ip;
291+
292+
return dso__data_read_offset(map__dso(map), machine, offset, buf, len);
293+
}
294+
285295
static __s32 dlfilter__object_code(void *ctx, __u64 ip, void *buf, __u32 len)
286296
{
287297
struct dlfilter *d = (struct dlfilter *)ctx;
288298
struct addr_location *al;
289299
struct addr_location a;
290-
struct map *map;
291-
u64 offset;
292300
__s32 ret;
293301

294302
if (!d->ctx_valid)
@@ -298,27 +306,17 @@ static __s32 dlfilter__object_code(void *ctx, __u64 ip, void *buf, __u32 len)
298306
if (!al)
299307
return -1;
300308

301-
map = al->map;
302-
303-
if (map && ip >= map__start(map) && ip < map__end(map) &&
309+
if (al->map && ip >= map__start(al->map) && ip < map__end(al->map) &&
304310
machine__kernel_ip(d->machine, ip) == machine__kernel_ip(d->machine, d->sample->ip))
305-
goto have_map;
311+
return code_read(ip, al->map, d->machine, buf, len);
306312

307313
addr_location__init(&a);
314+
308315
thread__find_map_fb(al->thread, d->sample->cpumode, ip, &a);
309-
if (!a.map) {
310-
ret = -1;
311-
goto out;
312-
}
316+
ret = a.map ? code_read(ip, a.map, d->machine, buf, len) : -1;
313317

314-
map = a.map;
315-
have_map:
316-
offset = map__map_ip(map, ip);
317-
if (ip + len >= map__end(map))
318-
len = map__end(map) - ip;
319-
ret = dso__data_read_offset(map__dso(map), d->machine, offset, buf, len);
320-
out:
321318
addr_location__exit(&a);
319+
322320
return ret;
323321
}
324322

0 commit comments

Comments
 (0)