Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp605446pxb; Tue, 5 Apr 2022 15:43:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy8IKtjT7gBk3/PXhOwSRIUC2JKTAtHbJi2Bvj3YgmuO/fqV0Gmp1LITtHLo0x43mPeeVh8 X-Received: by 2002:a17:902:e892:b0:153:db4c:8ccf with SMTP id w18-20020a170902e89200b00153db4c8ccfmr5686375plg.17.1649198584045; Tue, 05 Apr 2022 15:43:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649198584; cv=none; d=google.com; s=arc-20160816; b=xwELkTZqX7lKLY7xLFQ2R+uuZdhAj77sv4H//gi1sC0VO6M8vkIS6PACwTujl50Y9M kW9C2+n1t08y/K7nPoZ0mXsvMsB+sSpMDQiecRK1By2QxKOZX0uhBDtak/A6c+NqzpgO 8sZU/pH/DMW6L2CRF7iOEt1NycJ+VnuB8rgGXc1c2OewkmiAze1zB21ZH8jHmmgm21NJ oVw48hbiY35cAJsI+wNc/UW1BGbOgc5Cb22xqRNpfHKsurGvPtBjR1PNy/hCmFaD7/N/ LD5O6Knt9MUaeMGE1mRhvgagNRwom5EkgAQtJGIVaRTd1FhcJx5Mxuv0xE9aUPmZMv/3 UMDA== 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=HlSBFYaFEDMQrsnm0hSYPcf+q7GpN1ml/p/zvgcQ2ZkIra0VSZRTsarmpKDBVbeo/o m1OAwOxzVDkW/8cTt4WTy88UxnyxBIRlHWQ8vKpSam93RqFWJpTciWh4NoeWzFUwFltT OFDZOh87r2Iv635cxeGRXp3aOwILQpwicA0Lx54qbEtWYiGGhKa7KhC+o7+ibWgd3cKo ECm2azXi0KVKG8xvV37g1A5v/BshqrF2EXeOWrIi1KOfeafEcMYKUqyMAL+H/FGiCbvC P5P6gG8j8l+AP9Dq8DCphUV/XDmYbWhFWmqFlBMAoFiilZHAY557f+f/rMW0vzRz1eYI AryQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uOsrNKfH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id y21-20020a631815000000b003816043f110si16751735pgl.773.2022.04.05.15.43.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 15:43:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uOsrNKfH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8646066CB8; Tue, 5 Apr 2022 15:23:46 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1388129AbiDENVK (ORCPT + 99 others); Tue, 5 Apr 2022 09:21:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344357AbiDEJTe (ORCPT ); Tue, 5 Apr 2022 05:19:34 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0A3BBA1; Tue, 5 Apr 2022 02:07:49 -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 7BD9861573; Tue, 5 Apr 2022 09:07:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85C7AC385A0; Tue, 5 Apr 2022 09:07:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649149668; bh=P/lxEK3xXgM2nxhjaAHZNVVhYk11eH/eKFXBmOkQsxo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uOsrNKfHV/Zdp76lY7oq14/x5KBgu47WSiKkPhy5xt5E/GlpJ4Z7vnLg5ZdxIZxBR 1hZiL6SF9L7ZuzqJIdt3ruNDQbHVYxenhAINeW6ZyLVocizTSO39AsB6jfH+bOs+Y7 zuqw4LMg0277I/rjkGdAHxyxciLjXoSahyyPPEt4= 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.16 0759/1017] memstick/mspro_block: fix handling of read-only devices Date: Tue, 5 Apr 2022 09:27:52 +0200 Message-Id: <20220405070416.789172716@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@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=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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