From patchwork Mon Aug 23 07:33:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 1519558 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=DY3cywqM; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=casper.20170209 header.b=gCMffEP/; 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 4GtPDc0jTTz9sWS for ; Mon, 23 Aug 2021 17:36:00 +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=+DNifQI25+4KkNVVbg6xWujOK4G0u5n6hx3GcCi6zpk=; b=DY3cywqMP1PFGZ LU4M/2KwClnHxpdQUxRwZIqUj7MyP6WJrL4s38po+bQlzz3B+sWdizDAJERfIbv7BjO2KbRhVQB6U AtGthCfym8pQdMOG+sTjW82ZyAuS6RL3Zt+YagoMAjRx4Jm0wjSj25va9Pp5f5arRTAsf+hFVGLIl xf8+bfwvACusMC/YLwTxxpXfBgfSW1dGmUS8USjXNu2B4VfsJTcIXrwBv1dUZFuEy2clUUR3TQau9 BCrJNUZnkMQvi2gvke03S6gPj8YeBVM46QX5c9s2CCOVoKrtMR3yU/KLf/TnI0bw08gRkTpbQzvXP jRbvXrS3rZBhilZbWmQw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mI4UJ-00FkUN-5N; Mon, 23 Aug 2021 07:35:19 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mI4UH-00FkU1-Vx for linux-mtd@bombadil.infradead.org; Mon, 23 Aug 2021 07:35:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=2tzDZdLpuKXA+ygmvE34pMzvWGlwygVPE/R2irJ5MLo=; b=gCMffEP/BRk0dEPPUyj9UlH+Wf 5Nq9MqYwTnSYo/2I+R9/DGMjkbKkOLdIG8gv4XPhkUF42EECGOuK8MFUXaRR313l3h7djJnnvK3Ci eqpLnj8Bek91XVnL0De+G5LdcvZosu0XMwEXvImqkKPMCsR+1DtPOKb4fppfwCyN2rNxQNMijVH4E mTrm3189THKoG8n63sBXkAGFabQIXxa6vRgF2XP7o1aDdx9fhTRpZdWV3Zr1ufvrKhelXsFsLHw8C qJR5Yo0iOqa4ZhxRPAGMVbf0Yg1u48OiISuDE3t8BGlnYXre0RlDkLarjEdDLui0e23pMChUo/YBw n3WLEexw==; Received: from [2001:4bb8:193:fd10:c6e8:3c08:6f8b:cbf0] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mI4Tc-009QhA-1K; Mon, 23 Aug 2021 07:34:45 +0000 From: Christoph Hellwig To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra Cc: Guenter Roeck , linux-mtd@lists.infradead.org Subject: [PATCH 1/8] mtd_blkdevs: don't hold del_mtd_blktrans_dev in blktrans_{open, release} Date: Mon, 23 Aug 2021 09:33:52 +0200 Message-Id: <20210823073359.705281-2-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210823073359.705281-1-hch@lst.de> References: <20210823073359.705281-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html 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 There is nothing that this protects against except for slightly reducing the window when new opens can appear just before calling del_gendisk. Reported-by: Guenter Roeck Signed-off-by: Christoph Hellwig Tested-by: Guenter Roeck --- 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 44bea3f65060..6b81a1c9ccbe 100644 --- a/drivers/mtd/mtd_blkdevs.c +++ b/drivers/mtd/mtd_blkdevs.c @@ -207,7 +207,6 @@ 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); if (dev->open) @@ -233,7 +232,6 @@ static int blktrans_open(struct block_device *bdev, fmode_t mode) unlock: dev->open++; mutex_unlock(&dev->lock); - mutex_unlock(&mtd_table_mutex); blktrans_dev_put(dev); return ret; @@ -244,7 +242,6 @@ static int blktrans_open(struct block_device *bdev, fmode_t mode) module_put(dev->tr->owner); kref_put(&dev->ref, blktrans_dev_release); mutex_unlock(&dev->lock); - mutex_unlock(&mtd_table_mutex); blktrans_dev_put(dev); return ret; } @@ -256,7 +253,6 @@ static void blktrans_release(struct gendisk *disk, fmode_t mode) if (!dev) return; - mutex_lock(&mtd_table_mutex); mutex_lock(&dev->lock); if (--dev->open) @@ -272,7 +268,6 @@ static void blktrans_release(struct gendisk *disk, fmode_t mode) } unlock: mutex_unlock(&dev->lock); - mutex_unlock(&mtd_table_mutex); blktrans_dev_put(dev); } From patchwork Mon Aug 23 07:33:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 1519559 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=d6yuODs7; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=casper.20170209 header.b=khgBdt3e; 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 4GtPFr553Vz9sWS for ; Mon, 23 Aug 2021 17:37:04 +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=w89YGrcX7byjL0ih7W3ouxH+9o9R6Pe3aRXWgkyhcyw=; b=d6yuODs7wXCI0i BLd4nfW9o4mfYxht31uMVVZaHvdj45Agnzhd5EXZqVOyyFGirRd5hIEWCCEqSWyu/TirvRSMHb53G o4mtxhYrhgjXEu66KsZyzKoCzy2pbP2sQGpwY4h7ssj7Z/iK7a7nZrzBzaVUjsyisBA5ajGnHJNzT pFDwfpMOg7FysYGgLF+yKWLPXbAjaPm3MkPTszWImch5b9wEgcJXFBpsiTfX0+ZklrIPKfKBjxA5s MdUfDfSnkeNqXkCKc4rWpV02G15GLJ7xkOW/jhKn7yrLHsONl8HzawxFC1MJ0euWMvRQX47I+6sng aLnB+Ry/fvrOK9Sx8V6Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mI4VQ-00FkmA-13; Mon, 23 Aug 2021 07:36:28 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mI4VN-00FklJ-MO for linux-mtd@bombadil.infradead.org; Mon, 23 Aug 2021 07:36:25 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=b9Uclk6xpoiqnKRmUY/NkslucqoYr3q7peRqvLgdZC0=; b=khgBdt3e+C/I60lCMW3e21PVF8 ZcxCbOobT2+edSAS9yR0ytdZJXhig5OPGRrqV6BIzcYbWLdMTX+k52DCorgSVlc8KddifcrOKPPFQ cBkEh0HFu0Sl3fANZFx4zDbKKuY8CKDjmJU0mRqnOSz+Bcdts/8UnknoOKLjo1PjCEME8eDmHWD0D aNP3+ygMzfok/UtMrsr2Fva56da06KSC94M6f04v8/OlNN35308o2E47c2w00FFNfbNg176t+IYe1 NkmbUsNomYkCPVv+DictHDhmUZYZ/VAPgniEbhIrC8FrasZ2vAyNHY58DLv/gJCrHFKF1ttEo5/q/ z9NA8QbA==; Received: from [2001:4bb8:193:fd10:c6e8:3c08:6f8b:cbf0] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mI4UH-009QjV-Sk; Mon, 23 Aug 2021 07:35:48 +0000 From: Christoph Hellwig To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra Cc: Guenter Roeck , linux-mtd@lists.infradead.org Subject: [PATCH 2/8] mtd_blkdevs: use lockdep_assert_held Date: Mon, 23 Aug 2021 09:33:53 +0200 Message-Id: <20210823073359.705281-3-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210823073359.705281-1-hch@lst.de> References: <20210823073359.705281-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html 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 Use lockdep_assert_held to ensure mtd_table_mutex is held instead of mutex_trylock games. Signed-off-by: Christoph Hellwig --- drivers/mtd/mtd_blkdevs.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c index 6b81a1c9ccbe..81f0ce2a0b5a 100644 --- a/drivers/mtd/mtd_blkdevs.c +++ b/drivers/mtd/mtd_blkdevs.c @@ -310,10 +310,7 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new) struct gendisk *gd; int ret; - if (mutex_trylock(&mtd_table_mutex)) { - mutex_unlock(&mtd_table_mutex); - BUG(); - } + lockdep_assert_held(&mtd_table_mutex); mutex_lock(&blktrans_ref_mutex); list_for_each_entry(d, &tr->devs, list) { @@ -444,10 +441,7 @@ int del_mtd_blktrans_dev(struct mtd_blktrans_dev *old) { unsigned long flags; - if (mutex_trylock(&mtd_table_mutex)) { - mutex_unlock(&mtd_table_mutex); - BUG(); - } + lockdep_assert_held(&mtd_table_mutex); if (old->disk_attributes) sysfs_remove_group(&disk_to_dev(old->disk)->kobj, From patchwork Mon Aug 23 07:33:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 1519560 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=b4fxfBN7; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=casper.20170209 header.b=qw2zPFDK; 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 4GtPGb0BVZz9sWS for ; Mon, 23 Aug 2021 17:37:42 +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=BMVrwZL9msFH8dXLUhjgIteQqqNNaG/6SmjGnEZozUQ=; b=b4fxfBN7jtoTsq ZV5p+HVQ1iG1jyfFttr3D0V4rRNYvmkIIwbLss5/thJfiNaVbYdxxNQpnq71oGdBE9zX14tuQNMcb 48TsPh+tgOsHiBVW9b54L+tvEZzdYfTiXCOa9uLYR9xxhUJUx9sfqGhegpFSYyH++SxLB1IfxgsH1 FFf5e5CBfGRWAtm30eEw48dQuJQ8oj++rwyOcRPMA3tMFHpUk4/Cl5wv31FgOB4vb89WXKhZDEq54 P6xwGKjLTYK/Ve+I4PT6XFEOR9bXZIdy+ebiMZF0uU85/El14dF1937B0aNb/47kt/Rda+MokKoHl hfSGhdY+GMZWPWTWm4jg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mI4Vz-00Fkv0-Ki; Mon, 23 Aug 2021 07:37:03 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mI4Vx-00FkuB-SG for linux-mtd@bombadil.infradead.org; Mon, 23 Aug 2021 07:37:01 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=yDVJqb52UG/kPc/O2lDZLqU6iuRuPPYbXt2KymxHM48=; b=qw2zPFDKzIICgXNI4UeGsND53I r9pL6KIRnBJQNuoCZC7jMThBsfp9Ist8xuRIPNGqtp9zRjSkbyte/Xuk0250mYEwvWF9h1a5GYn5b SoIuTcXLbS4LWyD9kNm9SBRHh0Y3Yq7HIhRmZbMpzn07CAsKDrnZ6I7yzt087Js5dYyG5mKFsvcsg HIQ+tXh+iJxu5jXPl9q35/qrBtgyTe3GB1oLhah0nToNH1MO6eKq63BAF8PWQQfOGvTQHbVtOeRn2 +U5r98UBctg75X9A17bbRRNuSj1KKeDp5jKEDDxqyyCkEAcctGiFTUjzoGzFqX6mNt2jmGIEe1L4r BbfeXXIQ==; Received: from [2001:4bb8:193:fd10:c6e8:3c08:6f8b:cbf0] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mI4VN-009Qm5-72; Mon, 23 Aug 2021 07:36:41 +0000 From: Christoph Hellwig To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra Cc: Guenter Roeck , linux-mtd@lists.infradead.org Subject: [PATCH 3/8] mtd/ftl: don't cast away the type when calling add_mtd_blktrans_dev Date: Mon, 23 Aug 2021 09:33:54 +0200 Message-Id: <20210823073359.705281-4-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210823073359.705281-1-hch@lst.de> References: <20210823073359.705281-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html 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 Pass the actual mtd_blktrans_dev instead of casting the containing structure to void *. Signed-off-by: Christoph Hellwig --- drivers/mtd/ftl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mtd/ftl.c b/drivers/mtd/ftl.c index 9b33c082179d..f655d2905270 100644 --- a/drivers/mtd/ftl.c +++ b/drivers/mtd/ftl.c @@ -1029,7 +1029,7 @@ static void ftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd) partition->mbd.tr = tr; partition->mbd.devnum = -1; - if (!add_mtd_blktrans_dev((void *)partition)) + if (!add_mtd_blktrans_dev(&partition->mbd)) return; } From patchwork Mon Aug 23 07:33:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 1519561 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=i7/VxEfS; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=casper.20170209 header.b=f26IJTI1; 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 4GtPH90B4wz9sWS for ; Mon, 23 Aug 2021 17:38:13 +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=baudEJMK0BXEbHDtRqCNAZqNIAiEE+XIPSLgFDr43Qk=; b=i7/VxEfSSSkm4R VtUYTMwJzRePCDpcmq+IWVyKKAWUzYGSnPmDsSKrti4CscT5QvMcNdAzV5QG8czt7J/JN0hKDOFwl MDCwf/Nkn8VR5V3MRJi2FNoZ90M8ZPP76VMWEnrPd3ENoKRmpb/yEn/4Lls7cO0V9PpRa+1Vv/v3o qsQClypDFQevgIUPbP1lr4bWXHc4GKeV3wWua34xWIxMlgPxSTTgkylMSJ8wRP7BcyGDInHtPNuyH +ts074iX+S05OfvISTEbqMoNhz9BQ87bmgZSziML4J0CuDLtnpxYCv0LWaZ9Genkw/kCKBMQGt7Hm mgtlat9QZk5KgBooqc4Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mI4WU-00Fl53-Hb; Mon, 23 Aug 2021 07:37:34 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mI4WT-00Fl4N-Ct for linux-mtd@bombadil.infradead.org; Mon, 23 Aug 2021 07:37:33 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=d8ougPyR10neolLj0oF8pa2cwhasqlbLsL7gbTrUUE0=; b=f26IJTI1nQaR8jlZLlUqDTyvms UfuJR83srDKJX7MR1n3sd2pXx2lQRb/Fbn1lNuPYPv3Z4vQnWJV3Asc/seDka1OABMFPxksDeNSFt HRXXlPexqr+T6srnLAAMRsuD/y2zQKuM6pzW9cu5jKFOgOVZbJa8ZMltBxA/s1AFUkJ0fNEigNVdP rfDKqhbYh1BPvkSoRZoMxdqiLfioo8fuHEva3WT23WmKIFxcGIFWfpzqv/s5l/lCLdsXhl97QU2vS GP4N/wpOAN2ygGzNLRIgwbAewaAh2T0tT1uFbtkCaWi2Idc9Z0t+DLSutNWF51VEu65N2RalCXOAL gVOy/zzw==; Received: from [2001:4bb8:193:fd10:c6e8:3c08:6f8b:cbf0] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mI4Vx-009Qpl-NA; Mon, 23 Aug 2021 07:37:11 +0000 From: Christoph Hellwig To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra Cc: Guenter Roeck , linux-mtd@lists.infradead.org Subject: [PATCH 4/8] mtd/rfd_ftl: don't cast away the type when calling add_mtd_blktrans_dev Date: Mon, 23 Aug 2021 09:33:55 +0200 Message-Id: <20210823073359.705281-5-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210823073359.705281-1-hch@lst.de> References: <20210823073359.705281-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html 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 Pass the actual mtd_blktrans_dev instead of casting the containing structure to void *. Signed-off-by: Christoph Hellwig --- drivers/mtd/rfd_ftl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mtd/rfd_ftl.c b/drivers/mtd/rfd_ftl.c index 6e0d5ce9b010..6cf9356d3567 100644 --- a/drivers/mtd/rfd_ftl.c +++ b/drivers/mtd/rfd_ftl.c @@ -754,7 +754,7 @@ static void rfd_ftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd) printk(KERN_INFO PREFIX "name: '%s' type: %d flags %x\n", mtd->name, mtd->type, mtd->flags); - if (!add_mtd_blktrans_dev((void*)part)) + if (!add_mtd_blktrans_dev(&part->mbd)) return; } out: From patchwork Mon Aug 23 07:33:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 1519566 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=xED+mx5L; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=casper.20170209 header.b=p+9hu4m/; 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 4GtPHq47qSz9sWS for ; Mon, 23 Aug 2021 17:38:47 +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=4MhQwrZIM+i1ULKKOi8dPmrowyBs0n9xJOi52602XBs=; b=xED+mx5LCqeZnq L8q3NPrC/Z0Ve8OreFp1EBW08vTtLe6Bx7zE+MKruihzgdyUCxh3kT+Xs28W79LGvJQH36Cie81tx rqEGXjsnFibSBwz8p6kruKVHcR41QATK1U48VHTbqYbA6OHZwug59NdDI3SUAWM22txZS2DJzQJXW WK7wjTsUAkLaxQBhTvBCn4UQcTmveDlIHnC5j3WvWWf/VfwBrbckiLoLt3iLo5sfPgjYT6H6NONQL UXv4jaOOkp4F43zSZfumnHgyXBPXmm/f7M0DDHkK4J1hk/bVZzbGHDZ6tEN8jrntTKF+zd1mrX5oA NjQZIAkhcNNmp0YLvMSQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mI4X2-00FlGL-90; Mon, 23 Aug 2021 07:38:08 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mI4X0-00FlF7-Ag for linux-mtd@bombadil.infradead.org; Mon, 23 Aug 2021 07:38:06 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=yd1fP43x95zGCQR2SB7HQ/+6WrBHniI28nlCdjF+Hh0=; b=p+9hu4m/irFAS2rPiD+rwi1Vlt sKT2qkmJ+DEhTCdMWt82BrIypbbfNlFKm+uIM2zAx8KvQc8mQ9U5L9n6cu8FSADZISCgXFtKDCpki ei+G1dfrC3iLUsuqy/B1pKrSXMtO0nQ7UpjqM/MaSTH4XiMIRvWpm1ThJalRnF8ir+382964+tRDu BtrLdsmV8B+lcW3nOHHpTpAW/o7CqC2knA2IM8ADHs6H6NHTq5F/58hn5+8pLE2g9vok/8OEy04rg bgvA1NU1TEHwcJAYtKriPeXf+2Xvw7KaZ0AR/eOVKAgpDYlUwoZm6acP+I+AIZxsysvN4+6SRvr7M Ny/J9HdA==; Received: from [2001:4bb8:193:fd10:c6e8:3c08:6f8b:cbf0] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mI4WT-009Qr2-5D; Mon, 23 Aug 2021 07:37:42 +0000 From: Christoph Hellwig To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra Cc: Guenter Roeck , linux-mtd@lists.infradead.org Subject: [PATCH 5/8] mtd_blkdevs: simplify blktrans_dev_get Date: Mon, 23 Aug 2021 09:33:56 +0200 Message-Id: <20210823073359.705281-6-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210823073359.705281-1-hch@lst.de> References: <20210823073359.705281-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html 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 ->private_data is set before the disk is added and never cleared, so don't bother trying to handle a NULL pointer there. Signed-off-by: Christoph Hellwig --- drivers/mtd/mtd_blkdevs.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c index 81f0ce2a0b5a..f5e13b919614 100644 --- a/drivers/mtd/mtd_blkdevs.c +++ b/drivers/mtd/mtd_blkdevs.c @@ -39,16 +39,12 @@ static void blktrans_dev_release(struct kref *kref) static struct mtd_blktrans_dev *blktrans_dev_get(struct gendisk *disk) { - struct mtd_blktrans_dev *dev; + struct mtd_blktrans_dev *dev = disk->private_data; mutex_lock(&blktrans_ref_mutex); - dev = disk->private_data; - - if (!dev) - goto unlock; kref_get(&dev->ref); -unlock: mutex_unlock(&blktrans_ref_mutex); + return dev; } @@ -204,9 +200,6 @@ 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; - if (!dev) - return -ERESTARTSYS; /* FIXME: busy loop! -arnd*/ - mutex_lock(&dev->lock); if (dev->open) @@ -250,9 +243,6 @@ static void blktrans_release(struct gendisk *disk, fmode_t mode) { struct mtd_blktrans_dev *dev = blktrans_dev_get(disk); - if (!dev) - return; - mutex_lock(&dev->lock); if (--dev->open) @@ -276,9 +266,6 @@ static int blktrans_getgeo(struct block_device *bdev, struct hd_geometry *geo) struct mtd_blktrans_dev *dev = blktrans_dev_get(bdev->bd_disk); int ret = -ENXIO; - if (!dev) - return ret; - mutex_lock(&dev->lock); if (!dev->mtd) From patchwork Mon Aug 23 07:33:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 1519571 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=U/aMpNMd; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=casper.20170209 header.b=nagscX5z; 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 4GtPJy0qQ0z9sWS for ; Mon, 23 Aug 2021 17:39:46 +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=oo2fWhvUjVw5PuD/ET1cum5nQGm4QhbuqH5p+MUuzp8=; b=U/aMpNMdsUxHdY KEpEw6RAOawvMkjvTvEI2Csa0sP9q9ri8SdSfgivLD1LmJ14lEX1NX+9OdgF4S50HuvWqUIuV7Zcs il54126OTH2imqWZQiVuFPTr+TPUya0uvrw1T4ocTLf07jHFwOyOP6FNWy7NmHYFtOy7JiInPxu+q 5vtBMsze05TTIbR/oTQoHAeQls0Ni58V5efLOOwP289/YzYGesWRn4YuWqqrthk396/G4hyCD2X7y kdxmLv1XnKkh9X/wSf2LpVulVsV1oW1LwOxUfTI1NeuDiS1jqZqx/SQY7cEuPIXQ/ALQZwPvKttVU HpSIVGRjmwc4psQgGY6A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mI4Xx-00FldA-Ts; Mon, 23 Aug 2021 07:39:06 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mI4Xw-00FlcT-PH for linux-mtd@bombadil.infradead.org; Mon, 23 Aug 2021 07:39:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=Rv7dq3PUX/Wod9/odynZeofhwYjWg3dzwGlAC8IVmSU=; b=nagscX5z7wfrwRMMcCbRyEClwn Ma2k3yXNHjWz9UX4rFYotc1XfhO7Egyb7qpIor/YsjPjRKMB4QSroUDPkfvmUIC20Yj96983bzrVj 3VPodgqJiKW0t1wzvhLPW2ONv5GiX4bQX2Up/BAW649Orr0yvoCLlHJsV9ZqQVT5UEzyhbxFcy0Xu hdnjQt8hvu2pU6++FpUl19nozgfgIrS9T0Gd/ItJZqkgocEj5RJV9jshyfKb0s2brX6PxkbdwPuHB 6jQaMl0zIAugVu7PR2OIC008UkxB5kxFSZyp9OA4/2sM4SqP08yxR3Y1xmpi3jArxE18I9ApwJIE8 uJxwIlGA==; Received: from [2001:4bb8:193:fd10:c6e8:3c08:6f8b:cbf0] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mI4X0-009Qs0-Et; Mon, 23 Aug 2021 07:38:18 +0000 From: Christoph Hellwig To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra Cc: Guenter Roeck , linux-mtd@lists.infradead.org Subject: [PATCH 6/8] mtd_blkdevs: remove blktrans_ref_mutex Date: Mon, 23 Aug 2021 09:33:57 +0200 Message-Id: <20210823073359.705281-7-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210823073359.705281-1-hch@lst.de> References: <20210823073359.705281-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html 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 blktrans_ref_mutex is not actually needed. The kref is serialized internally, and devnum assignment in add_mtd_blktrans_dev happens before the disk is added and thus any of the block_device_operations methods otherwise using it are called. It is also already serialized by the global mtd_table_mutex. Signed-off-by: Christoph Hellwig --- drivers/mtd/mtd_blkdevs.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c index f5e13b919614..6f226b7cbb5c 100644 --- a/drivers/mtd/mtd_blkdevs.c +++ b/drivers/mtd/mtd_blkdevs.c @@ -23,7 +23,6 @@ #include "mtdcore.h" static LIST_HEAD(blktrans_majors); -static DEFINE_MUTEX(blktrans_ref_mutex); static void blktrans_dev_release(struct kref *kref) { @@ -41,18 +40,13 @@ static struct mtd_blktrans_dev *blktrans_dev_get(struct gendisk *disk) { struct mtd_blktrans_dev *dev = disk->private_data; - mutex_lock(&blktrans_ref_mutex); kref_get(&dev->ref); - mutex_unlock(&blktrans_ref_mutex); - return dev; } static void blktrans_dev_put(struct mtd_blktrans_dev *dev) { - mutex_lock(&blktrans_ref_mutex); kref_put(&dev->ref, blktrans_dev_release); - mutex_unlock(&blktrans_ref_mutex); } @@ -299,7 +293,6 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new) lockdep_assert_held(&mtd_table_mutex); - mutex_lock(&blktrans_ref_mutex); list_for_each_entry(d, &tr->devs, list) { if (new->devnum == -1) { /* Use first free number */ @@ -311,7 +304,6 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new) } } else if (d->devnum == new->devnum) { /* Required number taken */ - mutex_unlock(&blktrans_ref_mutex); return -EBUSY; } else if (d->devnum > new->devnum) { /* Required number was free */ @@ -329,14 +321,11 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new) * minor numbers and that the disk naming code below can cope * with this number. */ if (new->devnum > (MINORMASK >> tr->part_bits) || - (tr->part_bits && new->devnum >= 27 * 26)) { - mutex_unlock(&blktrans_ref_mutex); + (tr->part_bits && new->devnum >= 27 * 26)) return ret; - } list_add_tail(&new->list, &tr->devs); added: - mutex_unlock(&blktrans_ref_mutex); mutex_init(&new->lock); kref_init(&new->ref); From patchwork Mon Aug 23 07:33:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 1519575 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=kVARO2w1; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=casper.20170209 header.b=jJiTrbwJ; 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 4GtPKn1RdKz9sWS for ; Mon, 23 Aug 2021 17:40:29 +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=0ixx+B1NplU6zOMkKhSp76Z6CorJpNpDiih0lckO2Lk=; b=kVARO2w1lkJrk6 Q8xJH97Wsb7c4TME6pLJCYGB3QP8jypkiKfP0EPE5KXh06tS/0GBZrl12vHuCmJINGx4AMbhdkM6c EMkHBFAbTYXZfXtmyqTB0PNV8tydnt9K6btfex0nxa9PXRsGM4IzFb5HjcWIyuZXcAgBieXxXFsQ2 rqw4swVlJuRijRj3tEid5U1Zx5d08c2jTSDpVhAcanC8aD4x3PtGvP9I+nqQA6Hm4nwOTsuu9Lpmq 8GlECpvpBDjOIt5BsjxGrr1z79XKb17Z9Wu+IVC8rD7oltzN94oKdBOZf+3cyEtCvA4AStmHoQo/T BOrUJXuVxJYAD/Mtd0lg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mI4Ye-00Flsj-2k; Mon, 23 Aug 2021 07:39:48 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mI4Ya-00Flr3-Kd for linux-mtd@bombadil.infradead.org; Mon, 23 Aug 2021 07:39:44 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=TQvwYGDey7Tixxdk2ARcuyF6ump6jRrEEFzPTGwcYTI=; b=jJiTrbwJnRsaDZUS8K7f13JXht R1VYiaS3de/jJDmlOWt5XJcTTcDcohEdat5Cjtw9a23Yb/H2ovduTqZl8qKHvTklNiOEJz8s9Wg9O YXrkCMo0kJ21Yhzwhwla1MN7V9yvwzRphdSJekBvzSnrADQ34hVbO+3vBUAwllkLPbtEOb2QDlrAH QyXcoOJ+UiL9O99Ist5MINOy3FKZm8lABAh+7XSi1yzlfdMTPOCeJVQih7v39mExbQpHcLxxquimD +ouaR4ektXNdZG4vB/+1j/+hTAFvWdWf4/FBxp5DZvr1FSCxfZBLCGyIwcR31xttN9yLKaNwbqs1S 7AthodOA==; Received: from [2001:4bb8:193:fd10:c6e8:3c08:6f8b:cbf0] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mI4Xw-009QuJ-Sl; Mon, 23 Aug 2021 07:39:17 +0000 From: Christoph Hellwig To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra Cc: Guenter Roeck , linux-mtd@lists.infradead.org Subject: [PATCH 7/8] mtd_blkdevs: simplify blktrans_getgeo Date: Mon, 23 Aug 2021 09:33:58 +0200 Message-Id: <20210823073359.705281-8-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210823073359.705281-1-hch@lst.de> References: <20210823073359.705281-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html 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 No need to grab a mtd_blktrans_dev given that ->open already holds one and ->getgeo can only be called on an open disk. Signed-off-by: Christoph Hellwig --- 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 6f226b7cbb5c..012c0966010a 100644 --- a/drivers/mtd/mtd_blkdevs.c +++ b/drivers/mtd/mtd_blkdevs.c @@ -257,7 +257,7 @@ static void blktrans_release(struct gendisk *disk, fmode_t mode) static int blktrans_getgeo(struct block_device *bdev, struct hd_geometry *geo) { - struct mtd_blktrans_dev *dev = blktrans_dev_get(bdev->bd_disk); + struct mtd_blktrans_dev *dev = bdev->bd_disk->private_data; int ret = -ENXIO; mutex_lock(&dev->lock); @@ -268,7 +268,6 @@ static int blktrans_getgeo(struct block_device *bdev, struct hd_geometry *geo) ret = dev->tr->getgeo ? dev->tr->getgeo(dev, geo) : -ENOTTY; unlock: mutex_unlock(&dev->lock); - blktrans_dev_put(dev); return ret; } From patchwork Mon Aug 23 07:33:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 1519576 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=YGHorrOL; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=casper.20170209 header.b=S6hjwLRu; 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 4GtPLc6X2Bz9sWd for ; Mon, 23 Aug 2021 17:41:12 +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=ZJ8S2slNw5nY4NoejkxoGHlPdfm3USgrNrwHTXkAqck=; b=YGHorrOLoJT9Ho 6Xw8OsJ4H/zPnGKjNeeIALwxla6fJFM3sfSUIwno29PCoCChffxOIXNWZd4i7npOuG1jtKE46ID73 B+vI42dcNlVFUsF4YGmSRw48ujkQXeH77zihxZ0P39rSOgPuPI09gPaKi9sMZEUhTRa7H7/SIAsnR S2RQSqNgiFUjbv2EVjWcFNBlcTSfyTKV+uhZBGFQrvG4TAiymfB6AozwZNQ5FKKQC5t1WyHD8RDzN 27quzydpVr/tOtOFSJDH7yhwEp76NUZzwd9OdiSfOildbUAeKk8k3yKIaCJUdab5YeYGq/FunQDIl x0rTRevqaZRGhCmBfzbA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mI4ZI-00Fm7O-0T; Mon, 23 Aug 2021 07:40:28 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mI4Z7-00Fm3K-Dh for linux-mtd@bombadil.infradead.org; Mon, 23 Aug 2021 07:40:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=bW8lM6GBoFl8xsy9TFOTRkQUOIEc4wbj1euLF2HzbwU=; b=S6hjwLRu6s6HuqHxbvrvRxEqyz vU6s59azQUnian0aQdPRVSjAAI+wkXN2X1DudRM2rOnGDnQXaeb9QgAfL8waOYAR76vhcpq3K/BE1 eSrQCKRa2y7h7DTMmW7qDLwTpu60KA1F0XgLaFcpq4OXFr5CBO7qAwjD0lpzj6e5gUTdYU8palMdB dwcCzQRW5THkY6xWYHX4JHIYQydOanF14n26nhz+l3a465W3ra/f6DXee/W8lDHFJAPcQAmM4rQPo RpkudU2zBGLU7vcczt2bnuYAXtrOYDz3JqVJIZskY9wFfNsKrq6FBI8uefSHPefhPknMbfvIHeXhW 5NZ7/okA==; Received: from [2001:4bb8:193:fd10:c6e8:3c08:6f8b:cbf0] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mI4Ya-009QvE-CJ; Mon, 23 Aug 2021 07:39:54 +0000 From: Christoph Hellwig To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra Cc: Guenter Roeck , linux-mtd@lists.infradead.org Subject: [PATCH 8/8] mtd_blkdevs: simplify the refcounting in blktrans_{open, release} Date: Mon, 23 Aug 2021 09:33:59 +0200 Message-Id: <20210823073359.705281-9-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210823073359.705281-1-hch@lst.de> References: <20210823073359.705281-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html 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 Always grab a reference to the mtd_blktrans_dev in ->open instead of just on the first open, and do away with the additional temporary references in ->open and ->release. Signed-off-by: Christoph Hellwig --- drivers/mtd/mtd_blkdevs.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c index 012c0966010a..b8ae1ec14e17 100644 --- a/drivers/mtd/mtd_blkdevs.c +++ b/drivers/mtd/mtd_blkdevs.c @@ -36,14 +36,6 @@ static void blktrans_dev_release(struct kref *kref) kfree(dev); } -static struct mtd_blktrans_dev *blktrans_dev_get(struct gendisk *disk) -{ - struct mtd_blktrans_dev *dev = disk->private_data; - - kref_get(&dev->ref); - return dev; -} - static void blktrans_dev_put(struct mtd_blktrans_dev *dev) { kref_put(&dev->ref, blktrans_dev_release); @@ -191,15 +183,16 @@ 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); + struct mtd_blktrans_dev *dev = bdev->bd_disk->private_data; int ret = 0; + kref_get(&dev->ref); + mutex_lock(&dev->lock); if (dev->open) goto unlock; - kref_get(&dev->ref); __module_get(dev->tr->owner); if (!dev->mtd) @@ -219,7 +212,6 @@ static int blktrans_open(struct block_device *bdev, fmode_t mode) unlock: dev->open++; mutex_unlock(&dev->lock); - blktrans_dev_put(dev); return ret; error_release: @@ -227,7 +219,6 @@ static int blktrans_open(struct block_device *bdev, fmode_t mode) 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; @@ -235,14 +226,13 @@ static int blktrans_open(struct block_device *bdev, fmode_t mode) static void blktrans_release(struct gendisk *disk, fmode_t mode) { - struct mtd_blktrans_dev *dev = blktrans_dev_get(disk); + struct mtd_blktrans_dev *dev = disk->private_data; mutex_lock(&dev->lock); if (--dev->open) goto unlock; - kref_put(&dev->ref, blktrans_dev_release); module_put(dev->tr->owner); if (dev->mtd) {