linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] locks: fix file_lock deletion inside loop
@ 2015-03-27  2:34 Yan, Zheng
  2015-03-27 11:14 ` Jeff Layton
  0 siblings, 1 reply; 2+ messages in thread
From: Yan, Zheng @ 2015-03-27  2:34 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: viro, jeff.layton, Yan, Zheng

locks_delete_lock_ctx() is called inside the loop, so we
should use list_for_each_entry_safe.

Signed-off-by: Yan, Zheng <zyan@redhat.com>
---
 fs/locks.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/fs/locks.c b/fs/locks.c
index 528fedf..40bc384 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -1388,9 +1388,8 @@ any_leases_conflict(struct inode *inode, struct file_lock *breaker)
 int __break_lease(struct inode *inode, unsigned int mode, unsigned int type)
 {
 	int error = 0;
-	struct file_lock *new_fl;
 	struct file_lock_context *ctx = inode->i_flctx;
-	struct file_lock *fl;
+	struct file_lock *new_fl, *fl, *tmp;
 	unsigned long break_time;
 	int want_write = (mode & O_ACCMODE) != O_RDONLY;
 	LIST_HEAD(dispose);
@@ -1420,7 +1419,7 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type)
 			break_time++;	/* so that 0 means no break time */
 	}
 
-	list_for_each_entry(fl, &ctx->flc_lease, fl_list) {
+	list_for_each_entry_safe(fl, tmp, &ctx->flc_lease, fl_list) {
 		if (!leases_conflict(fl, new_fl))
 			continue;
 		if (want_write) {
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] locks: fix file_lock deletion inside loop
  2015-03-27  2:34 [PATCH] locks: fix file_lock deletion inside loop Yan, Zheng
@ 2015-03-27 11:14 ` Jeff Layton
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff Layton @ 2015-03-27 11:14 UTC (permalink / raw)
  To: Yan, Zheng; +Cc: linux-fsdevel, viro

On Fri, 27 Mar 2015 10:34:20 +0800
"Yan, Zheng" <zyan@redhat.com> wrote:

> locks_delete_lock_ctx() is called inside the loop, so we
> should use list_for_each_entry_safe.
> 
> Signed-off-by: Yan, Zheng <zyan@redhat.com>
> ---
>  fs/locks.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/locks.c b/fs/locks.c
> index 528fedf..40bc384 100644
> --- a/fs/locks.c
> +++ b/fs/locks.c
> @@ -1388,9 +1388,8 @@ any_leases_conflict(struct inode *inode, struct file_lock *breaker)
>  int __break_lease(struct inode *inode, unsigned int mode, unsigned int type)
>  {
>  	int error = 0;
> -	struct file_lock *new_fl;
>  	struct file_lock_context *ctx = inode->i_flctx;
> -	struct file_lock *fl;
> +	struct file_lock *new_fl, *fl, *tmp;
>  	unsigned long break_time;
>  	int want_write = (mode & O_ACCMODE) != O_RDONLY;
>  	LIST_HEAD(dispose);
> @@ -1420,7 +1419,7 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type)
>  			break_time++;	/* so that 0 means no break time */
>  	}
>  
> -	list_for_each_entry(fl, &ctx->flc_lease, fl_list) {
> +	list_for_each_entry_safe(fl, tmp, &ctx->flc_lease, fl_list) {
>  		if (!leases_conflict(fl, new_fl))
>  			continue;
>  		if (want_write) {

Well spotted. I'll plan to merge this, give it a bit of testing and send
on to Linus next week sometime.

Thanks,
-- 
Jeff Layton <jeff.layton@primarydata.com>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-03-27 11:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-27  2:34 [PATCH] locks: fix file_lock deletion inside loop Yan, Zheng
2015-03-27 11:14 ` Jeff Layton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).