From patchwork Sun Jun 13 11:30:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhihao Cheng X-Patchwork-Id: 1491428 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=hyyQWtNQ; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G2sfq1S7cz9sWk for ; Sun, 13 Jun 2021 21:24:19 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=CjcmgqNfAHd0DSxuDd8JQwS6r7D8D7gCZmpv9M28VMk=; b=hyyQWtNQURP2ul 3GlEjhFsRwftg7xv64at+49ytQkkW3B36U2/+hiwtDNfGQlFeJ6asXSc7+OBx86NbQFePlhL2Wn47 yTwmAxshpgDFtZFt+4eCPDiAqOfjwW9Sdc0xIpSvT15D1HEaPXLFCAhXp6QZCQq3S1+TLhNipZyik u+ySoUBnHYzS5TjxU/oD01/O/uWSKGnOlpAurCJUSrjKhDJLS+YxM2q5sezg4PgohKtoWrJaPSkpo 4CtlcOgSRJ/PM0+fGhL+p86n+bXMqWB6OSrtwdm1gVNG9OH/H7Q7/qPExB9odQcRr7dnZgWsZL2dT BZncHb2ILY0yh9wlGEAQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lsODR-00AIsp-Dm; Sun, 13 Jun 2021 11:23:45 +0000 Received: from szxga02-in.huawei.com ([45.249.212.188]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lsOC1-00AIS8-9Y for linux-mtd@lists.infradead.org; Sun, 13 Jun 2021 11:22:20 +0000 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4G2sXn1GGbz6yD1; Sun, 13 Jun 2021 19:19:05 +0800 (CST) Received: from dggema761-chm.china.huawei.com (10.1.198.203) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2176.2; Sun, 13 Jun 2021 19:22:12 +0800 Received: from huawei.com (10.175.127.227) by dggema761-chm.china.huawei.com (10.1.198.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Sun, 13 Jun 2021 19:22:11 +0800 From: Zhihao Cheng To: , , CC: , , , Subject: [PATCH 1/6] Revert "mtd: blkdevs: fix potential deadlock + lockdep warnings" Date: Sun, 13 Jun 2021 19:30:30 +0800 Message-ID: <20210613113035.2329421-2-chengzhihao1@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210613113035.2329421-1-chengzhihao1@huawei.com> References: <20210613113035.2329421-1-chengzhihao1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggema761-chm.china.huawei.com (10.1.198.203) X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210613_042217_634001_067C17E9 X-CRM114-Status: UNSURE ( 7.82 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -2.3 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: This reverts commit f3c63795e90f0c6238306883b6c72f14d5355721. --- drivers/mtd/mtd_blkdevs.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c index fb8e12d590a1..16ccce3e7fdb 100644 --- a/drivers/mtd/mtd_blkdevs.c +++ b/drivers/mtd/mtd_blkdevs.c @@ -209,8 +209,8 @@ static in [...] Content analysis details: (-2.3 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [45.249.212.188 listed in list.dnswl.org] 0.0 RCVD_IN_MSPIKE_H4 RBL: Very Good reputation (+4) [45.249.212.188 listed in wl.mailspike.net] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This reverts commit f3c63795e90f0c6238306883b6c72f14d5355721. --- drivers/mtd/mtd_blkdevs.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c index fb8e12d590a1..16ccce3e7fdb 100644 --- a/drivers/mtd/mtd_blkdevs.c +++ b/drivers/mtd/mtd_blkdevs.c @@ -209,8 +209,8 @@ static int blktrans_open(struct block_device *bdev, fmode_t mode) if (!dev) return -ERESTARTSYS; /* FIXME: busy loop! -arnd*/ - mutex_lock(&mtd_table_mutex); mutex_lock(&dev->lock); + mutex_lock(&mtd_table_mutex); if (dev->open) goto unlock; @@ -234,8 +234,8 @@ static int blktrans_open(struct block_device *bdev, fmode_t mode) unlock: dev->open++; - mutex_unlock(&dev->lock); mutex_unlock(&mtd_table_mutex); + mutex_unlock(&dev->lock); blktrans_dev_put(dev); return ret; @@ -245,8 +245,8 @@ static int blktrans_open(struct block_device *bdev, fmode_t mode) error_put: module_put(dev->tr->owner); kref_put(&dev->ref, blktrans_dev_release); - mutex_unlock(&dev->lock); mutex_unlock(&mtd_table_mutex); + mutex_unlock(&dev->lock); blktrans_dev_put(dev); return ret; } @@ -258,8 +258,8 @@ static void blktrans_release(struct gendisk *disk, fmode_t mode) if (!dev) return; - mutex_lock(&mtd_table_mutex); mutex_lock(&dev->lock); + mutex_lock(&mtd_table_mutex); if (--dev->open) goto unlock; @@ -273,8 +273,8 @@ static void blktrans_release(struct gendisk *disk, fmode_t mode) __put_mtd_device(dev->mtd); } unlock: - mutex_unlock(&dev->lock); mutex_unlock(&mtd_table_mutex); + mutex_unlock(&dev->lock); blktrans_dev_put(dev); } From patchwork Sun Jun 13 11:30:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhihao Cheng X-Patchwork-Id: 1491427 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=xeE/x8II; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G2sfJ1nDJz9sWk for ; Sun, 13 Jun 2021 21:23:52 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=UK5EUjI4yipQ1fCTU9n8augTymjgY+6ctXdOKzmkhRk=; b=xeE/x8II6wgzkr 1oZ2DfLEF4NS7iBIadrC7wXBlPy1iByFivHbFIhYDVeoCQFV/++nv6a38CH39O4riFUqcj4B3USTL nFlHGV2jtxAZ4CQz3dTgnPZB+zstSgGhfctx4rTP0QBMl1JJS8hlOBb+5Sq1A9NK8EJtpdhRWAFRf 7B3t4roERyN54EvRjJxu9Eks3JETTft/jxGSfxQT7PzXsRh3ohVAu/07BNXKIhPC/5LsXWjCVpXG4 u2In//4VF+fEpdPyWdYQ+kSS13aJHvYxTNyRhUxuOH2RGwzQ8PBjIWKLnIKvwDYh/1UmE7aBkW+Iv TNOp+GyPa6COAIMpOhxw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lsOD2-00AIkB-9G; Sun, 13 Jun 2021 11:23:20 +0000 Received: from szxga01-in.huawei.com ([45.249.212.187]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lsOC1-00AIS5-9W for linux-mtd@lists.infradead.org; Sun, 13 Jun 2021 11:22:20 +0000 Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4G2sVg2wSrzXfLW; Sun, 13 Jun 2021 19:17:15 +0800 (CST) Received: from dggema761-chm.china.huawei.com (10.1.198.203) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2176.2; Sun, 13 Jun 2021 19:22:12 +0800 Received: from huawei.com (10.175.127.227) by dggema761-chm.china.huawei.com (10.1.198.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Sun, 13 Jun 2021 19:22:12 +0800 From: Zhihao Cheng To: , , CC: , , , Subject: [PATCH 2/6] Revert "mtd: fix: avoid race condition when accessing mtd->usecount" Date: Sun, 13 Jun 2021 19:30:31 +0800 Message-ID: <20210613113035.2329421-3-chengzhihao1@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210613113035.2329421-1-chengzhihao1@huawei.com> References: <20210613113035.2329421-1-chengzhihao1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggema761-chm.china.huawei.com (10.1.198.203) X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210613_042217_623133_CAA1007C X-CRM114-Status: UNSURE ( 6.55 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -2.3 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: This reverts commit 073db4a51ee43ccb827f54a4261c0583b028d5ab. --- drivers/mtd/mtd_blkdevs.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c index 16ccce3e7fdb..00b13f71ccf3 100644 --- a/drivers/mtd/mtd_blkdevs.c +++ b/drivers/mtd/mtd_blkdevs.c @@ -210,7 +210,6 @@ static in [...] Content analysis details: (-2.3 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [45.249.212.187 listed in list.dnswl.org] 0.0 RCVD_IN_MSPIKE_H4 RBL: Very Good reputation (+4) [45.249.212.187 listed in wl.mailspike.net] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This reverts commit 073db4a51ee43ccb827f54a4261c0583b028d5ab. --- drivers/mtd/mtd_blkdevs.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c index 16ccce3e7fdb..00b13f71ccf3 100644 --- a/drivers/mtd/mtd_blkdevs.c +++ b/drivers/mtd/mtd_blkdevs.c @@ -210,7 +210,6 @@ static int blktrans_open(struct block_device *bdev, fmode_t mode) return -ERESTARTSYS; /* FIXME: busy loop! -arnd*/ mutex_lock(&dev->lock); - mutex_lock(&mtd_table_mutex); if (dev->open) goto unlock; @@ -234,7 +233,6 @@ static int blktrans_open(struct block_device *bdev, fmode_t mode) unlock: dev->open++; - mutex_unlock(&mtd_table_mutex); mutex_unlock(&dev->lock); blktrans_dev_put(dev); return ret; @@ -245,7 +243,6 @@ static int blktrans_open(struct block_device *bdev, fmode_t mode) error_put: module_put(dev->tr->owner); kref_put(&dev->ref, blktrans_dev_release); - mutex_unlock(&mtd_table_mutex); mutex_unlock(&dev->lock); blktrans_dev_put(dev); return ret; @@ -259,7 +256,6 @@ static void blktrans_release(struct gendisk *disk, fmode_t mode) return; mutex_lock(&dev->lock); - mutex_lock(&mtd_table_mutex); if (--dev->open) goto unlock; @@ -273,7 +269,6 @@ static void blktrans_release(struct gendisk *disk, fmode_t mode) __put_mtd_device(dev->mtd); } unlock: - mutex_unlock(&mtd_table_mutex); mutex_unlock(&dev->lock); blktrans_dev_put(dev); } From patchwork Sun Jun 13 11:30:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhihao Cheng X-Patchwork-Id: 1491424 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=UYpUhuwJ; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G2sdP3J6cz9sRN for ; Sun, 13 Jun 2021 21:23:05 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=wh2gHZhZ5ENQmw38/rPKBaMdTVF2t91PPCnNgNvwf1A=; b=UYpUhuwJ8HBrnu HAVqfOZ4EWM6luVRh3v8BAsPziPXFUJadj1lh9w5TbAq8FCeIhiJsn5sJLSXX+WlLnHaXJIOvtkNt PN+gUPIxPl8Xn6ZChhJ22G+eo2ojSdLm3Dw4n5qN7pUDrxZwHBdd10DSNP3+K7IVRpuT6qVS28VTv KeUBJXv5DHgts5SzIzsrK4Uf8PiVtFrCus3FQsFOtTQ/6D8q0tiIusM/nfWp4k3v5VtiwsZqfri8U q6KCN0P+Fm+whqQ717yGO0+fNWDosVPhFFd3gF0AA2RtWU3koFvXZD1wSCGHnJk0YSVYPBvPCPbh9 CUFaeHaS9GxW+BBZNgVQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lsOCF-00AIWQ-8R; Sun, 13 Jun 2021 11:22:31 +0000 Received: from szxga01-in.huawei.com ([45.249.212.187]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lsOC1-00AIS6-9T for linux-mtd@lists.infradead.org; Sun, 13 Jun 2021 11:22:19 +0000 Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4G2sVg5vjlzXfLX; Sun, 13 Jun 2021 19:17:15 +0800 (CST) Received: from dggema761-chm.china.huawei.com (10.1.198.203) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2176.2; Sun, 13 Jun 2021 19:22:13 +0800 Received: from huawei.com (10.175.127.227) by dggema761-chm.china.huawei.com (10.1.198.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Sun, 13 Jun 2021 19:22:12 +0800 From: Zhihao Cheng To: , , CC: , , , Subject: [PATCH 3/6] Revert "mtd: mtd_blkdevs: don't increase 'open' count on error path" Date: Sun, 13 Jun 2021 19:30:32 +0800 Message-ID: <20210613113035.2329421-4-chengzhihao1@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210613113035.2329421-1-chengzhihao1@huawei.com> References: <20210613113035.2329421-1-chengzhihao1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggema761-chm.china.huawei.com (10.1.198.203) X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210613_042217_556737_08C9B159 X-CRM114-Status: UNSURE ( 7.92 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -2.3 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: This reverts commit 342ff28f5a2e5aa3236617bd2bddf6c749677ef2. --- drivers/mtd/mtd_blkdevs.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c index 00b13f71ccf3..100a3c96760c 100644 --- a/drivers/mtd/mtd_blkdevs.c +++ b/drivers/mtd/mtd_blkdevs.c @@ -211,7 +211,7 @@ static in [...] Content analysis details: (-2.3 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [45.249.212.187 listed in list.dnswl.org] 0.0 RCVD_IN_MSPIKE_H4 RBL: Very Good reputation (+4) [45.249.212.187 listed in wl.mailspike.net] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This reverts commit 342ff28f5a2e5aa3236617bd2bddf6c749677ef2. --- drivers/mtd/mtd_blkdevs.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c index 00b13f71ccf3..100a3c96760c 100644 --- a/drivers/mtd/mtd_blkdevs.c +++ b/drivers/mtd/mtd_blkdevs.c @@ -211,7 +211,7 @@ static int blktrans_open(struct block_device *bdev, fmode_t mode) mutex_lock(&dev->lock); - if (dev->open) + if (dev->open++) goto unlock; kref_get(&dev->ref); @@ -232,7 +232,6 @@ static int blktrans_open(struct block_device *bdev, fmode_t mode) dev->file_mode = mode; unlock: - dev->open++; mutex_unlock(&dev->lock); blktrans_dev_put(dev); return ret; From patchwork Sun Jun 13 11:30:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhihao Cheng X-Patchwork-Id: 1491425 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=vRDidwXR; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G2sdj6rNyz9sRN for ; Sun, 13 Jun 2021 21:23:21 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=YJZRu3W2LnitsXWKnYIEwC8uyM/HNslN8QINbbqvdMk=; b=vRDidwXRAVcP2V eWOlNLXZsCmjZagwjWAOOw/4Kb5KACLkIX32hVe2AhlfT0y5N8PmZO56JjrbpXn9PXPQSxSxXG6eA HOkwn/AAn4KTtdWV1HLx50CiBa9Kouuii1BSpUcxG62DORm/kTii/ZatMIBszUVaZtzAXKpfPHSPM RrFjJi2rcwdU30JbAafkTHEmry7CuY8THYdIgqzaFOLLUMLuoslJNB6BJSxbhK+9sdFJEiBqsDI8Q UADE+EIJNklk4ZpZNcqhowmpnspJyuPrc4fH6ZfouvDtP54r18lVNdzIy8xsBkkBGzdFntbF738dt eZ/o94/FRUx5KYA48iNA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lsOCT-00AIaV-Fc; Sun, 13 Jun 2021 11:22:45 +0000 Received: from szxga08-in.huawei.com ([45.249.212.255]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lsOC1-00AIS4-8P for linux-mtd@lists.infradead.org; Sun, 13 Jun 2021 11:22:19 +0000 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.55]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4G2sVh3GsKz1BLsp; Sun, 13 Jun 2021 19:17:16 +0800 (CST) Received: from dggema761-chm.china.huawei.com (10.1.198.203) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2176.2; Sun, 13 Jun 2021 19:22:13 +0800 Received: from huawei.com (10.175.127.227) by dggema761-chm.china.huawei.com (10.1.198.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Sun, 13 Jun 2021 19:22:13 +0800 From: Zhihao Cheng To: , , CC: , , , Subject: [PATCH 4/6] Revert "mtd: mtd_blkdevs: fix error path in blktrans_open" Date: Sun, 13 Jun 2021 19:30:33 +0800 Message-ID: <20210613113035.2329421-5-chengzhihao1@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210613113035.2329421-1-chengzhihao1@huawei.com> References: <20210613113035.2329421-1-chengzhihao1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggema761-chm.china.huawei.com (10.1.198.203) X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210613_042217_536756_8BCF46E8 X-CRM114-Status: UNSURE ( 7.92 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -2.3 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: This reverts commit 94735ec4044a6d318b83ad3c5794e931ed168d10. --- drivers/mtd/mtd_blkdevs.c | 23 +++ 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c index 100a3c96760c..41dd3b955136 100644 --- a/drivers/mtd/mtd_blkdevs.c +++ b/drivers/mtd/mtd_blkdevs.c @@ -217,34 +217,17 @@ static [...] Content analysis details: (-2.3 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [45.249.212.255 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This reverts commit 94735ec4044a6d318b83ad3c5794e931ed168d10. --- drivers/mtd/mtd_blkdevs.c | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c index 100a3c96760c..41dd3b955136 100644 --- a/drivers/mtd/mtd_blkdevs.c +++ b/drivers/mtd/mtd_blkdevs.c @@ -217,34 +217,17 @@ static int blktrans_open(struct block_device *bdev, fmode_t mode) kref_get(&dev->ref); __module_get(dev->tr->owner); - if (!dev->mtd) - goto unlock; - - if (dev->tr->open) { - ret = dev->tr->open(dev); - if (ret) - goto error_put; + if (dev->mtd) { + ret = dev->tr->open ? dev->tr->open(dev) : 0; + __get_mtd_device(dev->mtd); } - ret = __get_mtd_device(dev->mtd); - if (ret) - goto error_release; dev->file_mode = mode; unlock: mutex_unlock(&dev->lock); blktrans_dev_put(dev); return ret; - -error_release: - if (dev->tr->release) - dev->tr->release(dev); -error_put: - module_put(dev->tr->owner); - kref_put(&dev->ref, blktrans_dev_release); - mutex_unlock(&dev->lock); - blktrans_dev_put(dev); - return ret; } static void blktrans_release(struct gendisk *disk, fmode_t mode) From patchwork Sun Jun 13 11:30:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhihao Cheng X-Patchwork-Id: 1491426 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=lD1tfVE3; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G2sdz0B7wz9sWk for ; Sun, 13 Jun 2021 21:23:35 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=FZLUn4By5pzGb2nYK6rDfc+tBf8dT3ACEJteBBEuupA=; b=lD1tfVE3d7kDE8 YF/KxDKswjX9dtTTWRe4W+eIeEG/sfqnE1RwOHkEs36XAqGdp1ahSoBvtX/IXvxUWxdgZ019K1mN3 HBKbKk6NBxEP9leLV7gFf1hxRjpTTtjsHKbTMofjJi91WLtCovxkSI89BjQiAwkpDGcXHObJV07Br RWd4vV2ZEsaBelPezxNglcZM9RzBgdYAc4mLH5qoSVDY/HGEvqhF9P+bKqJNH3IZM92erOhKxr/Mg FQcrVug6OIyFvP+DekePFSBRw073CO/e8hwrD4UQVYeZAGsIJVrLV+4oPgb3kwLQ+r4XSEz1KgC35 222plOTYewlpgxbFwLjA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lsOCj-00AIdv-3z; Sun, 13 Jun 2021 11:23:01 +0000 Received: from szxga01-in.huawei.com ([45.249.212.187]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lsOC1-00AIS7-9V for linux-mtd@lists.infradead.org; Sun, 13 Jun 2021 11:22:20 +0000 Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4G2sY50jW8zZcxP; Sun, 13 Jun 2021 19:19:21 +0800 (CST) Received: from dggema761-chm.china.huawei.com (10.1.198.203) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2176.2; Sun, 13 Jun 2021 19:22:14 +0800 Received: from huawei.com (10.175.127.227) by dggema761-chm.china.huawei.com (10.1.198.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Sun, 13 Jun 2021 19:22:13 +0800 From: Zhihao Cheng To: , , CC: , , , Subject: [PATCH 5/6] Revert "mtd: Remove redundant mutex from mtd_blkdevs.c" Date: Sun, 13 Jun 2021 19:30:34 +0800 Message-ID: <20210613113035.2329421-6-chengzhihao1@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210613113035.2329421-1-chengzhihao1@huawei.com> References: <20210613113035.2329421-1-chengzhihao1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggema761-chm.china.huawei.com (10.1.198.203) X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210613_042217_610252_8DE22763 X-CRM114-Status: UNSURE ( 7.34 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -2.3 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: This reverts commit 8cc9de3ebdf654601db51a516267dff89c49acc3. Signed-off-by: Zhihao Cheng --- drivers/mtd/mtd_blkdevs.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c index 41dd3b955136..e8a77f10ae24 100644 --- a/drivers/mtd/mtd_blkdevs.c +++ b/drivers/mtd/mtd_blkdevs.c @@ -22,6 +22,7 @@ Content analysis details: (-2.3 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [45.249.212.187 listed in list.dnswl.org] 0.0 RCVD_IN_MSPIKE_H4 RBL: Very Good reputation (+4) [45.249.212.187 listed in wl.mailspike.net] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This reverts commit 8cc9de3ebdf654601db51a516267dff89c49acc3. Signed-off-by: Zhihao Cheng --- drivers/mtd/mtd_blkdevs.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c index 41dd3b955136..e8a77f10ae24 100644 --- a/drivers/mtd/mtd_blkdevs.c +++ b/drivers/mtd/mtd_blkdevs.c @@ -22,6 +22,7 @@ #include "mtdcore.h" +static DEFINE_MUTEX(mtd_blkdevs_mutex); static LIST_HEAD(blktrans_majors); static DEFINE_MUTEX(blktrans_ref_mutex); @@ -209,6 +210,7 @@ static int blktrans_open(struct block_device *bdev, fmode_t mode) if (!dev) return -ERESTARTSYS; /* FIXME: busy loop! -arnd*/ + mutex_lock(&mtd_blkdevs_mutex); mutex_lock(&dev->lock); if (dev->open++) @@ -227,6 +229,7 @@ static int blktrans_open(struct block_device *bdev, fmode_t mode) unlock: mutex_unlock(&dev->lock); blktrans_dev_put(dev); + mutex_unlock(&mtd_blkdevs_mutex); return ret; } @@ -237,6 +240,7 @@ static void blktrans_release(struct gendisk *disk, fmode_t mode) if (!dev) return; + mutex_lock(&mtd_blkdevs_mutex); mutex_lock(&dev->lock); if (--dev->open) @@ -253,6 +257,7 @@ static void blktrans_release(struct gendisk *disk, fmode_t mode) unlock: mutex_unlock(&dev->lock); blktrans_dev_put(dev); + mutex_unlock(&mtd_blkdevs_mutex); } static int blktrans_getgeo(struct block_device *bdev, struct hd_geometry *geo) From patchwork Sun Jun 13 11:30:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhihao Cheng X-Patchwork-Id: 1491429 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=Jg8SOno2; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G2sgQ1zjVz9sWk for ; Sun, 13 Jun 2021 21:24:50 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=mg4R78vsaZuVHPBP8bf/mHTrVK+xOLXO5Nv/AO+B3OQ=; b=Jg8SOno2raMaXc Lgdh+ixyEZL5jLG0JQFhcL2z7N4fAUfHAeuLbfc1UmbLxGaUFJBS2iyR6D/DYteMFLe25tXuzgjnA 0yaUfh+FTXk79tGtPbRnJ3Il9j8NMHhoNgHkIVS8JAHr3PtmwHp59uvnm+e3VkZGUy7PrsWiHKeTh +SQj57QxaU1Z5uwslQZvoLoYS9udPZIo7H7X9LC54VO6wlDQeW9/0RJrcDrtsiRTxzrWgVWTN51/R /bh/hiDOjVOw3t2fIq/poEJFKiovpqMSYlISZGI+JQF/CZTk5SCEiEylnreKwJooZSdHJf5x/UjZr yheRpMYBmgT9UADIQ0ng==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lsODx-00AJ3M-5N; Sun, 13 Jun 2021 11:24:17 +0000 Received: from szxga02-in.huawei.com ([45.249.212.188]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lsOC1-00AIS9-9X for linux-mtd@lists.infradead.org; Sun, 13 Jun 2021 11:22:20 +0000 Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4G2sXq2Yn0z6wKG; Sun, 13 Jun 2021 19:19:07 +0800 (CST) Received: from dggema761-chm.china.huawei.com (10.1.198.203) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2176.2; Sun, 13 Jun 2021 19:22:14 +0800 Received: from huawei.com (10.175.127.227) by dggema761-chm.china.huawei.com (10.1.198.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Sun, 13 Jun 2021 19:22:13 +0800 From: Zhihao Cheng To: , , CC: , , , Subject: [PATCH 6/6] Revert "mtd: allow to unload the mtdtrans module if its block devices aren't open" Date: Sun, 13 Jun 2021 19:30:35 +0800 Message-ID: <20210613113035.2329421-7-chengzhihao1@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210613113035.2329421-1-chengzhihao1@huawei.com> References: <20210613113035.2329421-1-chengzhihao1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggema761-chm.china.huawei.com (10.1.198.203) X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210613_042217_747909_CD8AC3CB X-CRM114-Status: GOOD ( 15.04 ) X-Spam-Score: -2.3 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: This reverts commit 008c751ec78587dd9b48bb62d4b10d616554fea2. Signed-off-by: Zhihao Cheng --- drivers/mtd/mtd_blkdevs.c | 49 ++++++++++++++++++++ 1 file changed, 25 insertions(+), 24 deletions(-) Content analysis details: (-2.3 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [45.249.212.188 listed in list.dnswl.org] 0.0 RCVD_IN_MSPIKE_H4 RBL: Very Good reputation (+4) [45.249.212.188 listed in wl.mailspike.net] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This reverts commit 008c751ec78587dd9b48bb62d4b10d616554fea2. Signed-off-by: Zhihao Cheng --- drivers/mtd/mtd_blkdevs.c | 49 ++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c index e8a77f10ae24..4d386617fd8a 100644 --- a/drivers/mtd/mtd_blkdevs.c +++ b/drivers/mtd/mtd_blkdevs.c @@ -205,7 +205,7 @@ static blk_status_t mtd_queue_rq(struct blk_mq_hw_ctx *hctx, static int blktrans_open(struct block_device *bdev, fmode_t mode) { struct mtd_blktrans_dev *dev = blktrans_dev_get(bdev->bd_disk); - int ret = 0; + int ret; if (!dev) return -ERESTARTSYS; /* FIXME: busy loop! -arnd*/ @@ -213,17 +213,17 @@ static int blktrans_open(struct block_device *bdev, fmode_t mode) mutex_lock(&mtd_blkdevs_mutex); mutex_lock(&dev->lock); - if (dev->open++) + if (!dev->mtd) { + ret = -ENXIO; goto unlock; - - kref_get(&dev->ref); - __module_get(dev->tr->owner); - - if (dev->mtd) { - ret = dev->tr->open ? dev->tr->open(dev) : 0; - __get_mtd_device(dev->mtd); } + ret = !dev->open++ && dev->tr->open ? dev->tr->open(dev) : 0; + /* Take another reference on the device so it won't go away till + * last release */ + if (!ret) + kref_get(&dev->ref); + dev->file_mode = mode; unlock: @@ -243,17 +243,14 @@ static void blktrans_release(struct gendisk *disk, fmode_t mode) mutex_lock(&mtd_blkdevs_mutex); mutex_lock(&dev->lock); - if (--dev->open) - goto unlock; - + /* Release one reference, we sure its not the last one here*/ kref_put(&dev->ref, blktrans_dev_release); - module_put(dev->tr->owner); - if (dev->mtd) { - if (dev->tr->release) - dev->tr->release(dev); - __put_mtd_device(dev->mtd); - } + if (!dev->mtd) + goto unlock; + + if (!--dev->open && dev->tr->release) + dev->tr->release(dev); unlock: mutex_unlock(&dev->lock); blktrans_dev_put(dev); @@ -408,6 +405,9 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new) gd->queue = new->rq; + __get_mtd_device(new->mtd); + __module_get(tr->owner); + if (new->readonly) set_disk_ro(gd, 1); @@ -456,15 +456,16 @@ int del_mtd_blktrans_dev(struct mtd_blktrans_dev *old) blk_mq_unquiesce_queue(old->rq); blk_mq_unfreeze_queue(old->rq); - /* If the device is currently open, tell trans driver to close it, - then put mtd device, and don't touch it again */ + /* Ask trans driver for release to the mtd device */ mutex_lock(&old->lock); - if (old->open) { - if (old->tr->release) - old->tr->release(old); - __put_mtd_device(old->mtd); + if (old->open && old->tr->release) { + old->tr->release(old); + old->open = 0; } + __put_mtd_device(old->mtd); + module_put(old->tr->owner); + /* At that point, we don't touch the mtd anymore */ old->mtd = NULL; mutex_unlock(&old->lock);