@@ -237,15 +237,15 @@ static int expand_files(struct files_struct *files, unsigned int nr)
237237 return expanded ;
238238}
239239
240- static inline void __set_close_on_exec (unsigned int fd , struct fdtable * fdt )
240+ static inline void __set_close_on_exec (unsigned int fd , struct fdtable * fdt ,
241+ bool set )
241242{
242- __set_bit (fd , fdt -> close_on_exec );
243- }
244-
245- static inline void __clear_close_on_exec (unsigned int fd , struct fdtable * fdt )
246- {
247- if (test_bit (fd , fdt -> close_on_exec ))
248- __clear_bit (fd , fdt -> close_on_exec );
243+ if (set ) {
244+ __set_bit (fd , fdt -> close_on_exec );
245+ } else {
246+ if (test_bit (fd , fdt -> close_on_exec ))
247+ __clear_bit (fd , fdt -> close_on_exec );
248+ }
249249}
250250
251251static inline void __set_open_fd (unsigned int fd , struct fdtable * fdt )
@@ -518,10 +518,7 @@ static int alloc_fd(unsigned start, unsigned end, unsigned flags)
518518 files -> next_fd = fd + 1 ;
519519
520520 __set_open_fd (fd , fdt );
521- if (flags & O_CLOEXEC )
522- __set_close_on_exec (fd , fdt );
523- else
524- __clear_close_on_exec (fd , fdt );
521+ __set_close_on_exec (fd , fdt , flags & O_CLOEXEC );
525522 error = fd ;
526523
527524out :
@@ -1147,13 +1144,8 @@ void __f_unlock_pos(struct file *f)
11471144void set_close_on_exec (unsigned int fd , int flag )
11481145{
11491146 struct files_struct * files = current -> files ;
1150- struct fdtable * fdt ;
11511147 spin_lock (& files -> file_lock );
1152- fdt = files_fdtable (files );
1153- if (flag )
1154- __set_close_on_exec (fd , fdt );
1155- else
1156- __clear_close_on_exec (fd , fdt );
1148+ __set_close_on_exec (fd , files_fdtable (files ), flag );
11571149 spin_unlock (& files -> file_lock );
11581150}
11591151
@@ -1195,10 +1187,7 @@ __releases(&files->file_lock)
11951187 get_file (file );
11961188 rcu_assign_pointer (fdt -> fd [fd ], file );
11971189 __set_open_fd (fd , fdt );
1198- if (flags & O_CLOEXEC )
1199- __set_close_on_exec (fd , fdt );
1200- else
1201- __clear_close_on_exec (fd , fdt );
1190+ __set_close_on_exec (fd , fdt , flags & O_CLOEXEC );
12021191 spin_unlock (& files -> file_lock );
12031192
12041193 if (tofree )
0 commit comments