Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Bill Wendling <morbo@google.com>
Cc: Chaitanya S Prakash <chaitanyas.prakash@arm.com>
Cc: Fei Lang <langfei@huawei.com>
Cc: Howard Chu <howardchu95@gmail.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Justin Stitt <justinstitt@google.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Nick Desaulniers <nick.desaulniers+lkml@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephen Brennan <stephen.s.brennan@oracle.com>
Link: https://lore.kernel.org/r/20250519224645.1810891-1-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
ab2c742d ba5f102e

+26 -19
+26 -19
tools/perf/util/dso.c
··· 1349 1349 return dso; 1350 1350 } 1351 1351 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 + 1352 1362 static void dso__set_long_name_id(struct dso *dso, const char *name, bool name_allocated) 1353 1363 { 1354 1364 struct dsos *dsos = dso__dsos(dso); ··· 1372 1362 * renaming the dso. 1373 1363 */ 1374 1364 down_write(&dsos->lock); 1375 - } 1376 - 1377 - if (dso__long_name_allocated(dso)) 1378 - free((char *)dso__long_name(dso)); 1379 - 1380 - RC_CHK_ACCESS(dso)->long_name = name; 1381 - RC_CHK_ACCESS(dso)->long_name_len = strlen(name); 1382 - dso__set_long_name_allocated(dso, name_allocated); 1383 - 1384 - if (dsos) { 1365 + __dso__set_long_name_id(dso, name, name_allocated); 1385 1366 dsos->sorted = false; 1386 1367 up_write(&dsos->lock); 1368 + } else { 1369 + __dso__set_long_name_id(dso, name, name_allocated); 1387 1370 } 1388 1371 } 1389 1372 ··· 1454 1451 dso__set_long_name_id(dso, name, name_allocated); 1455 1452 } 1456 1453 1454 + static void __dso__set_short_name(struct dso *dso, const char *name, bool name_allocated) 1455 + { 1456 + if (dso__short_name_allocated(dso)) 1457 + free((char *)dso__short_name(dso)); 1458 + 1459 + RC_CHK_ACCESS(dso)->short_name = name; 1460 + RC_CHK_ACCESS(dso)->short_name_len = strlen(name); 1461 + dso__set_short_name_allocated(dso, name_allocated); 1462 + } 1463 + 1457 1464 void dso__set_short_name(struct dso *dso, const char *name, bool name_allocated) 1458 1465 { 1459 1466 struct dsos *dsos = dso__dsos(dso); ··· 1477 1464 * renaming the dso. 1478 1465 */ 1479 1466 down_write(&dsos->lock); 1480 - } 1481 - if (dso__short_name_allocated(dso)) 1482 - free((char *)dso__short_name(dso)); 1483 - 1484 - RC_CHK_ACCESS(dso)->short_name = name; 1485 - RC_CHK_ACCESS(dso)->short_name_len = strlen(name); 1486 - dso__set_short_name_allocated(dso, name_allocated); 1487 - 1488 - if (dsos) { 1467 + __dso__set_short_name(dso, name, name_allocated); 1489 1468 dsos->sorted = false; 1490 1469 up_write(&dsos->lock); 1470 + } else { 1471 + __dso__set_short_name(dso, name, name_allocated); 1491 1472 } 1492 1473 } 1493 1474