@@ -240,6 +240,11 @@ const struct inode_operations simple_dir_inode_operations = {
240
240
};
241
241
EXPORT_SYMBOL (simple_dir_inode_operations );
242
242
243
+ /* 0 is '.', 1 is '..', so always start with offset 2 or more */
244
+ enum {
245
+ DIR_OFFSET_MIN = 2 ,
246
+ };
247
+
243
248
static void offset_set (struct dentry * dentry , u32 offset )
244
249
{
245
250
dentry -> d_fsdata = (void * )((uintptr_t )(offset ));
@@ -261,9 +266,7 @@ void simple_offset_init(struct offset_ctx *octx)
261
266
{
262
267
xa_init_flags (& octx -> xa , XA_FLAGS_ALLOC1 );
263
268
lockdep_set_class (& octx -> xa .xa_lock , & simple_offset_xa_lock );
264
-
265
- /* 0 is '.', 1 is '..', so always start with offset 2 */
266
- octx -> next_offset = 2 ;
269
+ octx -> next_offset = DIR_OFFSET_MIN ;
267
270
}
268
271
269
272
/**
@@ -276,7 +279,7 @@ void simple_offset_init(struct offset_ctx *octx)
276
279
*/
277
280
int simple_offset_add (struct offset_ctx * octx , struct dentry * dentry )
278
281
{
279
- static const struct xa_limit limit = XA_LIMIT (2 , U32_MAX );
282
+ static const struct xa_limit limit = XA_LIMIT (DIR_OFFSET_MIN , U32_MAX );
280
283
u32 offset ;
281
284
int ret ;
282
285
@@ -481,7 +484,7 @@ static int offset_readdir(struct file *file, struct dir_context *ctx)
481
484
return 0 ;
482
485
483
486
/* In this case, ->private_data is protected by f_pos_lock */
484
- if (ctx -> pos == 2 )
487
+ if (ctx -> pos == DIR_OFFSET_MIN )
485
488
file -> private_data = NULL ;
486
489
else if (file -> private_data == ERR_PTR (- ENOENT ))
487
490
return 0 ;
0 commit comments