Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
linux
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
linux
Commits
e84f9e57
Commit
e84f9e57
authored
Sep 22, 2013
by
Al Viro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
consolidate the reassignments of ->f_op in ->open() instances
Signed-off-by:
Al Viro
<
viro@zeniv.linux.org.uk
>
parent
7b00ed6f
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
43 additions
and
77 deletions
+43
-77
drivers/char/misc.c
drivers/char/misc.c
+3
-9
drivers/gpu/drm/drm_fops.c
drivers/gpu/drm/drm_fops.c
+6
-11
drivers/media/dvb-core/dvbdev.c
drivers/media/dvb-core/dvbdev.c
+6
-13
drivers/usb/core/file.c
drivers/usb/core/file.c
+4
-12
fs/char_dev.c
fs/char_dev.c
+4
-2
include/linux/fs.h
include/linux/fs.h
+11
-0
sound/core/sound.c
sound/core/sound.c
+6
-16
sound/sound_core.c
sound/sound_core.c
+3
-14
No files found.
drivers/char/misc.c
View file @
e84f9e57
...
@@ -114,7 +114,7 @@ static int misc_open(struct inode * inode, struct file * file)
...
@@ -114,7 +114,7 @@ static int misc_open(struct inode * inode, struct file * file)
int
minor
=
iminor
(
inode
);
int
minor
=
iminor
(
inode
);
struct
miscdevice
*
c
;
struct
miscdevice
*
c
;
int
err
=
-
ENODEV
;
int
err
=
-
ENODEV
;
const
struct
file_operations
*
old_fops
,
*
new_fops
=
NULL
;
const
struct
file_operations
*
new_fops
=
NULL
;
mutex_lock
(
&
misc_mtx
);
mutex_lock
(
&
misc_mtx
);
...
@@ -141,17 +141,11 @@ static int misc_open(struct inode * inode, struct file * file)
...
@@ -141,17 +141,11 @@ static int misc_open(struct inode * inode, struct file * file)
}
}
err
=
0
;
err
=
0
;
old_fops
=
file
->
f_op
;
replace_fops
(
file
,
new_fops
);
file
->
f_op
=
new_fops
;
if
(
file
->
f_op
->
open
)
{
if
(
file
->
f_op
->
open
)
{
file
->
private_data
=
c
;
file
->
private_data
=
c
;
err
=
file
->
f_op
->
open
(
inode
,
file
);
err
=
file
->
f_op
->
open
(
inode
,
file
);
if
(
err
)
{
fops_put
(
file
->
f_op
);
file
->
f_op
=
fops_get
(
old_fops
);
}
}
}
fops_put
(
old_fops
);
fail:
fail:
mutex_unlock
(
&
misc_mtx
);
mutex_unlock
(
&
misc_mtx
);
return
err
;
return
err
;
...
...
drivers/gpu/drm/drm_fops.c
View file @
e84f9e57
...
@@ -148,7 +148,7 @@ int drm_stub_open(struct inode *inode, struct file *filp)
...
@@ -148,7 +148,7 @@ int drm_stub_open(struct inode *inode, struct file *filp)
struct
drm_minor
*
minor
;
struct
drm_minor
*
minor
;
int
minor_id
=
iminor
(
inode
);
int
minor_id
=
iminor
(
inode
);
int
err
=
-
ENODEV
;
int
err
=
-
ENODEV
;
const
struct
file_operations
*
old
_fops
;
const
struct
file_operations
*
new
_fops
;
DRM_DEBUG
(
"
\n
"
);
DRM_DEBUG
(
"
\n
"
);
...
@@ -163,18 +163,13 @@ int drm_stub_open(struct inode *inode, struct file *filp)
...
@@ -163,18 +163,13 @@ int drm_stub_open(struct inode *inode, struct file *filp)
if
(
drm_device_is_unplugged
(
dev
))
if
(
drm_device_is_unplugged
(
dev
))
goto
out
;
goto
out
;
old_fops
=
filp
->
f_op
;
new_fops
=
fops_get
(
dev
->
driver
->
fops
);
filp
->
f_op
=
fops_get
(
dev
->
driver
->
fops
);
if
(
!
new_fops
)
if
(
filp
->
f_op
==
NULL
)
{
filp
->
f_op
=
old_fops
;
goto
out
;
goto
out
;
}
if
(
filp
->
f_op
->
open
&&
(
err
=
filp
->
f_op
->
open
(
inode
,
filp
)))
{
fops_put
(
filp
->
f_op
);
filp
->
f_op
=
fops_get
(
old_fops
);
}
fops_put
(
old_fops
);
replace_fops
(
filp
,
new_fops
);
if
(
filp
->
f_op
->
open
)
err
=
filp
->
f_op
->
open
(
inode
,
filp
);
out:
out:
mutex_unlock
(
&
drm_global_mutex
);
mutex_unlock
(
&
drm_global_mutex
);
return
err
;
return
err
;
...
...
drivers/media/dvb-core/dvbdev.c
View file @
e84f9e57
...
@@ -74,22 +74,15 @@ static int dvb_device_open(struct inode *inode, struct file *file)
...
@@ -74,22 +74,15 @@ static int dvb_device_open(struct inode *inode, struct file *file)
if
(
dvbdev
&&
dvbdev
->
fops
)
{
if
(
dvbdev
&&
dvbdev
->
fops
)
{
int
err
=
0
;
int
err
=
0
;
const
struct
file_operations
*
old
_fops
;
const
struct
file_operations
*
new
_fops
;
file
->
private_data
=
dvbdev
;
new_fops
=
fops_get
(
dvbdev
->
fops
);
old_fops
=
file
->
f_op
;
if
(
!
new_fops
)
file
->
f_op
=
fops_get
(
dvbdev
->
fops
);
if
(
file
->
f_op
==
NULL
)
{
file
->
f_op
=
old_fops
;
goto
fail
;
goto
fail
;
}
file
->
private_data
=
dvbdev
;
if
(
file
->
f_op
->
open
)
replace_fops
(
file
,
new_fops
);
if
(
file
->
f_op
->
open
)
err
=
file
->
f_op
->
open
(
inode
,
file
);
err
=
file
->
f_op
->
open
(
inode
,
file
);
if
(
err
)
{
fops_put
(
file
->
f_op
);
file
->
f_op
=
fops_get
(
old_fops
);
}
fops_put
(
old_fops
);
up_read
(
&
minor_rwsem
);
up_read
(
&
minor_rwsem
);
mutex_unlock
(
&
dvbdev_mutex
);
mutex_unlock
(
&
dvbdev_mutex
);
return
err
;
return
err
;
...
...
drivers/usb/core/file.c
View file @
e84f9e57
...
@@ -29,27 +29,19 @@ static DECLARE_RWSEM(minor_rwsem);
...
@@ -29,27 +29,19 @@ static DECLARE_RWSEM(minor_rwsem);
static
int
usb_open
(
struct
inode
*
inode
,
struct
file
*
file
)
static
int
usb_open
(
struct
inode
*
inode
,
struct
file
*
file
)
{
{
int
minor
=
iminor
(
inode
);
const
struct
file_operations
*
c
;
int
err
=
-
ENODEV
;
int
err
=
-
ENODEV
;
const
struct
file_operations
*
old_fops
,
*
new_fops
=
NULL
;
const
struct
file_operations
*
new_fops
;
down_read
(
&
minor_rwsem
);
down_read
(
&
minor_rwsem
);
c
=
usb_minors
[
minor
]
;
new_fops
=
fops_get
(
usb_minors
[
iminor
(
inode
)])
;
if
(
!
c
||
!
(
new_fops
=
fops_get
(
c
))
)
if
(
!
new_fops
)
goto
done
;
goto
done
;
old_fops
=
file
->
f_op
;
replace_fops
(
file
,
new_fops
);
file
->
f_op
=
new_fops
;
/* Curiouser and curiouser... NULL ->open() as "no device" ? */
/* Curiouser and curiouser... NULL ->open() as "no device" ? */
if
(
file
->
f_op
->
open
)
if
(
file
->
f_op
->
open
)
err
=
file
->
f_op
->
open
(
inode
,
file
);
err
=
file
->
f_op
->
open
(
inode
,
file
);
if
(
err
)
{
fops_put
(
file
->
f_op
);
file
->
f_op
=
fops_get
(
old_fops
);
}
fops_put
(
old_fops
);
done:
done:
up_read
(
&
minor_rwsem
);
up_read
(
&
minor_rwsem
);
return
err
;
return
err
;
...
...
fs/char_dev.c
View file @
e84f9e57
...
@@ -368,6 +368,7 @@ void cdev_put(struct cdev *p)
...
@@ -368,6 +368,7 @@ void cdev_put(struct cdev *p)
*/
*/
static
int
chrdev_open
(
struct
inode
*
inode
,
struct
file
*
filp
)
static
int
chrdev_open
(
struct
inode
*
inode
,
struct
file
*
filp
)
{
{
const
struct
file_operations
*
fops
;
struct
cdev
*
p
;
struct
cdev
*
p
;
struct
cdev
*
new
=
NULL
;
struct
cdev
*
new
=
NULL
;
int
ret
=
0
;
int
ret
=
0
;
...
@@ -400,10 +401,11 @@ static int chrdev_open(struct inode *inode, struct file *filp)
...
@@ -400,10 +401,11 @@ static int chrdev_open(struct inode *inode, struct file *filp)
return
ret
;
return
ret
;
ret
=
-
ENXIO
;
ret
=
-
ENXIO
;
f
ilp
->
f_op
=
fops_get
(
p
->
ops
);
f
ops
=
fops_get
(
p
->
ops
);
if
(
!
f
ilp
->
f_op
)
if
(
!
f
ops
)
goto
out_cdev_put
;
goto
out_cdev_put
;
replace_fops
(
filp
,
fops
);
if
(
filp
->
f_op
->
open
)
{
if
(
filp
->
f_op
->
open
)
{
ret
=
filp
->
f_op
->
open
(
inode
,
filp
);
ret
=
filp
->
f_op
->
open
(
inode
,
filp
);
if
(
ret
)
if
(
ret
)
...
...
include/linux/fs.h
View file @
e84f9e57
...
@@ -1875,6 +1875,17 @@ extern struct dentry *mount_pseudo(struct file_system_type *, char *,
...
@@ -1875,6 +1875,17 @@ extern struct dentry *mount_pseudo(struct file_system_type *, char *,
(((fops) && try_module_get((fops)->owner) ? (fops) : NULL))
(((fops) && try_module_get((fops)->owner) ? (fops) : NULL))
#define fops_put(fops) \
#define fops_put(fops) \
do { if (fops) module_put((fops)->owner); } while(0)
do { if (fops) module_put((fops)->owner); } while(0)
/*
* This one is to be used *ONLY* from ->open() instances.
* fops must be non-NULL, pinned down *and* module dependencies
* should be sufficient to pin the caller down as well.
*/
#define replace_fops(f, fops) \
do { \
struct file *__file = (f); \
fops_put(__file->f_op); \
BUG_ON(!(__file->f_op = (fops))); \
} while(0)
extern
int
register_filesystem
(
struct
file_system_type
*
);
extern
int
register_filesystem
(
struct
file_system_type
*
);
extern
int
unregister_filesystem
(
struct
file_system_type
*
);
extern
int
unregister_filesystem
(
struct
file_system_type
*
);
...
...
sound/core/sound.c
View file @
e84f9e57
...
@@ -153,7 +153,7 @@ static int snd_open(struct inode *inode, struct file *file)
...
@@ -153,7 +153,7 @@ static int snd_open(struct inode *inode, struct file *file)
{
{
unsigned
int
minor
=
iminor
(
inode
);
unsigned
int
minor
=
iminor
(
inode
);
struct
snd_minor
*
mptr
=
NULL
;
struct
snd_minor
*
mptr
=
NULL
;
const
struct
file_operations
*
old
_fops
;
const
struct
file_operations
*
new
_fops
;
int
err
=
0
;
int
err
=
0
;
if
(
minor
>=
ARRAY_SIZE
(
snd_minors
))
if
(
minor
>=
ARRAY_SIZE
(
snd_minors
))
...
@@ -167,24 +167,14 @@ static int snd_open(struct inode *inode, struct file *file)
...
@@ -167,24 +167,14 @@ static int snd_open(struct inode *inode, struct file *file)
return
-
ENODEV
;
return
-
ENODEV
;
}
}
}
}
old_fops
=
file
->
f_op
;
new_fops
=
fops_get
(
mptr
->
f_ops
);
file
->
f_op
=
fops_get
(
mptr
->
f_ops
);
if
(
file
->
f_op
==
NULL
)
{
file
->
f_op
=
old_fops
;
err
=
-
ENODEV
;
}
mutex_unlock
(
&
sound_mutex
);
mutex_unlock
(
&
sound_mutex
);
if
(
err
<
0
)
if
(
!
new_fops
)
return
err
;
return
-
ENODEV
;
replace_fops
(
file
,
new_fops
);
if
(
file
->
f_op
->
open
)
{
if
(
file
->
f_op
->
open
)
err
=
file
->
f_op
->
open
(
inode
,
file
);
err
=
file
->
f_op
->
open
(
inode
,
file
);
if
(
err
)
{
fops_put
(
file
->
f_op
);
file
->
f_op
=
fops_get
(
old_fops
);
}
}
fops_put
(
old_fops
);
return
err
;
return
err
;
}
}
...
...
sound/sound_core.c
View file @
e84f9e57
...
@@ -626,31 +626,20 @@ static int soundcore_open(struct inode *inode, struct file *file)
...
@@ -626,31 +626,20 @@ static int soundcore_open(struct inode *inode, struct file *file)
if
(
s
)
if
(
s
)
new_fops
=
fops_get
(
s
->
unit_fops
);
new_fops
=
fops_get
(
s
->
unit_fops
);
}
}
spin_unlock
(
&
sound_loader_lock
);
if
(
new_fops
)
{
if
(
new_fops
)
{
/*
/*
* We rely upon the fact that we can't be unloaded while the
* We rely upon the fact that we can't be unloaded while the
* subdriver is there, so if ->open() is successful we can
* subdriver is there.
* safely drop the reference counter and if it is not we can
* revert to old ->f_op. Ugly, indeed, but that's the cost of
* switching ->f_op in the first place.
*/
*/
int
err
=
0
;
int
err
=
0
;
const
struct
file_operations
*
old_fops
=
file
->
f_op
;
replace_fops
(
file
,
new_fops
);
file
->
f_op
=
new_fops
;
spin_unlock
(
&
sound_loader_lock
);
if
(
file
->
f_op
->
open
)
if
(
file
->
f_op
->
open
)
err
=
file
->
f_op
->
open
(
inode
,
file
);
err
=
file
->
f_op
->
open
(
inode
,
file
);
if
(
err
)
{
fops_put
(
file
->
f_op
);
file
->
f_op
=
fops_get
(
old_fops
);
}
fops_put
(
old_fops
);
return
err
;
return
err
;
}
}
spin_unlock
(
&
sound_loader_lock
);
return
-
ENODEV
;
return
-
ENODEV
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment