Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2469984pxj; Mon, 10 May 2021 03:53:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxQq1lBCDLqy+XGYsSPqtrRLugEy3LbLD72st4SL0FVfbr4S8vxEY5mkL/pyBSkPi6XvriW X-Received: by 2002:a6b:f606:: with SMTP id n6mr17429996ioh.142.1620644003810; Mon, 10 May 2021 03:53:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620644003; cv=none; d=google.com; s=arc-20160816; b=OXz9a9aI5G+C2CosTV1A+W0U/lFi8kPgfYUtrUVXW68XhoadCDU2UYGUth+vB2P9jM SHl0bVjYoTL2Z45qvsJ6MadKkzfhx+QM1uIsoW0pT3pmvenmPVa4QutB8xVBy/BBK01+ Tx2qTnEPh8pcaa+iC4MbTp/Jjl0B4ojc5hE58tSh0rspURQDwXPyUykrnysQA+w0D2tW u/a8KA8vcrLDNryfelhB6M8CFdpu4XO5q2Rwis/Id4uJtcaR452F2TTrFEE5djcBmwwQ q3/1nR64z+9asZervh/NxhT5226x1V+joYkRTfJU4mbmUotMJAnWpLW10QlbjMDl7su6 mYig== 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=Nw4msrTQq7J3+QA7UJpi4Znz/bw891EicyxFB9m99p4=; b=TXdtYx+p6w++p5RY3VZ5Wy4pHb5Dhi8hnpAlIU7Ynbbn34ybU8PGa+XN33GbfcTXlL 7FwQH8oYpb9PBFTfFNpng3e9q4dy2Z5AX3KU0mOsmBx2ZS6LrqeQTxujADh55gf4KM5s jcXl0391sU39HCa2ehv2GHtWRKA8utCRVNrqq+H/4AHV6ayNEihGrZ/02SgSa8HNWXoM u28aX1mXu7qJwl3Df0qLJmr5NASBv6ez/d+RdI6lHmzlAvIJAxnInn3gaIarOQuJV4dG jGMZmp+gFOQbjIq47RryK6vPxSathVDWJZeAJXxM+EbLzdKKm3W0ofrbWDuvP4oZLqKR FaXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ETNMiM3r; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p31si2172962jac.95.2021.05.10.03.53.11; Mon, 10 May 2021 03:53:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ETNMiM3r; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231758AbhEJKxZ (ORCPT + 99 others); Mon, 10 May 2021 06:53:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:52048 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232310AbhEJKmZ (ORCPT ); Mon, 10 May 2021 06:42:25 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A8B4061977; Mon, 10 May 2021 10:32:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620642754; bh=sP2dQjHD2FueC4m/bS+QFiIvXArU9tbnHjslAyBS4zI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ETNMiM3rv6T2Vv6WRZPOTEIlxyfpozZhj8TqtNrIA9j54bJ3xs9GIbjmjr4shqY2L TN8Xr1SlLnlDWlk+uOnfcBhxjGlxTqKGMVJxwaJwxp3SsPynTrORXhEWdX7IcuA8pi 5UNLrMUUEQ1dwVV98I/YrpP0A3FgRDHJiIehCnxs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Seunghui Lee , Ulf Hansson Subject: [PATCH 5.10 036/299] mmc: core: Set read only for SD cards with permanent write protect bit Date: Mon, 10 May 2021 12:17:13 +0200 Message-Id: <20210510102006.040965751@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210510102004.821838356@linuxfoundation.org> References: <20210510102004.821838356@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Seunghui Lee commit 917a5336f2c27928be270226ab374ed0cbf3805d upstream. Some of SD cards sets permanent write protection bit in their CSD register, due to lifespan or internal problem. To avoid unnecessary I/O write operations, let's parse the bits in the CSD during initialization and mark the card as read only for this case. Signed-off-by: Seunghui Lee Link: https://lore.kernel.org/r/20210222083156.19158-1-sh043.lee@samsung.com Cc: stable@vger.kernel.org Signed-off-by: Ulf Hansson Signed-off-by: Greg Kroah-Hartman --- drivers/mmc/core/sd.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/drivers/mmc/core/sd.c +++ b/drivers/mmc/core/sd.c @@ -135,6 +135,9 @@ static int mmc_decode_csd(struct mmc_car csd->erase_size = UNSTUFF_BITS(resp, 39, 7) + 1; csd->erase_size <<= csd->write_blkbits - 9; } + + if (UNSTUFF_BITS(resp, 13, 1)) + mmc_card_set_readonly(card); break; case 1: /* @@ -169,6 +172,9 @@ static int mmc_decode_csd(struct mmc_car csd->write_blkbits = 9; csd->write_partial = 0; csd->erase_size = 1; + + if (UNSTUFF_BITS(resp, 13, 1)) + mmc_card_set_readonly(card); break; default: pr_err("%s: unrecognised CSD structure version %d\n",