@@ -64,22 +64,13 @@ const struct file_operations *debugfs_real_fops(const struct file *filp)
64
64
}
65
65
EXPORT_SYMBOL_GPL (debugfs_real_fops );
66
66
67
- /**
68
- * debugfs_file_get - mark the beginning of file data access
69
- * @dentry: the dentry object whose data is being accessed.
70
- *
71
- * Up to a matching call to debugfs_file_put(), any successive call
72
- * into the file removing functions debugfs_remove() and
73
- * debugfs_remove_recursive() will block. Since associated private
74
- * file data may only get freed after a successful return of any of
75
- * the removal functions, you may safely access it after a successful
76
- * call to debugfs_file_get() without worrying about lifetime issues.
77
- *
78
- * If -%EIO is returned, the file has already been removed and thus,
79
- * it is not safe to access any of its data. If, on the other hand,
80
- * it is allowed to access the file data, zero is returned.
81
- */
82
- int debugfs_file_get (struct dentry * dentry )
67
+ enum dbgfs_get_mode {
68
+ DBGFS_GET_ALREADY ,
69
+ DBGFS_GET_REGULAR ,
70
+ DBGFS_GET_SHORT ,
71
+ };
72
+
73
+ static int __debugfs_file_get (struct dentry * dentry , enum dbgfs_get_mode mode )
83
74
{
84
75
struct debugfs_fsdata * fsd ;
85
76
void * d_fsd ;
@@ -96,15 +87,17 @@ int debugfs_file_get(struct dentry *dentry)
96
87
if (!((unsigned long )d_fsd & DEBUGFS_FSDATA_IS_REAL_FOPS_BIT )) {
97
88
fsd = d_fsd ;
98
89
} else {
90
+ if (WARN_ON (mode == DBGFS_GET_ALREADY ))
91
+ return - EINVAL ;
92
+
99
93
fsd = kmalloc (sizeof (* fsd ), GFP_KERNEL );
100
94
if (!fsd )
101
95
return - ENOMEM ;
102
96
103
- if (( unsigned long ) d_fsd & DEBUGFS_FSDATA_IS_SHORT_FOPS_BIT ) {
97
+ if (mode == DBGFS_GET_SHORT ) {
104
98
fsd -> real_fops = NULL ;
105
99
fsd -> short_fops = (void * )((unsigned long )d_fsd &
106
- ~(DEBUGFS_FSDATA_IS_REAL_FOPS_BIT |
107
- DEBUGFS_FSDATA_IS_SHORT_FOPS_BIT ));
100
+ ~DEBUGFS_FSDATA_IS_REAL_FOPS_BIT );
108
101
} else {
109
102
fsd -> real_fops = (void * )((unsigned long )d_fsd &
110
103
~DEBUGFS_FSDATA_IS_REAL_FOPS_BIT );
@@ -138,6 +131,26 @@ int debugfs_file_get(struct dentry *dentry)
138
131
139
132
return 0 ;
140
133
}
134
+
135
+ /**
136
+ * debugfs_file_get - mark the beginning of file data access
137
+ * @dentry: the dentry object whose data is being accessed.
138
+ *
139
+ * Up to a matching call to debugfs_file_put(), any successive call
140
+ * into the file removing functions debugfs_remove() and
141
+ * debugfs_remove_recursive() will block. Since associated private
142
+ * file data may only get freed after a successful return of any of
143
+ * the removal functions, you may safely access it after a successful
144
+ * call to debugfs_file_get() without worrying about lifetime issues.
145
+ *
146
+ * If -%EIO is returned, the file has already been removed and thus,
147
+ * it is not safe to access any of its data. If, on the other hand,
148
+ * it is allowed to access the file data, zero is returned.
149
+ */
150
+ int debugfs_file_get (struct dentry * dentry )
151
+ {
152
+ return __debugfs_file_get (dentry , DBGFS_GET_ALREADY );
153
+ }
141
154
EXPORT_SYMBOL_GPL (debugfs_file_get );
142
155
143
156
/**
@@ -267,7 +280,7 @@ static int open_proxy_open(struct inode *inode, struct file *filp)
267
280
const struct file_operations * real_fops = NULL ;
268
281
int r ;
269
282
270
- r = debugfs_file_get (dentry );
283
+ r = __debugfs_file_get (dentry , DBGFS_GET_REGULAR );
271
284
if (r )
272
285
return r == - EIO ? - ENOENT : r ;
273
286
@@ -424,15 +437,16 @@ static void __full_proxy_fops_init(struct file_operations *proxy_fops,
424
437
proxy_fops -> unlocked_ioctl = full_proxy_unlocked_ioctl ;
425
438
}
426
439
427
- static int full_proxy_open (struct inode * inode , struct file * filp )
440
+ static int full_proxy_open (struct inode * inode , struct file * filp ,
441
+ enum dbgfs_get_mode mode )
428
442
{
429
443
struct dentry * dentry = F_DENTRY (filp );
430
444
const struct file_operations * real_fops ;
431
445
struct file_operations * proxy_fops = NULL ;
432
446
struct debugfs_fsdata * fsd ;
433
447
int r ;
434
448
435
- r = debugfs_file_get (dentry );
449
+ r = __debugfs_file_get (dentry , mode );
436
450
if (r )
437
451
return r == - EIO ? - ENOENT : r ;
438
452
@@ -491,8 +505,22 @@ static int full_proxy_open(struct inode *inode, struct file *filp)
491
505
return r ;
492
506
}
493
507
508
+ static int full_proxy_open_regular (struct inode * inode , struct file * filp )
509
+ {
510
+ return full_proxy_open (inode , filp , DBGFS_GET_REGULAR );
511
+ }
512
+
494
513
const struct file_operations debugfs_full_proxy_file_operations = {
495
- .open = full_proxy_open ,
514
+ .open = full_proxy_open_regular ,
515
+ };
516
+
517
+ static int full_proxy_open_short (struct inode * inode , struct file * filp )
518
+ {
519
+ return full_proxy_open (inode , filp , DBGFS_GET_SHORT );
520
+ }
521
+
522
+ const struct file_operations debugfs_full_short_proxy_file_operations = {
523
+ .open = full_proxy_open_short ,
496
524
};
497
525
498
526
ssize_t debugfs_attr_read (struct file * file , char __user * buf ,
0 commit comments