From patchwork Sun Jan 5 12:47:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 13926510 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 61BDC1369BB; Sun, 5 Jan 2025 12:47:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736081271; cv=none; b=c4nJSydfNekk0Z+XI9W0HcjXcD/GD/hkR0QRBHxKKDaGCydMMpw8iE1gMS64Ot+L8lA09Krq86nOC+DM9cLXX27az9tIbhyTa5BwU06/et+4NPlZ9A6djHFiLuowNv4gVSImy2Cbjj7c/CU1evM9QvEMIGVguMs6IDuzY0KDlXI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736081271; c=relaxed/simple; bh=SUhZ7GEHZtJZaDdirrowKcn0d6YjA73MGwSKIo7qoU4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Gt7DcaNYlm6WwcQey080r8DNYW8WCtGlvSYzrm4DtwoqPuli4Ajn/g6dMl4YpHrdgkaX7UFhYP5nnIm+cycAEz7FMOiaLvZ1iKHcyI4dt9VjSI6nQX8l54d/FNerPqn8iiX/xqSYfBvyU3dyFKUKiXlvke1e0jY82zdGatF47P0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ijc/UoKP; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Ijc/UoKP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A360BC4CED0; Sun, 5 Jan 2025 12:47:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736081270; bh=SUhZ7GEHZtJZaDdirrowKcn0d6YjA73MGwSKIo7qoU4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ijc/UoKPIQd6vzvLxb1a5qXjwaNqvV/JLAsZ/svhfgISqlSxVLkfD39CH4RfS9T2K IHmX5/tUhWC49hzPzPvE18lr0UO+p1LwEcXnZFnlfdIa2KCCSejEpimv2puKXoNURt BDR6n7P0D0rcIYT7JLAXguargpVDsR2YFCcjoQh9M9LJTB2YWm/hDTcweJylRYi52P LRSLMsolO8gARTogF9+dzOhwoM8WFqEC9nJv6Y45hG53+i95be1TmFUTmrAsu266rS VPvou5ie+C64xpWen9bUFjUgZ8fiqSgLexAxtTSWAa93I2ubGvI3igZLu0JSBwbOTD WjBsymFCg+R3Q== From: "Masami Hiramatsu (Google)" To: Steven Rostedt , Peter Zijlstra Cc: Anil S Keshavamurthy , Masami Hiramatsu , "David S . Miller" , Mathieu Desnoyers , Oleg Nesterov , Tzvetomir Stoyanov , Naveen N Rao , Josh Poimboeuf , Jason Baron , Ard Biesheuvel , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Subject: [PATCH v2 1/6] tracing/kprobes: Fix to free objects when failed to copy a symbol Date: Sun, 5 Jan 2025 21:47:45 +0900 Message-ID: <173608126490.1253657.340741438044767488.stgit@devnote2> X-Mailer: git-send-email 2.43.0 In-Reply-To: <173608125422.1253657.3732758016133408588.stgit@devnote2> References: <173608125422.1253657.3732758016133408588.stgit@devnote2> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Masami Hiramatsu (Google) In __trace_kprobe_create(), if something fails it must goto error block to free objects. But when strdup() a symbol, it returns without that. Fix it to goto the error block to free objects correctly. Fixes: 6212dd29683e ("tracing/kprobes: Use dyn_event framework for kprobe events") Signed-off-by: Masami Hiramatsu (Google) --- kernel/trace/trace_kprobe.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c index bae26eb14449..4c3e316454a0 100644 --- a/kernel/trace/trace_kprobe.c +++ b/kernel/trace/trace_kprobe.c @@ -935,8 +935,10 @@ static int __trace_kprobe_create(int argc, const char *argv[]) } /* a symbol specified */ symbol = kstrdup(argv[1], GFP_KERNEL); - if (!symbol) - return -ENOMEM; + if (!symbol) { + ret = -ENOMEM; + goto error; + } tmp = strchr(symbol, '%'); if (tmp) { From patchwork Sun Jan 5 12:47:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 13926511 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7BEC64C6D; Sun, 5 Jan 2025 12:48:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736081282; cv=none; b=D40wmJhntaGZxYJ0/LQh5sJGEN693/3JMKXEpQcVoCL08nvgM+ld32gV8YtT76heZt9fVycot11aiaqi7WgZKaUDR7uO11kuFGp/qkCEQVnh0O1H+tKaTYozjlHBufvv5D0ZDghCdpz9OdIZJZ5c9cHn+E+IAlOWg0ZFMvuYy8E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736081282; c=relaxed/simple; bh=Ygf+iCbx7dZy/D639P/x2vHGiaFTI7wGxpffxyQB5zQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rnAj54/CjysYOLMQUj8feuK473+0DT7BwZ5lqNKCw+RrQBQXG4mClkaYhMLAFlYSlQaSRJmHCaxUSOK/2HlDZmK8RDpZ0VC1/NQVFv9QB9jrnPSHR6Q1rEsb5CX7Gj4DG+raxyJm6a9w/Du0f2QmJ749GGUrB3z5F/QSiiSuQ40= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sOEYRM+i; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="sOEYRM+i" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C8289C4CED0; Sun, 5 Jan 2025 12:47:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736081282; bh=Ygf+iCbx7dZy/D639P/x2vHGiaFTI7wGxpffxyQB5zQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sOEYRM+iM9kN2pRmgjurk3VFjj8I3iRxuq90TT3fWbIYDQ/zDOQZtsZ4BL5ChQAk8 CtNE0QxGRN31W77kngnsgDKWK09rxJre8EbZbsHZ2Q2V/VAzD+wddAGzPBxUnmmQZ6 4ZEoklm8+Png2Q/hN1qmkGkqBfutsyTFqIj0pMqsb9IdCsWStEyIRTFMkwa0PyB2Zp /1LDBt0WFgKOEXA/5wtgKhkiT23wFNohEWcYAgaG2Yb6mzZsJ5i6EGJnTASFrPaMCp b/7LFmb2YnNbVHOYMqbhuUBiivU2DqkV69zOPUKzL2rQaU03jMHEU2uLg56QxE0j/F VMw1gkSG/5K4Q== From: "Masami Hiramatsu (Google)" To: Steven Rostedt , Peter Zijlstra Cc: Anil S Keshavamurthy , Masami Hiramatsu , "David S . Miller" , Mathieu Desnoyers , Oleg Nesterov , Tzvetomir Stoyanov , Naveen N Rao , Josh Poimboeuf , Jason Baron , Ard Biesheuvel , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Subject: [PATCH v2 2/6] Provide __free(argv) for argv_split() users Date: Sun, 5 Jan 2025 21:47:56 +0900 Message-ID: <173608127627.1253657.12054758575695672674.stgit@devnote2> X-Mailer: git-send-email 2.43.0 In-Reply-To: <173608125422.1253657.3732758016133408588.stgit@devnote2> References: <173608125422.1253657.3732758016133408588.stgit@devnote2> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Masami Hiramatsu (Google) Provide __free(argv) macro for argv_split() users so that they can avoid gotos. Signed-off-by: Masami Hiramatsu (Google) --- Changes in v2: - Fix to call argv_free() only if the argument is !IS_ERR_OR_NULL(). - Add including cleanup.h. --- include/linux/string.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/linux/string.h b/include/linux/string.h index 493ac4862c77..07f2a90d5d9c 100644 --- a/include/linux/string.h +++ b/include/linux/string.h @@ -4,6 +4,7 @@ #include #include +#include /* for DEFINE_FREE() */ #include /* for inline */ #include /* for size_t */ #include /* for NULL */ @@ -312,6 +313,8 @@ extern void *kmemdup_array(const void *src, size_t count, size_t element_size, g extern char **argv_split(gfp_t gfp, const char *str, int *argcp); extern void argv_free(char **argv); +DEFINE_FREE(argv, char **, if (!IS_ERR_OR_NULL(_T)) argv_free(_T)) + /* lib/cmdline.c */ extern int get_option(char **str, int *pint); extern char *get_options(const char *str, int nints, int *ints); From patchwork Sun Jan 5 12:48:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 13926512 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 80AF736C; Sun, 5 Jan 2025 12:48:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736081293; cv=none; b=cIzHhYx0iPclIz7Fk2F9xEPO9qmpYqjaoXdQYbKbuhztzG6VbAJVrmVjy5Mhh7mg4XzUYuBUdRPWc/PQODS0pDay9tg++lygTdLtheIZf8soTK1jpM1332q49kPa5J/JPagbpe6JKaCdL6hkGva6TGpNWiadchtg9zuQOn8YKFA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736081293; c=relaxed/simple; bh=+pxLLLe29dzlgSbN6WDsHwCIQvOgeEupwWyEX6Or1L4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Wa3C/2yW+JAKambfCSRyrLzukfKY+imVrJxjO6SAoz2evgY5cDnQWaL0glIyi7aXhnYFHbUoMeTVyH0WBVdXhVlN1yS+NXahWm8610wIeaXrKJbYNRca96jhDJbnJ3lfgLcNirWB3smOuuHZlbQXGiBftoP/3Gq4dzPTRKroVPo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uKnVP1rW; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="uKnVP1rW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D64A4C4CED0; Sun, 5 Jan 2025 12:48:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736081293; bh=+pxLLLe29dzlgSbN6WDsHwCIQvOgeEupwWyEX6Or1L4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uKnVP1rWgV8GRmTLHV+ayljgggD7L77b+U5IoOTlyZ1PiGmOAOiXW4KyHGZr/EKtt WfVwXhmKCLuigI5PwHvwRLYoCZB68FhHf+2XrWoug3lWTaU7Nb5M2o6Rcr19K/WZH6 9G2F+7dnnindL7voIt3MJSgfyFNJb6xFBtXs9ZEsV9s4z0KIZ5glbMHbNQhqxDEdWt Gundn53DLvJAsZX/ZYHQOcUytUk9/bvjIFqd8lJNJqgJNrJ9CVwIp67PcZA1+z6GMM YHk3TV5NGvUSli32DhfYZNGcDZkt0MWfNQq/DXQIB34jSkoaI2Pep4KfDACAFxU8Lv wna+QB84jT0Bw== From: "Masami Hiramatsu (Google)" To: Steven Rostedt , Peter Zijlstra Cc: Anil S Keshavamurthy , Masami Hiramatsu , "David S . Miller" , Mathieu Desnoyers , Oleg Nesterov , Tzvetomir Stoyanov , Naveen N Rao , Josh Poimboeuf , Jason Baron , Ard Biesheuvel , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Subject: [PATCH v2 3/6] tracing: Use __free() for argv in dynevent Date: Sun, 5 Jan 2025 21:48:07 +0900 Message-ID: <173608128743.1253657.14202571481200245375.stgit@devnote2> X-Mailer: git-send-email 2.43.0 In-Reply-To: <173608125422.1253657.3732758016133408588.stgit@devnote2> References: <173608125422.1253657.3732758016133408588.stgit@devnote2> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Masami Hiramatsu (Google) Use __free() for the args allocated by argv_split() in dynevent. Signed-off-by: Masami Hiramatsu (Google) --- Changes in v2: - Rebased on probes/for-next, which reverts previous dynevent guard patch. --- kernel/trace/trace_dynevent.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/kernel/trace/trace_dynevent.c b/kernel/trace/trace_dynevent.c index 4376887e0d8a..630d9695b2df 100644 --- a/kernel/trace/trace_dynevent.c +++ b/kernel/trace/trace_dynevent.c @@ -74,24 +74,20 @@ int dyn_event_release(const char *raw_command, struct dyn_event_operations *type struct dyn_event *pos, *n; char *system = NULL, *event, *p; int argc, ret = -ENOENT; - char **argv; + char **argv __free(argv) = NULL; argv = argv_split(GFP_KERNEL, raw_command, &argc); if (!argv) return -ENOMEM; if (argv[0][0] == '-') { - if (argv[0][1] != ':') { - ret = -EINVAL; - goto out; - } + if (argv[0][1] != ':') + return -EINVAL; event = &argv[0][2]; } else { event = strchr(argv[0], ':'); - if (!event) { - ret = -EINVAL; - goto out; - } + if (!event) + return -EINVAL; event++; } @@ -101,10 +97,8 @@ int dyn_event_release(const char *raw_command, struct dyn_event_operations *type event = p + 1; *p = '\0'; } - if (!system && event[0] == '\0') { - ret = -EINVAL; - goto out; - } + if (!system && event[0] == '\0') + return -EINVAL; mutex_lock(&event_mutex); for_each_dyn_event_safe(pos, n) { @@ -120,8 +114,7 @@ int dyn_event_release(const char *raw_command, struct dyn_event_operations *type } tracing_reset_all_online_cpus(); mutex_unlock(&event_mutex); -out: - argv_free(argv); + return ret; } From patchwork Sun Jan 5 12:48:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 13926513 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D52D7148FE4; Sun, 5 Jan 2025 12:48:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736081304; cv=none; b=f/o4mwTUOdqCp/IYc8WbSmp7SGG0D2fUv2LS6zSQiVUIjhCmeaIUo4DfQWY1Ptq43zRK6XbfVZMeyFWA9JWbgY04kkIzLeoCfnLcA5+2VV/YQXY7FvTU9djtBbs/GPiO8plnyVdfsD1aoA7QhAbl4yBRf9O4UdN4PBsc674yGYk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736081304; c=relaxed/simple; bh=BcADqpQVIfcOvYJDWh5fJTXzfcEJmhMIEhtchptg8lU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YngN2iKeB+Q0KU9mVk7jKe8wZ5fIM/dtkPeZ6Y2jR9ZUycg4KZ2whWSE+EQAoDBlkbOv/oJvgqkm7yjajx6aIU0oAREy0M+r0hGyl6qZpzFqH5bbxPoWd38LXaa+nTrekn0Mo53NAjibEh7o9/hfMVA71ZwU1jAEf7SeskydSZs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qQD+MkE6; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="qQD+MkE6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3C1F8C4CED0; Sun, 5 Jan 2025 12:48:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736081304; bh=BcADqpQVIfcOvYJDWh5fJTXzfcEJmhMIEhtchptg8lU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qQD+MkE6y6yyCqxqhybV4KV0XkkKg275OQGPGigmXDZi1duxHsPzZyYL7ft3XpI6N 3qOsLi0Az+GzBiPvruZ7TdPBQCh8qGWGGEWg+xClOZ+a4oWuvLAe1CB7DiBze6lbET aV2NAdolWEGapwjOq7u/+Ow4/P8FAA3G1rpjX2oZXsIuebfgUMhZXHST38pwO+n1ok bCnq+lL/e0LlSRkmwHWQEBh/RJHCsICsIeqEWlfsi4MKp9b6s5dBFw5NhI+pf55RFn CzZHgCI5S5wonFfIr6P5FCCUS1i0+PL/rTsgv1EuRchF+Qnq0wcOqYdGI6m5vEeU5h bcB+39bCElAvg== From: "Masami Hiramatsu (Google)" To: Steven Rostedt , Peter Zijlstra Cc: Anil S Keshavamurthy , Masami Hiramatsu , "David S . Miller" , Mathieu Desnoyers , Oleg Nesterov , Tzvetomir Stoyanov , Naveen N Rao , Josh Poimboeuf , Jason Baron , Ard Biesheuvel , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Subject: [PATCH v2 4/6] tracing: Use __free() in trace_probe for cleanup Date: Sun, 5 Jan 2025 21:48:18 +0900 Message-ID: <173608129849.1253657.9624732633284234291.stgit@devnote2> X-Mailer: git-send-email 2.43.0 In-Reply-To: <173608125422.1253657.3732758016133408588.stgit@devnote2> References: <173608125422.1253657.3732758016133408588.stgit@devnote2> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Masami Hiramatsu (Google) Use __free() in trace_probe to cleanup some gotos. Signed-off-by: Masami Hiramatsu (Google) --- kernel/trace/trace_probe.c | 52 +++++++++++++++----------------------------- 1 file changed, 18 insertions(+), 34 deletions(-) diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c index 16a5e368e7b7..bf6a7b81ae95 100644 --- a/kernel/trace/trace_probe.c +++ b/kernel/trace/trace_probe.c @@ -1409,7 +1409,7 @@ static int traceprobe_parse_probe_arg_body(const char *argv, ssize_t *size, struct traceprobe_parse_context *ctx) { struct fetch_insn *code, *tmp = NULL; - char *type, *arg; + char *type, *arg __free(kfree) = NULL; int ret, len; len = strlen(argv); @@ -1426,22 +1426,16 @@ static int traceprobe_parse_probe_arg_body(const char *argv, ssize_t *size, return -ENOMEM; parg->comm = kstrdup(arg, GFP_KERNEL); - if (!parg->comm) { - ret = -ENOMEM; - goto out; - } + if (!parg->comm) + return -ENOMEM; type = parse_probe_arg_type(arg, parg, ctx); - if (IS_ERR(type)) { - ret = PTR_ERR(type); - goto out; - } + if (IS_ERR(type)) + return PTR_ERR(type); code = tmp = kcalloc(FETCH_INSN_MAX, sizeof(*code), GFP_KERNEL); - if (!code) { - ret = -ENOMEM; - goto out; - } + if (!code) + return -ENOMEM; code[FETCH_INSN_MAX - 1].op = FETCH_OP_END; ctx->last_type = NULL; @@ -1497,8 +1491,6 @@ static int traceprobe_parse_probe_arg_body(const char *argv, ssize_t *size, kfree(code->data); } kfree(tmp); -out: - kfree(arg); return ret; } @@ -1668,7 +1660,7 @@ const char **traceprobe_expand_meta_args(int argc, const char *argv[], { const struct btf_param *params = NULL; int i, j, n, used, ret, args_idx = -1; - const char **new_argv = NULL; + const char **new_argv __free(kfree) = NULL; ret = argv_has_var_arg(argc, argv, &args_idx, ctx); if (ret < 0) @@ -1707,7 +1699,7 @@ const char **traceprobe_expand_meta_args(int argc, const char *argv[], ret = sprint_nth_btf_arg(n, "", buf + used, bufsize - used, ctx); if (ret < 0) - goto error; + return ERR_PTR(ret); new_argv[j++] = buf + used; used += ret + 1; @@ -1721,25 +1713,20 @@ const char **traceprobe_expand_meta_args(int argc, const char *argv[], n = simple_strtoul(argv[i] + 4, &type, 10); if (type && !(*type == ':' || *type == '\0')) { trace_probe_log_err(0, BAD_VAR); - ret = -ENOENT; - goto error; + return ERR_PTR(-ENOENT); } /* Note: $argN starts from $arg1 */ ret = sprint_nth_btf_arg(n - 1, type, buf + used, bufsize - used, ctx); if (ret < 0) - goto error; + return ERR_PTR(ret); new_argv[j++] = buf + used; used += ret + 1; } else new_argv[j++] = argv[i]; } - return new_argv; - -error: - kfree(new_argv); - return ERR_PTR(ret); + return_ptr(new_argv); } /* @buf: *buf must be equal to NULL. Caller must to free *buf */ @@ -1747,14 +1734,14 @@ int traceprobe_expand_dentry_args(int argc, const char *argv[], char **buf) { int i, used, ret; const int bufsize = MAX_DENTRY_ARGS_LEN; - char *tmpbuf = NULL; + char *tmpbuf __free(kfree) = NULL; if (*buf) return -EINVAL; used = 0; for (i = 0; i < argc; i++) { - char *tmp; + char *tmp __free(kfree) = NULL; char *equal; size_t arg_len; @@ -1769,7 +1756,7 @@ int traceprobe_expand_dentry_args(int argc, const char *argv[], char **buf) tmp = kstrdup(argv[i], GFP_KERNEL); if (!tmp) - goto nomem; + return -ENOMEM; equal = strchr(tmp, '='); if (equal) @@ -1790,18 +1777,15 @@ int traceprobe_expand_dentry_args(int argc, const char *argv[], char **buf) offsetof(struct file, f_path.dentry), equal ? equal + 1 : tmp); - kfree(tmp); + kfree(no_free_ptr(tmp)); if (ret >= bufsize - used) - goto nomem; + return -ENOMEM; argv[i] = tmpbuf + used; used += ret + 1; } - *buf = tmpbuf; + *buf = no_free_ptr(tmpbuf); return 0; -nomem: - kfree(tmpbuf); - return -ENOMEM; } void traceprobe_finish_parse(struct traceprobe_parse_context *ctx) From patchwork Sun Jan 5 12:48:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 13926514 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AD920148FE4; Sun, 5 Jan 2025 12:48:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736081315; cv=none; b=kUd42vIuEU1DEMlHPwp5AzM8vLJ2HkMCiH+ROZUChrpa/QGmizkvFpbjodWW1tWz9DhkYXSpWYHdPOt2oSWrgjqtopRF8CzIPD1xlB5P1dL+Lp8bOJ0NIh534MPZO+lkbFKoaJdp2kvvRyWL1NoKbka7VD8ZO5BAPvA/dsdemDo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736081315; c=relaxed/simple; bh=uzkzzVOVp+KWO+4A35/pNLQLY+KpQ4i4Dz/CaWwI1yY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KM1TJ6cVYSMU7734fshy3lzvfyadx+XUGbL6TaiCn57WkDrAQo6fq0JDrdSO7SEqblGp9CU/ilxf/CsYJJ6+X6D44emLfaGVKgq/q1ENp60kk7San40+ajl5eEX4HbOwGZ64ZTdoQbvjEGlOlfRTl/87jLA3XOF91r53ZVYmuNI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CLa2aiKH; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CLa2aiKH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 30EE7C4CED0; Sun, 5 Jan 2025 12:48:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736081315; bh=uzkzzVOVp+KWO+4A35/pNLQLY+KpQ4i4Dz/CaWwI1yY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CLa2aiKHY3P+0phL9k7Ij/KB2fJuYYcrlPV/tPKwPdZOcegPSSPmc8ew/4YKDKa34 NksuPE7WiyDvavG8drhcXANQPJiyPkWD+EA9NZE899fOEeJlFTisd6bYRsjPQqn5pB N/UxEGQAxOJktvdOY1XS00g8WOqohy4zPBGPhiSkkwoIncnmv7veuVSCRFhB0ob2gr FEDwDM74Vn0FFovqgA98ZVmOMgBJAFO1o0JNUEt1RaLJ77bpaDtG6UGHehtpYittvZ bDOuOEWWo0BfWMW0NVHpQRHYJrWcaSjzeKQDMyCtllYc5lBaIGZsSS7xHGZIgmybOS c/okrwCgawypg== From: "Masami Hiramatsu (Google)" To: Steven Rostedt , Peter Zijlstra Cc: Anil S Keshavamurthy , Masami Hiramatsu , "David S . Miller" , Mathieu Desnoyers , Oleg Nesterov , Tzvetomir Stoyanov , Naveen N Rao , Josh Poimboeuf , Jason Baron , Ard Biesheuvel , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Subject: [PATCH v2 5/6] tracing: Use __free() for kprobe events to cleanup Date: Sun, 5 Jan 2025 21:48:29 +0900 Message-ID: <173608130975.1253657.5725356281406948364.stgit@devnote2> X-Mailer: git-send-email 2.43.0 In-Reply-To: <173608125422.1253657.3732758016133408588.stgit@devnote2> References: <173608125422.1253657.3732758016133408588.stgit@devnote2> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Masami Hiramatsu (Google) Use __free() in trace_kprobe.c to cleanup code. Signed-off-by: Masami Hiramatsu (Google) --- Changes in v2: - Instead of using no_free_ptr(), just assign NULL to the registered pointer. --- kernel/trace/trace_kprobe.c | 57 ++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 31 deletions(-) diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c index 4c3e316454a0..e1ae65f57bf9 100644 --- a/kernel/trace/trace_kprobe.c +++ b/kernel/trace/trace_kprobe.c @@ -8,6 +8,7 @@ #define pr_fmt(fmt) "trace_kprobe: " fmt #include +#include #include #include #include @@ -257,6 +258,8 @@ static void free_trace_kprobe(struct trace_kprobe *tk) } } +DEFINE_FREE(trace_kprobe, struct trace_kprobe *, free_trace_kprobe(_T)) + /* * Allocate new trace_probe and initialize it (including kprobes). */ @@ -268,7 +271,7 @@ static struct trace_kprobe *alloc_trace_kprobe(const char *group, int maxactive, int nargs, bool is_return) { - struct trace_kprobe *tk; + struct trace_kprobe *tk __free(trace_kprobe) = NULL; int ret = -ENOMEM; tk = kzalloc(struct_size(tk, tp.args, nargs), GFP_KERNEL); @@ -277,12 +280,12 @@ static struct trace_kprobe *alloc_trace_kprobe(const char *group, tk->nhit = alloc_percpu(unsigned long); if (!tk->nhit) - goto error; + return ERR_PTR(ret); if (symbol) { tk->symbol = kstrdup(symbol, GFP_KERNEL); if (!tk->symbol) - goto error; + return ERR_PTR(ret); tk->rp.kp.symbol_name = tk->symbol; tk->rp.kp.offset = offs; } else @@ -299,13 +302,10 @@ static struct trace_kprobe *alloc_trace_kprobe(const char *group, ret = trace_probe_init(&tk->tp, event, group, false, nargs); if (ret < 0) - goto error; + return ERR_PTR(ret); dyn_event_init(&tk->devent, &trace_kprobe_ops); - return tk; -error: - free_trace_kprobe(tk); - return ERR_PTR(ret); + return_ptr(tk); } static struct trace_kprobe *find_trace_kprobe(const char *event, @@ -861,11 +861,12 @@ static int __trace_kprobe_create(int argc, const char *argv[]) * Type of args: * FETCHARG:TYPE : use TYPE instead of unsigned long. */ - struct trace_kprobe *tk = NULL; + struct trace_kprobe *tk __free(trace_kprobe) = NULL; int i, len, new_argc = 0, ret = 0; bool is_return = false; - char *symbol = NULL, *tmp = NULL; - const char **new_argv = NULL; + char *symbol __free(kfree) = NULL; + char *tmp = NULL; + const char **new_argv __free(kfree) = NULL; const char *event = NULL, *group = KPROBE_EVENT_SYSTEM; enum probe_print_type ptype; int maxactive = 0; @@ -874,7 +875,7 @@ static int __trace_kprobe_create(int argc, const char *argv[]) char buf[MAX_EVENT_NAME_LEN]; char gbuf[MAX_EVENT_NAME_LEN]; char abuf[MAX_BTF_ARGS_LEN]; - char *dbuf = NULL; + char *dbuf __free(kfree) = NULL; struct traceprobe_parse_context ctx = { .flags = TPARG_FL_KERNEL }; switch (argv[0][0]) { @@ -931,7 +932,7 @@ static int __trace_kprobe_create(int argc, const char *argv[]) /* Check whether uprobe event specified */ if (strchr(argv[1], '/') && strchr(argv[1], ':')) { ret = -ECANCELED; - goto error; + goto out; } /* a symbol specified */ symbol = kstrdup(argv[1], GFP_KERNEL); @@ -1035,7 +1036,7 @@ static int __trace_kprobe_create(int argc, const char *argv[]) ctx.offset = 0; ret = traceprobe_parse_probe_arg(&tk->tp, i, argv[i], &ctx); if (ret) - goto error; /* This can be -ENOMEM */ + goto out; /* This can be -ENOMEM */ } /* entry handler for kretprobe */ if (is_return && tk->tp.entry_arg) { @@ -1046,7 +1047,7 @@ static int __trace_kprobe_create(int argc, const char *argv[]) ptype = is_return ? PROBE_PRINT_RETURN : PROBE_PRINT_NORMAL; ret = traceprobe_set_print_fmt(&tk->tp, ptype); if (ret < 0) - goto error; + goto out; ret = register_trace_kprobe(tk); if (ret) { @@ -1057,21 +1058,20 @@ static int __trace_kprobe_create(int argc, const char *argv[]) trace_probe_log_err(0, BAD_PROBE_ADDR); else if (ret != -ENOMEM && ret != -EEXIST) trace_probe_log_err(0, FAIL_REG_PROBE); - goto error; - } + } else + /* + * Here, 'tk' has been registered to the list successfully, + * so we don't need to free it. + */ + tk = NULL; out: traceprobe_finish_parse(&ctx); trace_probe_log_clear(); - kfree(new_argv); - kfree(symbol); - kfree(dbuf); return ret; parse_error: ret = -EINVAL; -error: - free_trace_kprobe(tk); goto out; } @@ -1893,7 +1893,7 @@ create_local_trace_kprobe(char *func, void *addr, unsigned long offs, bool is_return) { enum probe_print_type ptype; - struct trace_kprobe *tk; + struct trace_kprobe *tk __free(trace_kprobe) = NULL; int ret; char *event; @@ -1924,19 +1924,14 @@ create_local_trace_kprobe(char *func, void *addr, unsigned long offs, ptype = trace_kprobe_is_return(tk) ? PROBE_PRINT_RETURN : PROBE_PRINT_NORMAL; - if (traceprobe_set_print_fmt(&tk->tp, ptype) < 0) { - ret = -ENOMEM; - goto error; - } + if (traceprobe_set_print_fmt(&tk->tp, ptype) < 0) + return ERR_PTR(-ENOMEM); ret = __register_trace_kprobe(tk); if (ret < 0) - goto error; + return ERR_PTR(ret); return trace_probe_event_call(&tk->tp); -error: - free_trace_kprobe(tk); - return ERR_PTR(ret); } void destroy_local_trace_kprobe(struct trace_event_call *event_call) From patchwork Sun Jan 5 12:48:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 13926515 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9697314D2A7; Sun, 5 Jan 2025 12:48:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736081326; cv=none; b=PcuKa/kVUlF6TcNs401wug8m/2wJtH4uxsG10Ns/Jbci8yEzNRTfpCfXVEmEjkNs3BhVMApI6MYooiD7+dswlxL64XYCn/TdDRLwHpNF5N7K8knGSIC9S4CWL7k16sJ6TbkjuKCvK5ki+hZFt+M2QMJLXgVAHsXUzeLjT2NFrX8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736081326; c=relaxed/simple; bh=cUk0FGMod4R3TPo7w6+8KT52zO+2JcZZNj1drC22v3o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Nr7iTFiDl0jCJ35SS03yfRCoMvLjgBPH69ArgTj32kEMqfyC+hz4C94UIKTerI87OqPLVMAaOqpRpbrG8sjz19JXmgZ2p27LnJ1A71ZdJWERJl+hpRyJk0rGL49V5pFqdpEVntNnGYU3a9Sp24J9VC7I3XT8atz38ylaadWo3Ks= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UWjyr3Wu; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UWjyr3Wu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0DB95C4CEE0; Sun, 5 Jan 2025 12:48:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736081326; bh=cUk0FGMod4R3TPo7w6+8KT52zO+2JcZZNj1drC22v3o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UWjyr3Wu5mq8zOqM3qHUHRJFg22MO5e4N5+vecfsl9uJ1KDJNC+hvo6EmwxLcuYnS d9fIBrd5Tn17pkBV8rnc6ogru1Wn8rzEk3zm+gQK1waCMJZdAGZ9DHChOVkCj83z/k ElGp1AoKCvF5MWm+1avki/TaAlZ92q+GgOzXay7EhvjSpre3/sI85okZuCYP7yHlla 4VWMOCLU/X1dCWgZOTjVGLOgt0/MxCOBsQlztSzLGX51U7U/E8I36nNbmi1AH1Jpjo Joe283+aGIdfqSCeLPyNhr93xLlyoMDR2cUrnEbW61fNLlkQbKDrXXhInbNjpeySQK kFnw8jr3ryu7Q== From: "Masami Hiramatsu (Google)" To: Steven Rostedt , Peter Zijlstra Cc: Anil S Keshavamurthy , Masami Hiramatsu , "David S . Miller" , Mathieu Desnoyers , Oleg Nesterov , Tzvetomir Stoyanov , Naveen N Rao , Josh Poimboeuf , Jason Baron , Ard Biesheuvel , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Subject: [PATCH v2 6/6] tracing/kprobes: Simplify __trace_kprobe_create() by removing gotos Date: Sun, 5 Jan 2025 21:48:40 +0900 Message-ID: <173608132061.1253657.12688788891506602137.stgit@devnote2> X-Mailer: git-send-email 2.43.0 In-Reply-To: <173608125422.1253657.3732758016133408588.stgit@devnote2> References: <173608125422.1253657.3732758016133408588.stgit@devnote2> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Masami Hiramatsu (Google) Simplify __trace_kprobe_create() by removing gotos. Signed-off-by: Masami Hiramatsu (Google) --- kernel/trace/trace_kprobe.c | 82 ++++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c index e1ae65f57bf9..b5c59c0f83cb 100644 --- a/kernel/trace/trace_kprobe.c +++ b/kernel/trace/trace_kprobe.c @@ -835,7 +835,8 @@ static int validate_probe_symbol(char *symbol) static int trace_kprobe_entry_handler(struct kretprobe_instance *ri, struct pt_regs *regs); -static int __trace_kprobe_create(int argc, const char *argv[]) +static int ___trace_kprobe_create(int argc, const char *argv[], + struct traceprobe_parse_context *ctx) { /* * Argument syntax: @@ -876,7 +877,6 @@ static int __trace_kprobe_create(int argc, const char *argv[]) char gbuf[MAX_EVENT_NAME_LEN]; char abuf[MAX_BTF_ARGS_LEN]; char *dbuf __free(kfree) = NULL; - struct traceprobe_parse_context ctx = { .flags = TPARG_FL_KERNEL }; switch (argv[0][0]) { case 'r': @@ -890,8 +890,6 @@ static int __trace_kprobe_create(int argc, const char *argv[]) if (argc < 2) return -ECANCELED; - trace_probe_log_init("trace_kprobe", argc, argv); - event = strchr(&argv[0][1], ':'); if (event) event++; @@ -899,7 +897,7 @@ static int __trace_kprobe_create(int argc, const char *argv[]) if (isdigit(argv[0][1])) { if (!is_return) { trace_probe_log_err(1, BAD_MAXACT_TYPE); - goto parse_error; + return -EINVAL; } if (event) len = event - &argv[0][1] - 1; @@ -907,21 +905,21 @@ static int __trace_kprobe_create(int argc, const char *argv[]) len = strlen(&argv[0][1]); if (len > MAX_EVENT_NAME_LEN - 1) { trace_probe_log_err(1, BAD_MAXACT); - goto parse_error; + return -EINVAL; } memcpy(buf, &argv[0][1], len); buf[len] = '\0'; ret = kstrtouint(buf, 0, &maxactive); if (ret || !maxactive) { trace_probe_log_err(1, BAD_MAXACT); - goto parse_error; + return -EINVAL; } /* kretprobes instances are iterated over via a list. The * maximum should stay reasonable. */ if (maxactive > KRETPROBE_MAXACTIVE_MAX) { trace_probe_log_err(1, MAXACT_TOO_BIG); - goto parse_error; + return -EINVAL; } } @@ -930,16 +928,13 @@ static int __trace_kprobe_create(int argc, const char *argv[]) if (kstrtoul(argv[1], 0, (unsigned long *)&addr)) { trace_probe_log_set_index(1); /* Check whether uprobe event specified */ - if (strchr(argv[1], '/') && strchr(argv[1], ':')) { - ret = -ECANCELED; - goto out; - } + if (strchr(argv[1], '/') && strchr(argv[1], ':')) + return -ECANCELED; + /* a symbol specified */ symbol = kstrdup(argv[1], GFP_KERNEL); - if (!symbol) { - ret = -ENOMEM; - goto error; - } + if (!symbol) + return -ENOMEM; tmp = strchr(symbol, '%'); if (tmp) { @@ -948,7 +943,7 @@ static int __trace_kprobe_create(int argc, const char *argv[]) is_return = true; } else { trace_probe_log_err(tmp - symbol, BAD_ADDR_SUFFIX); - goto parse_error; + return -EINVAL; } } @@ -956,7 +951,7 @@ static int __trace_kprobe_create(int argc, const char *argv[]) ret = traceprobe_split_symbol_offset(symbol, &offset); if (ret || offset < 0 || offset > UINT_MAX) { trace_probe_log_err(0, BAD_PROBE_ADDR); - goto parse_error; + return -EINVAL; } ret = validate_probe_symbol(symbol); if (ret) { @@ -964,17 +959,17 @@ static int __trace_kprobe_create(int argc, const char *argv[]) trace_probe_log_err(0, NON_UNIQ_SYMBOL); else trace_probe_log_err(0, BAD_PROBE_ADDR); - goto parse_error; + return -EINVAL; } if (is_return) - ctx.flags |= TPARG_FL_RETURN; + ctx->flags |= TPARG_FL_RETURN; ret = kprobe_on_func_entry(NULL, symbol, offset); if (ret == 0 && !is_return) - ctx.flags |= TPARG_FL_FENTRY; + ctx->flags |= TPARG_FL_FENTRY; /* Defer the ENOENT case until register kprobe */ if (ret == -EINVAL && is_return) { trace_probe_log_err(0, BAD_RETPROBE); - goto parse_error; + return -EINVAL; } } @@ -983,7 +978,7 @@ static int __trace_kprobe_create(int argc, const char *argv[]) ret = traceprobe_parse_event_name(&event, &group, gbuf, event - argv[0]); if (ret) - goto parse_error; + return ret; } if (!event) { @@ -999,26 +994,24 @@ static int __trace_kprobe_create(int argc, const char *argv[]) } argc -= 2; argv += 2; - ctx.funcname = symbol; + ctx->funcname = symbol; new_argv = traceprobe_expand_meta_args(argc, argv, &new_argc, - abuf, MAX_BTF_ARGS_LEN, &ctx); + abuf, MAX_BTF_ARGS_LEN, ctx); if (IS_ERR(new_argv)) { ret = PTR_ERR(new_argv); new_argv = NULL; - goto out; + return ret; } if (new_argv) { argc = new_argc; argv = new_argv; } - if (argc > MAX_TRACE_ARGS) { - ret = -E2BIG; - goto out; - } + if (argc > MAX_TRACE_ARGS) + return -E2BIG; ret = traceprobe_expand_dentry_args(argc, argv, &dbuf); if (ret) - goto out; + return ret; /* setup a probe */ tk = alloc_trace_kprobe(group, event, addr, symbol, offset, maxactive, @@ -1027,16 +1020,16 @@ static int __trace_kprobe_create(int argc, const char *argv[]) ret = PTR_ERR(tk); /* This must return -ENOMEM, else there is a bug */ WARN_ON_ONCE(ret != -ENOMEM); - goto out; /* We know tk is not allocated */ + return ret; /* We know tk is not allocated */ } /* parse arguments */ for (i = 0; i < argc; i++) { trace_probe_log_set_index(i + 2); - ctx.offset = 0; - ret = traceprobe_parse_probe_arg(&tk->tp, i, argv[i], &ctx); + ctx->offset = 0; + ret = traceprobe_parse_probe_arg(&tk->tp, i, argv[i], ctx); if (ret) - goto out; /* This can be -ENOMEM */ + return ret; /* This can be -ENOMEM */ } /* entry handler for kretprobe */ if (is_return && tk->tp.entry_arg) { @@ -1047,7 +1040,7 @@ static int __trace_kprobe_create(int argc, const char *argv[]) ptype = is_return ? PROBE_PRINT_RETURN : PROBE_PRINT_NORMAL; ret = traceprobe_set_print_fmt(&tk->tp, ptype); if (ret < 0) - goto out; + return ret; ret = register_trace_kprobe(tk); if (ret) { @@ -1065,14 +1058,21 @@ static int __trace_kprobe_create(int argc, const char *argv[]) */ tk = NULL; -out: + return ret; +} + +static int __trace_kprobe_create(int argc, const char *argv[]) +{ + struct traceprobe_parse_context ctx = { .flags = TPARG_FL_KERNEL }; + int ret; + + trace_probe_log_init("trace_kprobe", argc, argv); + + ret = ___trace_kprobe_create(argc, argv, &ctx); + traceprobe_finish_parse(&ctx); trace_probe_log_clear(); return ret; - -parse_error: - ret = -EINVAL; - goto out; } static int trace_kprobe_create(const char *raw_command)