From patchwork Tue Aug 1 20:09:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 9875425 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C44C36041F for ; Tue, 1 Aug 2017 20:09:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B878D2872E for ; Tue, 1 Aug 2017 20:09:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AD53B28744; Tue, 1 Aug 2017 20:09:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE2AF2872E for ; Tue, 1 Aug 2017 20:09:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752136AbdHAUJe (ORCPT ); Tue, 1 Aug 2017 16:09:34 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:29424 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752016AbdHAUJe (ORCPT ); Tue, 1 Aug 2017 16:09:34 -0400 Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v71K9SOR026076 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 1 Aug 2017 20:09:29 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id v71K9R0m029131 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 1 Aug 2017 20:09:27 GMT Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id v71K9Q11002304; Tue, 1 Aug 2017 20:09:27 GMT Received: from mwanda (/197.254.35.146) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 01 Aug 2017 13:09:25 -0700 Date: Tue, 1 Aug 2017 23:09:17 +0300 From: Dan Carpenter To: "Nicholas A. Bellinger" , Xiubo Li Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH] tcmu: Oops in unmap_thread_fn() Message-ID: <20170801200917.brigs5x47eujfx7a@mwanda> MIME-Version: 1.0 Content-Disposition: inline X-Mailer: git-send-email haha only kidding User-Agent: NeoMutt/20170609 (1.8.3) X-Source-IP: userv0021.oracle.com [156.151.31.71] Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Calling list_del() on the iterator pointer in list_for_each_entry() will cause an oops. We need to user the _safe() version for that. Fixes: c73d02f63c16 ("tcmu: Add fifo type waiter list support to avoid starvation") Signed-off-by: Dan Carpenter Reviewed-by: Mike Christie diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c index 9258b7dd2c30..fd9fcea68d23 100644 --- a/drivers/target/target_core_user.c +++ b/drivers/target/target_core_user.c @@ -1985,7 +1985,7 @@ static struct target_backend_ops tcmu_ops = { static int unmap_thread_fn(void *data) { - struct tcmu_dev *udev; + struct tcmu_dev *udev, *tmp; loff_t off; uint32_t start, end, block; static uint32_t free_blocks; @@ -2056,7 +2056,7 @@ static int unmap_thread_fn(void *data) * for the global data pool blocks. */ mutex_lock(&root_udev_waiter_mutex); - list_for_each_entry(udev, &root_udev_waiter, waiter) { + list_for_each_entry_safe(udev, tmp, &root_udev_waiter, waiter) { mutex_lock(&udev->cmdr_lock); if (udev->waiting_blocks < free_blocks) { mutex_unlock(&udev->cmdr_lock);