@@ -304,6 +304,17 @@ void trace_array_put(struct trace_array *this_tr)
304
304
mutex_unlock (& trace_types_lock );
305
305
}
306
306
307
+ int tracing_check_open_get_tr (struct trace_array * tr )
308
+ {
309
+ if (tracing_disabled )
310
+ return - ENODEV ;
311
+
312
+ if (tr && trace_array_get (tr ) < 0 )
313
+ return - ENODEV ;
314
+
315
+ return 0 ;
316
+ }
317
+
307
318
int call_filter_check_discard (struct trace_event_call * call , void * rec ,
308
319
struct ring_buffer * buffer ,
309
320
struct ring_buffer_event * event )
@@ -4140,8 +4151,11 @@ __tracing_open(struct inode *inode, struct file *file, bool snapshot)
4140
4151
4141
4152
int tracing_open_generic (struct inode * inode , struct file * filp )
4142
4153
{
4143
- if (tracing_disabled )
4144
- return - ENODEV ;
4154
+ int ret ;
4155
+
4156
+ ret = tracing_check_open_get_tr (NULL );
4157
+ if (ret )
4158
+ return ret ;
4145
4159
4146
4160
filp -> private_data = inode -> i_private ;
4147
4161
return 0 ;
@@ -4159,12 +4173,11 @@ bool tracing_is_disabled(void)
4159
4173
int tracing_open_generic_tr (struct inode * inode , struct file * filp )
4160
4174
{
4161
4175
struct trace_array * tr = inode -> i_private ;
4176
+ int ret ;
4162
4177
4163
- if (tracing_disabled )
4164
- return - ENODEV ;
4165
-
4166
- if (trace_array_get (tr ) < 0 )
4167
- return - ENODEV ;
4178
+ ret = tracing_check_open_get_tr (tr );
4179
+ if (ret )
4180
+ return ret ;
4168
4181
4169
4182
filp -> private_data = inode -> i_private ;
4170
4183
@@ -4233,10 +4246,11 @@ static int tracing_open(struct inode *inode, struct file *file)
4233
4246
{
4234
4247
struct trace_array * tr = inode -> i_private ;
4235
4248
struct trace_iterator * iter ;
4236
- int ret = 0 ;
4249
+ int ret ;
4237
4250
4238
- if (trace_array_get (tr ) < 0 )
4239
- return - ENODEV ;
4251
+ ret = tracing_check_open_get_tr (tr );
4252
+ if (ret )
4253
+ return ret ;
4240
4254
4241
4255
/* If this file was open for write, then erase contents */
4242
4256
if ((file -> f_mode & FMODE_WRITE ) && (file -> f_flags & O_TRUNC )) {
@@ -4352,11 +4366,9 @@ static int show_traces_open(struct inode *inode, struct file *file)
4352
4366
struct seq_file * m ;
4353
4367
int ret ;
4354
4368
4355
- if (tracing_disabled )
4356
- return - ENODEV ;
4357
-
4358
- if (trace_array_get (tr ) < 0 )
4359
- return - ENODEV ;
4369
+ ret = tracing_check_open_get_tr (tr );
4370
+ if (ret )
4371
+ return ret ;
4360
4372
4361
4373
ret = seq_open (file , & show_traces_seq_ops );
4362
4374
if (ret ) {
@@ -4710,11 +4722,9 @@ static int tracing_trace_options_open(struct inode *inode, struct file *file)
4710
4722
struct trace_array * tr = inode -> i_private ;
4711
4723
int ret ;
4712
4724
4713
- if (tracing_disabled )
4714
- return - ENODEV ;
4715
-
4716
- if (trace_array_get (tr ) < 0 )
4717
- return - ENODEV ;
4725
+ ret = tracing_check_open_get_tr (tr );
4726
+ if (ret )
4727
+ return ret ;
4718
4728
4719
4729
ret = single_open (file , tracing_trace_options_show , inode -> i_private );
4720
4730
if (ret < 0 )
@@ -5051,8 +5061,11 @@ static const struct seq_operations tracing_saved_tgids_seq_ops = {
5051
5061
5052
5062
static int tracing_saved_tgids_open (struct inode * inode , struct file * filp )
5053
5063
{
5054
- if (tracing_disabled )
5055
- return - ENODEV ;
5064
+ int ret ;
5065
+
5066
+ ret = tracing_check_open_get_tr (NULL );
5067
+ if (ret )
5068
+ return ret ;
5056
5069
5057
5070
return seq_open (filp , & tracing_saved_tgids_seq_ops );
5058
5071
}
@@ -5128,8 +5141,11 @@ static const struct seq_operations tracing_saved_cmdlines_seq_ops = {
5128
5141
5129
5142
static int tracing_saved_cmdlines_open (struct inode * inode , struct file * filp )
5130
5143
{
5131
- if (tracing_disabled )
5132
- return - ENODEV ;
5144
+ int ret ;
5145
+
5146
+ ret = tracing_check_open_get_tr (NULL );
5147
+ if (ret )
5148
+ return ret ;
5133
5149
5134
5150
return seq_open (filp , & tracing_saved_cmdlines_seq_ops );
5135
5151
}
@@ -5293,8 +5309,11 @@ static const struct seq_operations tracing_eval_map_seq_ops = {
5293
5309
5294
5310
static int tracing_eval_map_open (struct inode * inode , struct file * filp )
5295
5311
{
5296
- if (tracing_disabled )
5297
- return - ENODEV ;
5312
+ int ret ;
5313
+
5314
+ ret = tracing_check_open_get_tr (NULL );
5315
+ if (ret )
5316
+ return ret ;
5298
5317
5299
5318
return seq_open (filp , & tracing_eval_map_seq_ops );
5300
5319
}
@@ -5817,13 +5836,11 @@ static int tracing_open_pipe(struct inode *inode, struct file *filp)
5817
5836
{
5818
5837
struct trace_array * tr = inode -> i_private ;
5819
5838
struct trace_iterator * iter ;
5820
- int ret = 0 ;
5821
-
5822
- if (tracing_disabled )
5823
- return - ENODEV ;
5839
+ int ret ;
5824
5840
5825
- if (trace_array_get (tr ) < 0 )
5826
- return - ENODEV ;
5841
+ ret = tracing_check_open_get_tr (tr );
5842
+ if (ret )
5843
+ return ret ;
5827
5844
5828
5845
mutex_lock (& trace_types_lock );
5829
5846
@@ -6560,11 +6577,9 @@ static int tracing_clock_open(struct inode *inode, struct file *file)
6560
6577
struct trace_array * tr = inode -> i_private ;
6561
6578
int ret ;
6562
6579
6563
- if (tracing_disabled )
6564
- return - ENODEV ;
6565
-
6566
- if (trace_array_get (tr ))
6567
- return - ENODEV ;
6580
+ ret = tracing_check_open_get_tr (tr );
6581
+ if (ret )
6582
+ return ret ;
6568
6583
6569
6584
ret = single_open (file , tracing_clock_show , inode -> i_private );
6570
6585
if (ret < 0 )
@@ -6594,11 +6609,9 @@ static int tracing_time_stamp_mode_open(struct inode *inode, struct file *file)
6594
6609
struct trace_array * tr = inode -> i_private ;
6595
6610
int ret ;
6596
6611
6597
- if (tracing_disabled )
6598
- return - ENODEV ;
6599
-
6600
- if (trace_array_get (tr ))
6601
- return - ENODEV ;
6612
+ ret = tracing_check_open_get_tr (tr );
6613
+ if (ret )
6614
+ return ret ;
6602
6615
6603
6616
ret = single_open (file , tracing_time_stamp_mode_show , inode -> i_private );
6604
6617
if (ret < 0 )
@@ -6651,10 +6664,11 @@ static int tracing_snapshot_open(struct inode *inode, struct file *file)
6651
6664
struct trace_array * tr = inode -> i_private ;
6652
6665
struct trace_iterator * iter ;
6653
6666
struct seq_file * m ;
6654
- int ret = 0 ;
6667
+ int ret ;
6655
6668
6656
- if (trace_array_get (tr ) < 0 )
6657
- return - ENODEV ;
6669
+ ret = tracing_check_open_get_tr (tr );
6670
+ if (ret )
6671
+ return ret ;
6658
6672
6659
6673
if (file -> f_mode & FMODE_READ ) {
6660
6674
iter = __tracing_open (inode , file , true);
@@ -7118,8 +7132,9 @@ static int tracing_err_log_open(struct inode *inode, struct file *file)
7118
7132
struct trace_array * tr = inode -> i_private ;
7119
7133
int ret = 0 ;
7120
7134
7121
- if (trace_array_get (tr ) < 0 )
7122
- return - ENODEV ;
7135
+ ret = tracing_check_open_get_tr (tr );
7136
+ if (ret )
7137
+ return ret ;
7123
7138
7124
7139
/* If this file was opened for write, then erase contents */
7125
7140
if ((file -> f_mode & FMODE_WRITE ) && (file -> f_flags & O_TRUNC ))
@@ -7170,11 +7185,9 @@ static int tracing_buffers_open(struct inode *inode, struct file *filp)
7170
7185
struct ftrace_buffer_info * info ;
7171
7186
int ret ;
7172
7187
7173
- if (tracing_disabled )
7174
- return - ENODEV ;
7175
-
7176
- if (trace_array_get (tr ) < 0 )
7177
- return - ENODEV ;
7188
+ ret = tracing_check_open_get_tr (tr );
7189
+ if (ret )
7190
+ return ret ;
7178
7191
7179
7192
info = kzalloc (sizeof (* info ), GFP_KERNEL );
7180
7193
if (!info ) {
0 commit comments