Merge tag 'trace-v6.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[platform/kernel/linux-starfive.git] / kernel / trace / trace.c
index 2b4ded7..abaaf51 100644 (file)
@@ -1772,7 +1772,7 @@ static void trace_create_maxlat_file(struct trace_array *tr,
        init_irq_work(&tr->fsnotify_irqwork, latency_fsnotify_workfn_irq);
        tr->d_max_latency = trace_create_file("tracing_max_latency",
                                              TRACE_MODE_WRITE,
-                                             d_tracer, &tr->max_latency,
+                                             d_tracer, tr,
                                              &tracing_max_lat_fops);
 }
 
@@ -1805,7 +1805,7 @@ void latency_fsnotify(struct trace_array *tr)
 
 #define trace_create_maxlat_file(tr, d_tracer)                         \
        trace_create_file("tracing_max_latency", TRACE_MODE_WRITE,      \
-                         d_tracer, &tr->max_latency, &tracing_max_lat_fops)
+                         d_tracer, tr, &tracing_max_lat_fops)
 
 #endif
 
@@ -4973,6 +4973,33 @@ int tracing_open_generic_tr(struct inode *inode, struct file *filp)
        return 0;
 }
 
+/*
+ * The private pointer of the inode is the trace_event_file.
+ * Update the tr ref count associated to it.
+ */
+int tracing_open_file_tr(struct inode *inode, struct file *filp)
+{
+       struct trace_event_file *file = inode->i_private;
+       int ret;
+
+       ret = tracing_check_open_get_tr(file->tr);
+       if (ret)
+               return ret;
+
+       filp->private_data = inode->i_private;
+
+       return 0;
+}
+
+int tracing_release_file_tr(struct inode *inode, struct file *filp)
+{
+       struct trace_event_file *file = inode->i_private;
+
+       trace_array_put(file->tr);
+
+       return 0;
+}
+
 static int tracing_mark_open(struct inode *inode, struct file *filp)
 {
        stream_open(inode, filp);
@@ -6691,14 +6718,18 @@ static ssize_t
 tracing_max_lat_read(struct file *filp, char __user *ubuf,
                     size_t cnt, loff_t *ppos)
 {
-       return tracing_nsecs_read(filp->private_data, ubuf, cnt, ppos);
+       struct trace_array *tr = filp->private_data;
+
+       return tracing_nsecs_read(&tr->max_latency, ubuf, cnt, ppos);
 }
 
 static ssize_t
 tracing_max_lat_write(struct file *filp, const char __user *ubuf,
                      size_t cnt, loff_t *ppos)
 {
-       return tracing_nsecs_write(filp->private_data, ubuf, cnt, ppos);
+       struct trace_array *tr = filp->private_data;
+
+       return tracing_nsecs_write(&tr->max_latency, ubuf, cnt, ppos);
 }
 
 #endif
@@ -7752,18 +7783,20 @@ static const struct file_operations tracing_thresh_fops = {
 
 #ifdef CONFIG_TRACER_MAX_TRACE
 static const struct file_operations tracing_max_lat_fops = {
-       .open           = tracing_open_generic,
+       .open           = tracing_open_generic_tr,
        .read           = tracing_max_lat_read,
        .write          = tracing_max_lat_write,
        .llseek         = generic_file_llseek,
+       .release        = tracing_release_generic_tr,
 };
 #endif
 
 static const struct file_operations set_tracer_fops = {
-       .open           = tracing_open_generic,
+       .open           = tracing_open_generic_tr,
        .read           = tracing_set_trace_read,
        .write          = tracing_set_trace_write,
        .llseek         = generic_file_llseek,
+       .release        = tracing_release_generic_tr,
 };
 
 static const struct file_operations tracing_pipe_fops = {
@@ -8956,12 +8989,33 @@ trace_options_write(struct file *filp, const char __user *ubuf, size_t cnt,
        return cnt;
 }
 
+static int tracing_open_options(struct inode *inode, struct file *filp)
+{
+       struct trace_option_dentry *topt = inode->i_private;
+       int ret;
+
+       ret = tracing_check_open_get_tr(topt->tr);
+       if (ret)
+               return ret;
+
+       filp->private_data = inode->i_private;
+       return 0;
+}
+
+static int tracing_release_options(struct inode *inode, struct file *file)
+{
+       struct trace_option_dentry *topt = file->private_data;
+
+       trace_array_put(topt->tr);
+       return 0;
+}
 
 static const struct file_operations trace_options_fops = {
-       .open = tracing_open_generic,
+       .open = tracing_open_options,
        .read = trace_options_read,
        .write = trace_options_write,
        .llseek = generic_file_llseek,
+       .release = tracing_release_options,
 };
 
 /*
@@ -9739,8 +9793,8 @@ init_tracer_tracefs(struct trace_array *tr, struct dentry *d_tracer)
                          tr, &tracing_mark_fops);
 
        file = __find_event_file(tr, "ftrace", "print");
-       if (file && file->dir)
-               trace_create_file("trigger", TRACE_MODE_WRITE, file->dir,
+       if (file && file->ef)
+               eventfs_add_file("trigger", TRACE_MODE_WRITE, file->ef,
                                  file, &event_trigger_fops);
        tr->trace_marker_file = file;