Re: [PATCH 2/5] tracing: Verify if trace array exists before destroying it.

2019-08-14 Thread Aruna Ramakrishna




On 08/14/2019 10:55 AM, Divya Indi wrote:

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



^^ s/trace/trace array/

As you pointed out yourself. :)

All the patches look good to me. For this patchset:

Reviewed-by: Aruna Ramakrishna 

Thanks,
Aruna


[PATCH 2/5] tracing: Verify if trace array exists before destroying it.

2019-08-14 Thread Divya Indi
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 
---
 kernel/trace/trace.c | 16 +---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 1c80521..468ecc5 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -8421,17 +8421,27 @@ 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(_mutex);
mutex_lock(_types_lock);
 
-   ret = __remove_instance(tr);
+   ret = -ENODEV;
+
+   /* Making sure trace array exists before destroying it. */
+   list_for_each_entry(tr, _trace_arrays, list) {
+   if (tr == this_tr) {
+   ret = __remove_instance(tr);
+   break;
+   }
+   }
 
mutex_unlock(_types_lock);
mutex_unlock(_mutex);
-- 
1.8.3.1