@@ -89,10 +89,32 @@ static int ovl_change_flags(struct file *file, unsigned int flags)
8989 return 0 ;
9090}
9191
92+ struct ovl_file {
93+ struct file * realfile ;
94+ };
95+
96+ struct ovl_file * ovl_file_alloc (struct file * realfile )
97+ {
98+ struct ovl_file * of = kzalloc (sizeof (struct ovl_file ), GFP_KERNEL );
99+
100+ if (unlikely (!of ))
101+ return NULL ;
102+
103+ of -> realfile = realfile ;
104+ return of ;
105+ }
106+
107+ void ovl_file_free (struct ovl_file * of )
108+ {
109+ fput (of -> realfile );
110+ kfree (of );
111+ }
112+
92113static int ovl_real_fdget_path (const struct file * file , struct fd * real ,
93114 struct path * realpath )
94115{
95- struct file * realfile = file -> private_data ;
116+ struct ovl_file * of = file -> private_data ;
117+ struct file * realfile = of -> realfile ;
96118
97119 real -> word = (unsigned long )realfile ;
98120
@@ -144,6 +166,7 @@ static int ovl_open(struct inode *inode, struct file *file)
144166 struct dentry * dentry = file_dentry (file );
145167 struct file * realfile ;
146168 struct path realpath ;
169+ struct ovl_file * of ;
147170 int err ;
148171
149172 /* lazy lookup and verify lowerdata */
@@ -166,15 +189,20 @@ static int ovl_open(struct inode *inode, struct file *file)
166189 if (IS_ERR (realfile ))
167190 return PTR_ERR (realfile );
168191
169- file -> private_data = realfile ;
192+ of = ovl_file_alloc (realfile );
193+ if (!of ) {
194+ fput (realfile );
195+ return - ENOMEM ;
196+ }
197+
198+ file -> private_data = of ;
170199
171200 return 0 ;
172201}
173202
174203static int ovl_release (struct inode * inode , struct file * file )
175204{
176- fput (file -> private_data );
177-
205+ ovl_file_free (file -> private_data );
178206 return 0 ;
179207}
180208
@@ -426,13 +454,13 @@ static int ovl_fsync(struct file *file, loff_t start, loff_t end, int datasync)
426454
427455static int ovl_mmap (struct file * file , struct vm_area_struct * vma )
428456{
429- struct file * realfile = file -> private_data ;
457+ struct ovl_file * of = file -> private_data ;
430458 struct backing_file_ctx ctx = {
431459 .cred = ovl_creds (file_inode (file )-> i_sb ),
432460 .accessed = ovl_file_accessed ,
433461 };
434462
435- return backing_file_mmap (realfile , vma , & ctx );
463+ return backing_file_mmap (of -> realfile , vma , & ctx );
436464}
437465
438466static long ovl_fallocate (struct file * file , int mode , loff_t offset , loff_t len )
0 commit comments