@@ -240,6 +240,11 @@ const struct inode_operations simple_dir_inode_operations = {
240240};
241241EXPORT_SYMBOL (simple_dir_inode_operations );
242242
243+ /* 0 is '.', 1 is '..', so always start with offset 2 or more */
244+ enum {
245+ DIR_OFFSET_MIN = 2 ,
246+ };
247+
243248static void offset_set (struct dentry * dentry , u32 offset )
244249{
245250 dentry -> d_fsdata = (void * )((uintptr_t )(offset ));
@@ -261,9 +266,7 @@ void simple_offset_init(struct offset_ctx *octx)
261266{
262267 xa_init_flags (& octx -> xa , XA_FLAGS_ALLOC1 );
263268 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 ;
267270}
268271
269272/**
@@ -276,7 +279,7 @@ void simple_offset_init(struct offset_ctx *octx)
276279 */
277280int simple_offset_add (struct offset_ctx * octx , struct dentry * dentry )
278281{
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 );
280283 u32 offset ;
281284 int ret ;
282285
@@ -481,7 +484,7 @@ static int offset_readdir(struct file *file, struct dir_context *ctx)
481484 return 0 ;
482485
483486 /* In this case, ->private_data is protected by f_pos_lock */
484- if (ctx -> pos == 2 )
487+ if (ctx -> pos == DIR_OFFSET_MIN )
485488 file -> private_data = NULL ;
486489 else if (file -> private_data == ERR_PTR (- ENOENT ))
487490 return 0 ;
0 commit comments