linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Divya Indi <divya.indi@oracle.com>
To: Steven Rostedt <rostedt@goodmis.org>, linux-kernel@vger.kernel.org
Cc: Divya Indi <divya.indi@oracle.com>,
	Aruna Ramakrishna <aruna.ramakrishna@oracle.com>,
	Srinivas Eeda <srinivas.eeda@oracle.com>,
	Joe Jin <joe.jin@oracle.com>,
	Manjunath Patil <manjunath.b.patil@oracle.com>
Subject: [PATCH 2/5] tracing: Verify if trace array exists before destroying it.
Date: Wed, 13 Nov 2019 13:15:59 -0800	[thread overview]
Message-ID: <1573679762-7774-3-git-send-email-divya.indi@oracle.com> (raw)
In-Reply-To: <1573679762-7774-2-git-send-email-divya.indi@oracle.com>

A trace array can be destroyed from userspace or kernel. Verify if the
trace exists before proceeding to destroy/remove it.

Signed-off-by: Divya Indi <divya.indi@oracle.com>
Reviewed-by: Aruna Ramakrishna <aruna.ramakrishna@oracle.com>
Reviewed-by: Manjunath Patil <manjunath.b.patil@oracle.com>
---
 kernel/trace/trace.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 1c80521..bff967f 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -8421,17 +8421,26 @@ static int __remove_instance(struct trace_array *tr)
 	return 0;
 }
 
-int trace_array_destroy(struct trace_array *tr)
+int trace_array_destroy(struct trace_array *this_tr)
 {
+	struct trace_array *tr;
 	int ret;
 
-	if (!tr)
+	if (!this_tr)
 		return -EINVAL;
 
 	mutex_lock(&event_mutex);
 	mutex_lock(&trace_types_lock);
 
-	ret = __remove_instance(tr);
+	ret = -ENODEV;
+
+	/* Making sure trace array exists before destroying it. */
+	list_for_each_entry(tr, &ftrace_trace_arrays, list) {
+		if (tr == this_tr) {
+			ret = __remove_instance(tr);
+			break;
+		}
+	}
 
 	mutex_unlock(&trace_types_lock);
 	mutex_unlock(&event_mutex);
-- 
1.8.3.1


  reply	other threads:[~2019-11-13 21:17 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-13 21:15 [RFC v4] Kernel access to ftrace instances Divya Indi
2019-11-13 21:15 ` [PATCH 1/5] tracing: Declare newly exported APIs in include/linux/trace.h Divya Indi
2019-11-13 21:15   ` Divya Indi [this message]
2019-11-13 21:16     ` [PATCH 3/5] tracing: Adding NULL checks Divya Indi
2019-11-13 21:16       ` [PATCH 4/5] tracing: Adding new functions for kernel access to Ftrace instances Divya Indi
2019-11-13 21:16         ` [PATCH 5/5] tracing: Sample module to demonstrate " Divya Indi
2019-11-14 17:17         ` [PATCH 4/5] tracing: Adding new functions for " Steven Rostedt
  -- strict thread matches above, loose matches on Subject: below --
2019-08-14 17:55 [PATCH 0/5 v4]Kernel Access " Divya Indi
2019-08-14 17:55 ` [PATCH 2/5] tracing: Verify if trace array exists before destroying it Divya Indi
2019-08-14 18:42   ` Aruna Ramakrishna

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1573679762-7774-3-git-send-email-divya.indi@oracle.com \
    --to=divya.indi@oracle.com \
    --cc=aruna.ramakrishna@oracle.com \
    --cc=joe.jin@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=manjunath.b.patil@oracle.com \
    --cc=rostedt@goodmis.org \
    --cc=srinivas.eeda@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).