From patchwork Fri Mar 27 02:34:20 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yan, Zheng" X-Patchwork-Id: 6103181 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 0448EBF90F for ; Fri, 27 Mar 2015 02:34:36 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 368D12042A for ; Fri, 27 Mar 2015 02:34:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 41ADF203E5 for ; Fri, 27 Mar 2015 02:34:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752270AbbC0Cec (ORCPT ); Thu, 26 Mar 2015 22:34:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33421 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752138AbbC0Cec (ORCPT ); Thu, 26 Mar 2015 22:34:32 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 2E634AC7CE; Fri, 27 Mar 2015 02:34:32 +0000 (UTC) Received: from localhost.localdomain (vpn1-5-217.pek2.redhat.com [10.72.5.217]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t2R2YSHF025096; Thu, 26 Mar 2015 22:34:29 -0400 From: "Yan, Zheng" To: linux-fsdevel@vger.kernel.org Cc: viro@zeniv.linux.org.uk, jeff.layton@primarydata.com, "Yan, Zheng" Subject: [PATCH] locks: fix file_lock deletion inside loop Date: Fri, 27 Mar 2015 10:34:20 +0800 Message-Id: <1427423660-6635-1-git-send-email-zyan@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP locks_delete_lock_ctx() is called inside the loop, so we should use list_for_each_entry_safe. Signed-off-by: Yan, Zheng --- 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) {