@@ -2613,6 +2613,8 @@ __tracing_open(struct inode *inode, struct file *file, bool snapshot)
26132613 tracing_iter_reset (iter , cpu );
26142614 }
26152615
2616+ tr -> ref ++ ;
2617+
26162618 mutex_unlock (& trace_types_lock );
26172619
26182620 return iter ;
@@ -2649,6 +2651,10 @@ static int tracing_release(struct inode *inode, struct file *file)
26492651 tr = iter -> tr ;
26502652
26512653 mutex_lock (& trace_types_lock );
2654+
2655+ WARN_ON (!tr -> ref );
2656+ tr -> ref -- ;
2657+
26522658 for_each_tracing_cpu (cpu ) {
26532659 if (iter -> buffer_iter [cpu ])
26542660 ring_buffer_read_finish (iter -> buffer_iter [cpu ]);
@@ -4460,6 +4466,10 @@ static int tracing_buffers_open(struct inode *inode, struct file *filp)
44604466 if (!info )
44614467 return - ENOMEM ;
44624468
4469+ mutex_lock (& trace_types_lock );
4470+
4471+ tr -> ref ++ ;
4472+
44634473 info -> iter .tr = tr ;
44644474 info -> iter .cpu_file = tc -> cpu ;
44654475 info -> iter .trace = tr -> current_trace ;
@@ -4470,6 +4480,8 @@ static int tracing_buffers_open(struct inode *inode, struct file *filp)
44704480
44714481 filp -> private_data = info ;
44724482
4483+ mutex_unlock (& trace_types_lock );
4484+
44734485 return nonseekable_open (inode , filp );
44744486}
44754487
@@ -4568,10 +4580,17 @@ static int tracing_buffers_release(struct inode *inode, struct file *file)
45684580 struct ftrace_buffer_info * info = file -> private_data ;
45694581 struct trace_iterator * iter = & info -> iter ;
45704582
4583+ mutex_lock (& trace_types_lock );
4584+
4585+ WARN_ON (!iter -> tr -> ref );
4586+ iter -> tr -> ref -- ;
4587+
45714588 if (info -> spare )
45724589 ring_buffer_free_read_page (iter -> trace_buffer -> buffer , info -> spare );
45734590 kfree (info );
45744591
4592+ mutex_unlock (& trace_types_lock );
4593+
45754594 return 0 ;
45764595}
45774596
@@ -5411,6 +5430,10 @@ static int instance_delete(const char *name)
54115430 if (!found )
54125431 goto out_unlock ;
54135432
5433+ ret = - EBUSY ;
5434+ if (tr -> ref )
5435+ goto out_unlock ;
5436+
54145437 list_del (& tr -> list );
54155438
54165439 event_trace_del_tracer (tr );
0 commit comments