mirror of
https://github.com/nxp-imx/linux-imx.git
synced 2025-07-13 20:59:37 +02:00
perf thread: Fixes to thread__new() related to initializing comm
[ Upstream commit3536c2575e
] Freeing the thread on failure won't work with reference count checking, use thread__delete(). Don't allocate the comm_str, use a stack allocation instead. Fixes:f6005cafeb
("perf thread: Add reference count checking") Signed-off-by: Ian Rogers <irogers@google.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: James Clark <james.clark@arm.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Leo Yan <leo.yan@linux.dev> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: https://lore.kernel.org/r/20240508035301.1554434-5-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
9029a775f0
commit
c5314cfa92
|
@ -39,12 +39,13 @@ int thread__init_maps(struct thread *thread, struct machine *machine)
|
||||||
|
|
||||||
struct thread *thread__new(pid_t pid, pid_t tid)
|
struct thread *thread__new(pid_t pid, pid_t tid)
|
||||||
{
|
{
|
||||||
char *comm_str;
|
|
||||||
struct comm *comm;
|
|
||||||
RC_STRUCT(thread) *_thread = zalloc(sizeof(*_thread));
|
RC_STRUCT(thread) *_thread = zalloc(sizeof(*_thread));
|
||||||
struct thread *thread;
|
struct thread *thread;
|
||||||
|
|
||||||
if (ADD_RC_CHK(thread, _thread) != NULL) {
|
if (ADD_RC_CHK(thread, _thread) != NULL) {
|
||||||
|
struct comm *comm;
|
||||||
|
char comm_str[32];
|
||||||
|
|
||||||
thread__set_pid(thread, pid);
|
thread__set_pid(thread, pid);
|
||||||
thread__set_tid(thread, tid);
|
thread__set_tid(thread, tid);
|
||||||
thread__set_ppid(thread, -1);
|
thread__set_ppid(thread, -1);
|
||||||
|
@ -56,13 +57,8 @@ struct thread *thread__new(pid_t pid, pid_t tid)
|
||||||
init_rwsem(thread__namespaces_lock(thread));
|
init_rwsem(thread__namespaces_lock(thread));
|
||||||
init_rwsem(thread__comm_lock(thread));
|
init_rwsem(thread__comm_lock(thread));
|
||||||
|
|
||||||
comm_str = malloc(32);
|
snprintf(comm_str, sizeof(comm_str), ":%d", tid);
|
||||||
if (!comm_str)
|
|
||||||
goto err_thread;
|
|
||||||
|
|
||||||
snprintf(comm_str, 32, ":%d", tid);
|
|
||||||
comm = comm__new(comm_str, 0, false);
|
comm = comm__new(comm_str, 0, false);
|
||||||
free(comm_str);
|
|
||||||
if (!comm)
|
if (!comm)
|
||||||
goto err_thread;
|
goto err_thread;
|
||||||
|
|
||||||
|
@ -76,7 +72,7 @@ struct thread *thread__new(pid_t pid, pid_t tid)
|
||||||
return thread;
|
return thread;
|
||||||
|
|
||||||
err_thread:
|
err_thread:
|
||||||
free(thread);
|
thread__delete(thread);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user