From patchwork Sun Sep 1 10:19:15 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Azat Khuzhin X-Patchwork-Id: 2852485 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 441E99F313 for ; Sun, 1 Sep 2013 10:20:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 444A4202DB for ; Sun, 1 Sep 2013 10:20:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3DC3820276 for ; Sun, 1 Sep 2013 10:20:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753477Ab3IAKUV (ORCPT ); Sun, 1 Sep 2013 06:20:21 -0400 Received: from mail-la0-f54.google.com ([209.85.215.54]:52503 "EHLO mail-la0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751905Ab3IAKUU (ORCPT ); Sun, 1 Sep 2013 06:20:20 -0400 Received: by mail-la0-f54.google.com with SMTP id ea20so2719455lab.41 for ; Sun, 01 Sep 2013 03:20:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=R53GLlpDt0MFtnwqWGNN7x1OnfzYIBdREQg2Fxyx7oc=; b=kSTZzecceB86xwRVw1Hbm4X/6qiUEFPOjAeg+kTE+ijm6GKncBoqAsuhofFga/GOH0 yf3+3bU3r5Y77n5s6VyF4OuAjQirVNmkPCzFDMuVfCKvSSLMBN3MgscHEmU38dWP95lv mwQ1AmlkAU8neRRsR2soHhihPWs0y92Um5xgkQFMZO/n9gL6K36T6yhgsllzyhPFNtxY 0ca5wb1KHi1LtcgBk0cVf3DE6AKsk3W3iiqq5mMq/9J7EyXU2ze5nWPTWumfWbhvVImH 7YPShWonLk8xOUuGXKodTSiBEXL7AT3WOwd33SDNL/qpPElBQzz62GRhtF3LiAll7Yfq IH/w== X-Received: by 10.112.168.170 with SMTP id zx10mr15859854lbb.0.1378030818557; Sun, 01 Sep 2013 03:20:18 -0700 (PDT) Received: from localhost ([188.134.22.24]) by mx.google.com with ESMTPSA id jo6sm418189lbc.14.1969.12.31.16.00.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sun, 01 Sep 2013 03:20:17 -0700 (PDT) From: Azat Khuzhin To: linux-btrfs@vger.kernel.org Cc: jbacik@fusionio.com, miaox@cn.fujitsu.com, Azat Khuzhin , Chris Mason , linux-kernel@vger.kernel.org (open list) Subject: [PATCH] btrfs: use list_for_each_entry_safe() when delete items Date: Sun, 1 Sep 2013 14:19:15 +0400 Message-Id: <1378030756-22166-1-git-send-email-a3at.mail@gmail.com> X-Mailer: git-send-email 1.7.10.4 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-9.2 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham 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 Replace list_for_each_entry() by list_for_each_entry_safe() in __btrfs_close_devices() list_for_each_entry() { list_replace_rcu(); call_rcu(); <-- We may free the device, if we get next device by the current one, the page fault may happen. } Signed-off-by: Azat Khuzhin Reviewed-by: Miao Xie --- V2: Add some comments from Miao into commit message fs/btrfs/volumes.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 78b8717..1d1b595 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -616,13 +616,13 @@ static void free_device(struct rcu_head *head) static int __btrfs_close_devices(struct btrfs_fs_devices *fs_devices) { - struct btrfs_device *device; + struct btrfs_device *device, *next; if (--fs_devices->opened > 0) return 0; mutex_lock(&fs_devices->device_list_mutex); - list_for_each_entry(device, &fs_devices->devices, dev_list) { + list_for_each_entry_safe(device, next, &fs_devices->devices, dev_list) { struct btrfs_device *new_device; struct rcu_string *name;