Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp663793pxb; Tue, 5 Apr 2022 17:51:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzG41rdpKUYTd8b2Vt7EKcZ7XBLL3qXG+31LSJnk0iEy1wQs74BEHy1+t8NJwkkLaIIcBk3 X-Received: by 2002:a17:907:7d89:b0:6e7:fdc1:255b with SMTP id oz9-20020a1709077d8900b006e7fdc1255bmr5967390ejc.340.1649206305241; Tue, 05 Apr 2022 17:51:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649206305; cv=none; d=google.com; s=arc-20160816; b=oyL2xwEVfG4FnrDpvIvzDyGYZjg3a2E3dS6/U5R7K2JC6ZKauPFIMGsJh78J3JgsvG rMdpeH5FC3nkl2Ye/eryAWZEyZdz+1PxeRRQ75n78rtD3EciCRq7oUpopwbe5HwwmgAb ScyT97O5u6qbcO7MfEBihT5JWCjxKU9/zK7QVPsl7/iTX+veZCXozxoDrtGJAzdIZM1+ Y/hm8H5rXdv4rfP3CJ4YJkzbCut24o2MhmHXs1bHPsnKHxGavXZ1eg/ru9MYhf4qVZXB muW4+36LMqeE2qC2GsilXw7ZbBQ7HsT8tDv1aIYQnE1Iy2IygD8Mst5OsjRKuD816rVp sbRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=RWszYFNg19r8aVsqxlPhoHgt6P/WQQETBDOFol3uuqY=; b=ZpR5dLzlcxRprGe3IKYvLun8BYLo5HSLflG5XwhaSG8vI8bmRNdcwXfS1ehFqGCOmC v7tdp5wlBlO7cZWJB3b4pofDHaIZFuP5ENETk1UI0fnUcJocmsl9udoBMN9Fm7nWBsJH HK6b+vnATQnJTigrtUZfTkyyGzALyov11oT9VTPFEb/A7s9ubJ52AalmrnfgZIcemrH5 dDFZ5ddSvroSEyLXLgWfB6x60zG5N5YDzDX0jy3/ehnEgIHQI/Y8tdEqnGLvI2Eo18QY nLUKJGh6RoT7gn0JG93mLP68SoRr6PUHKynwNR+5w+oDiORxmUrUCCazealVWyzKXNTz S9xA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xpP1nCve; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l19-20020a17090612d300b006df76385e94si9901825ejb.820.2022.04.05.17.51.15; Tue, 05 Apr 2022 17:51:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xpP1nCve; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350341AbiDEJ5c (ORCPT + 99 others); Tue, 5 Apr 2022 05:57:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239909AbiDEIVx (ORCPT ); Tue, 5 Apr 2022 04:21:53 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A90865F2; Tue, 5 Apr 2022 01:19:26 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3F8FE609AD; Tue, 5 Apr 2022 08:19:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5097EC385A2; Tue, 5 Apr 2022 08:19:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649146764; bh=P/lxEK3xXgM2nxhjaAHZNVVhYk11eH/eKFXBmOkQsxo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xpP1nCveV5RWSzRmUNCPHzci+bkYSzc/lNICGiprsrf0ZEHDncSmik5O4tlZJ4rFk TJVPyewjFxLYST8WM94RDbB31YrY1H/Q+//Ps+bL+VogdWMPl1n2A1fRRiksBvc0Qq UEMgh0Yv5InaQ6DmF32I44oQcT3m4jHTLCwa06Fo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christoph Hellwig , Jens Axboe , Sasha Levin Subject: [PATCH 5.17 0842/1126] memstick/mspro_block: fix handling of read-only devices Date: Tue, 5 Apr 2022 09:26:29 +0200 Message-Id: <20220405070432.267789464@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070407.513532867@linuxfoundation.org> References: <20220405070407.513532867@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Christoph Hellwig [ Upstream commit 6dab421bfe06a59bf8f212a72e34673e8acf2018 ] 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 Link: https://lore.kernel.org/r/20220215094514.3828912-4-hch@lst.de Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- 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 c0450397b673..7ea312f0840e 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; -- 2.34.1