Skip to contentSkip to conversation

locks: fix file_lock deletion inside loop

PATCH In review Yan, Zheng 2 participants 2 messages Mar 27, 2015

Subsystems (2)
lore
Share & tools
lore

Yan, Zheng

author
#0 lore raw

PATCH 1/1 locks: fix file_lock deletion inside loop

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

---
 fs/locks.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
fs/locks.c +2 -3
index 528fedf..40bc384 100644
@@ -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) {
Signature · 1 line
1.9.3
#1 lore raw
Quoted 24 lines · Zheng

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

---
 fs/locks.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
fs/locks.c +1 -2
index 528fedf..40bc384 100644
@@ -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);

fs/locks.c int __break_lease(struct inode *inode, unsigned int mode, unsigned int type) · line 1425

Quoted 8 lines
fs/locks.c +1 -1
@@ -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,

Signature · 1 line
Jeff Layton <[email protected]>