Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
raspberrypi-kernel
提交
05c0ae21
R
raspberrypi-kernel
项目概览
openeuler
/
raspberrypi-kernel
通知
13
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
raspberrypi-kernel
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
05c0ae21
编写于
4月 04, 2013
作者:
A
Al Viro
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
try a saner locking for pde_opener...
Signed-off-by:
N
Al Viro
<
viro@zeniv.linux.org.uk
>
上级
ca469f35
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
24 addition
and
44 deletion
+24
-44
fs/proc/inode.c
fs/proc/inode.c
+21
-41
fs/proc/internal.h
fs/proc/internal.h
+2
-2
include/linux/proc_fs.h
include/linux/proc_fs.h
+1
-1
未找到文件。
fs/proc/inode.c
浏览文件 @
05c0ae21
...
...
@@ -133,67 +133,48 @@ enum {BIAS = -1U<<31};
static
inline
int
use_pde
(
struct
proc_dir_entry
*
pde
)
{
int
res
=
1
;
spin_lock
(
&
pde
->
pde_unload_lock
);
if
(
unlikely
(
pde
->
pde_users
<
0
))
res
=
0
;
else
pde
->
pde_users
++
;
spin_unlock
(
&
pde
->
pde_unload_lock
);
return
res
;
}
static
void
__pde_users_dec
(
struct
proc_dir_entry
*
pde
)
{
if
(
--
pde
->
pde_users
==
BIAS
)
complete
(
pde
->
pde_unload_completion
);
return
atomic_inc_unless_negative
(
&
pde
->
in_use
);
}
static
void
unuse_pde
(
struct
proc_dir_entry
*
pde
)
{
spin_lock
(
&
pde
->
pde_unload_lock
);
__pde_users_dec
(
pde
);
spin_unlock
(
&
pde
->
pde_unload_lock
);
if
(
atomic_dec_return
(
&
pde
->
in_use
)
==
BIAS
)
complete
(
pde
->
pde_unload_completion
);
}
/* pde is locked */
static
void
close_pdeo
(
struct
proc_dir_entry
*
pde
,
struct
pde_opener
*
pdeo
)
{
pdeo
->
count
++
;
if
(
!
mutex_trylock
(
&
pdeo
->
mutex
))
{
if
(
pdeo
->
closing
)
{
/* somebody else is doing that, just wait */
DECLARE_COMPLETION_ONSTACK
(
c
);
pdeo
->
c
=
&
c
;
spin_unlock
(
&
pde
->
pde_unload_lock
);
mutex_lock
(
&
pdeo
->
mutex
);
wait_for_completion
(
&
c
);
spin_lock
(
&
pde
->
pde_unload_lock
);
WARN_ON
(
!
list_empty
(
&
pdeo
->
lh
));
}
else
{
struct
file
*
file
;
pdeo
->
closing
=
1
;
spin_unlock
(
&
pde
->
pde_unload_lock
);
file
=
pdeo
->
file
;
pde
->
proc_fops
->
release
(
file_inode
(
file
),
file
);
spin_lock
(
&
pde
->
pde_unload_lock
);
list_del_init
(
&
pdeo
->
lh
);
}
mutex_unlock
(
&
pdeo
->
mutex
);
if
(
!--
pdeo
->
count
)
if
(
pdeo
->
c
)
complete
(
pdeo
->
c
);
kfree
(
pdeo
);
}
}
void
proc_entry_rundown
(
struct
proc_dir_entry
*
de
)
{
spin_lock
(
&
de
->
pde_unload_lock
);
de
->
pde_users
+=
BIAS
;
DECLARE_COMPLETION_ONSTACK
(
c
);
/* Wait until all existing callers into module are done. */
if
(
de
->
pde_users
!=
BIAS
)
{
DECLARE_COMPLETION_ONSTACK
(
c
);
de
->
pde_unload_completion
=
&
c
;
spin_unlock
(
&
de
->
pde_unload_lock
);
wait_for_completion
(
de
->
pde_unload_completion
);
spin_lock
(
&
de
->
pde_unload_lock
);
}
de
->
pde_unload_completion
=
&
c
;
if
(
atomic_add_return
(
BIAS
,
&
de
->
in_use
)
!=
BIAS
)
wait_for_completion
(
&
c
);
spin_lock
(
&
de
->
pde_unload_lock
);
while
(
!
list_empty
(
&
de
->
pde_openers
))
{
struct
pde_opener
*
pdeo
;
pdeo
=
list_first_entry
(
&
de
->
pde_openers
,
struct
pde_opener
,
lh
);
...
...
@@ -356,7 +337,7 @@ static int proc_reg_open(struct inode *inode, struct file *file)
* by hand in remove_proc_entry(). For this, save opener's credentials
* for later.
*/
pdeo
=
k
m
alloc
(
sizeof
(
struct
pde_opener
),
GFP_KERNEL
);
pdeo
=
k
z
alloc
(
sizeof
(
struct
pde_opener
),
GFP_KERNEL
);
if
(
!
pdeo
)
return
-
ENOMEM
;
...
...
@@ -370,18 +351,17 @@ static int proc_reg_open(struct inode *inode, struct file *file)
if
(
open
)
rv
=
open
(
inode
,
file
);
spin_lock
(
&
pde
->
pde_unload_lock
);
if
(
rv
==
0
&&
release
)
{
/* To know what to release. */
mutex_init
(
&
pdeo
->
mutex
);
pdeo
->
count
=
0
;
pdeo
->
file
=
file
;
/* Strictly for "too late" ->release in proc_reg_release(). */
spin_lock
(
&
pde
->
pde_unload_lock
);
list_add
(
&
pdeo
->
lh
,
&
pde
->
pde_openers
);
spin_unlock
(
&
pde
->
pde_unload_lock
);
}
else
kfree
(
pdeo
);
__pde_users_dec
(
pde
);
spin_unlock
(
&
pde
->
pde_unload_lock
);
unuse_pde
(
pde
);
return
rv
;
}
...
...
fs/proc/internal.h
浏览文件 @
05c0ae21
...
...
@@ -153,8 +153,8 @@ int proc_readdir_de(struct proc_dir_entry *de, struct file *filp, void *dirent,
struct
pde_opener
{
struct
file
*
file
;
struct
list_head
lh
;
int
c
ount
;
/* number of threads in close_pdeo() */
struct
mutex
mutex
;
int
c
losing
;
struct
completion
*
c
;
};
ssize_t
__proc_file_read
(
struct
file
*
,
char
__user
*
,
size_t
,
loff_t
*
);
...
...
include/linux/proc_fs.h
浏览文件 @
05c0ae21
...
...
@@ -65,7 +65,7 @@ struct proc_dir_entry {
void
*
data
;
read_proc_t
*
read_proc
;
atomic_t
count
;
/* use count */
int
pde_users
;
/* number of callers into module in progress; */
atomic_t
in_use
;
/* number of callers into module in progress; */
/* negative -> it's going away RSN */
struct
completion
*
pde_unload_completion
;
struct
list_head
pde_openers
;
/* who did ->open, but not ->release */
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录