From patchwork Wed Feb 2 15:56:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12733204 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3089FC43217 for ; Wed, 2 Feb 2022 15:57:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231464AbiBBP51 (ORCPT ); Wed, 2 Feb 2022 10:57:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344989AbiBBP50 (ORCPT ); Wed, 2 Feb 2022 10:57:26 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C42EC061714; Wed, 2 Feb 2022 07:57:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=QzwLw7j8eTvZsRbJglcJOtBbwWYohx/2fo0FBI/zHLQ=; b=lIGa4JS6CboqrLuLU51vbGBy5v LUZTqwoJY2B7TqEJmBOq3DBaDsINQwkco4MR70yhNcpQ4rGLQKpBE9A3hwlBFUr453Eprfp/frLXl bAiw+m7cF6EY+eAE7/ONNOSG57ub97sMxqv/T/Us/VOkSh6s7c4Qjne9gR1kg9ykIKMFUi+15OObR Q/i9EGP1vCUS93CN9tds14oJ7AqrZ+7SGeUpk8kQ4BP/GMkezCBpTRLdYttN5PPo3M3vqSNoKC9Tw Mcw5ggKMjixI8OSuxsZnCVJZuhxMUorynzAF2ZgOGiloH4JEDIz1pkBRE/ww3U8Z8oOwSUIp6L3HI w8nKwwUA==; Received: from [2001:4bb8:191:327d:b3e5:1ccd:eaac:6609] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1nFI0Q-00G6ZE-1B; Wed, 02 Feb 2022 15:57:14 +0000 From: Christoph Hellwig To: Jens Axboe Cc: "Michael S. Tsirkin" , Jason Wang , Paolo Bonzini , Stefan Hajnoczi , Maxim Levitsky , Alex Dubov , Ulf Hansson , linux-block@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-mmc@vger.kernel.org Subject: [PATCH 4/5] memstick/mspro_block: fix handling of read-only devices Date: Wed, 2 Feb 2022 16:56:58 +0100 Message-Id: <20220202155659.107895-5-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220202155659.107895-1-hch@lst.de> References: <20220202155659.107895-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org Use set_disk_ro to propagate the read-only state to the block layer instead of checking for it in ->open and leaking a reference in case of a read-only device. Signed-off-by: Christoph Hellwig --- drivers/memstick/core/mspro_block.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/memstick/core/mspro_block.c b/drivers/memstick/core/mspro_block.c index c0450397b6735..7ea312f0840e0 100644 --- a/drivers/memstick/core/mspro_block.c +++ b/drivers/memstick/core/mspro_block.c @@ -186,13 +186,8 @@ static int mspro_block_bd_open(struct block_device *bdev, fmode_t mode) mutex_lock(&mspro_block_disk_lock); - if (msb && msb->card) { + if (msb && msb->card) msb->usage_count++; - if ((mode & FMODE_WRITE) && msb->read_only) - rc = -EROFS; - else - rc = 0; - } mutex_unlock(&mspro_block_disk_lock); @@ -1239,6 +1234,9 @@ static int mspro_block_init_disk(struct memstick_dev *card) set_capacity(msb->disk, capacity); dev_dbg(&card->dev, "capacity set %ld\n", capacity); + if (msb->read_only) + set_disk_ro(msb->disk, true); + rc = device_add_disk(&card->dev, msb->disk, NULL); if (rc) goto out_cleanup_disk;