Skip to content

Commit ab2c742

Browse files
captain5050acmel
authored andcommitted
perf dso: Minor refactor to allow clang's Wthread-safety analysis
The pattern: ``` if (x) { lock(...) } block1; if (x) { unlock(...) } ``` defeats clang's -Wthread-safety analysis where it complains of locks held on one path and not another. Add helper functions for "block1" then restructure as: ``` if (x) { lock(...); block1(); unlock(...); } else { block1(); } ``` Signed-off-by: Ian Rogers <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Athira Rajeev <[email protected]> Cc: Bill Wendling <[email protected]> Cc: Chaitanya S Prakash <[email protected]> Cc: Fei Lang <[email protected]> Cc: Howard Chu <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: James Clark <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Justin Stitt <[email protected]> Cc: Kan Liang <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Nathan Chancellor <[email protected]> Cc: Nick Desaulniers <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Stephen Brennan <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent ba5f102 commit ab2c742

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed

tools/perf/util/dso.c

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,6 +1349,16 @@ struct dso *machine__findnew_kernel(struct machine *machine, const char *name,
13491349
return dso;
13501350
}
13511351

1352+
static void __dso__set_long_name_id(struct dso *dso, const char *name, bool name_allocated)
1353+
{
1354+
if (dso__long_name_allocated(dso))
1355+
free((char *)dso__long_name(dso));
1356+
1357+
RC_CHK_ACCESS(dso)->long_name = name;
1358+
RC_CHK_ACCESS(dso)->long_name_len = strlen(name);
1359+
dso__set_long_name_allocated(dso, name_allocated);
1360+
}
1361+
13521362
static void dso__set_long_name_id(struct dso *dso, const char *name, bool name_allocated)
13531363
{
13541364
struct dsos *dsos = dso__dsos(dso);
@@ -1362,18 +1372,11 @@ static void dso__set_long_name_id(struct dso *dso, const char *name, bool name_a
13621372
* renaming the dso.
13631373
*/
13641374
down_write(&dsos->lock);
1365-
}
1366-
1367-
if (dso__long_name_allocated(dso))
1368-
free((char *)dso__long_name(dso));
1369-
1370-
RC_CHK_ACCESS(dso)->long_name = name;
1371-
RC_CHK_ACCESS(dso)->long_name_len = strlen(name);
1372-
dso__set_long_name_allocated(dso, name_allocated);
1373-
1374-
if (dsos) {
1375+
__dso__set_long_name_id(dso, name, name_allocated);
13751376
dsos->sorted = false;
13761377
up_write(&dsos->lock);
1378+
} else {
1379+
__dso__set_long_name_id(dso, name, name_allocated);
13771380
}
13781381
}
13791382

@@ -1451,6 +1454,16 @@ void dso__set_long_name(struct dso *dso, const char *name, bool name_allocated)
14511454
dso__set_long_name_id(dso, name, name_allocated);
14521455
}
14531456

1457+
static void __dso__set_short_name(struct dso *dso, const char *name, bool name_allocated)
1458+
{
1459+
if (dso__short_name_allocated(dso))
1460+
free((char *)dso__short_name(dso));
1461+
1462+
RC_CHK_ACCESS(dso)->short_name = name;
1463+
RC_CHK_ACCESS(dso)->short_name_len = strlen(name);
1464+
dso__set_short_name_allocated(dso, name_allocated);
1465+
}
1466+
14541467
void dso__set_short_name(struct dso *dso, const char *name, bool name_allocated)
14551468
{
14561469
struct dsos *dsos = dso__dsos(dso);
@@ -1464,17 +1477,11 @@ void dso__set_short_name(struct dso *dso, const char *name, bool name_allocated)
14641477
* renaming the dso.
14651478
*/
14661479
down_write(&dsos->lock);
1467-
}
1468-
if (dso__short_name_allocated(dso))
1469-
free((char *)dso__short_name(dso));
1470-
1471-
RC_CHK_ACCESS(dso)->short_name = name;
1472-
RC_CHK_ACCESS(dso)->short_name_len = strlen(name);
1473-
dso__set_short_name_allocated(dso, name_allocated);
1474-
1475-
if (dsos) {
1480+
__dso__set_short_name(dso, name, name_allocated);
14761481
dsos->sorted = false;
14771482
up_write(&dsos->lock);
1483+
} else {
1484+
__dso__set_short_name(dso, name, name_allocated);
14781485
}
14791486
}
14801487

0 commit comments

Comments
 (0)