Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp413189pxj; Thu, 20 May 2021 12:14:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwlI5oh+XqTVHuhuDPCxBZR84bk13lOMJsZGsfbfIpOZtC1LGIH+nJU8sptYBTvob/E8yfP X-Received: by 2002:a17:907:75e9:: with SMTP id jz9mr6087749ejc.314.1621538057250; Thu, 20 May 2021 12:14:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621538057; cv=none; d=google.com; s=arc-20160816; b=ybPQv6lJ7h35Nfd/w8oFk1NTDeZIjh2bbJZ21RWm0b/z5z8CZuIKLQRQ2gfFpPrEam qL9WNK6zPQSZX9GsaClSCeYmRNiPEb/Bf5Jb18j+lctcm43yI+dSQomVxgFQ/KnDc3RJ 8HcTtGKUBE6MLtcEJmMdSC0RdKPNwIth2XaZQES+NqIllrQLdm+G6W0eB+crRQ5+JGJc 7G01gGoMJpwjTdAYPBnoabeYY27finxiDU1ap9ikWhE0tG+rnDEroNcPTiF+80c1R7bZ Spex8gYvEci8KfKboRK6HEN2iZMjw8EE0XemHu9PcVVeLkzVOVW2IJESGRGEFuUekS11 2deA== 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=lXJipr+QjUfTVgvc8tMWREfacoqkMyNreD+3GZY/zaI=; b=WKtpDAldtFM9fbxiQDZPXH0nO3zQHbo4KdleIrqWY1LzVy9yaku6yumliB6KFj88B6 64IYythmr5o/QICMuTtL/Lbu18BOy3f4AzbmX2JBkxyDpYPAXu44oi2rHDdLpt6Sh9jw 2WLPaBGW8TwzZWbx36i1xbmxyGYp9yVWuRhfnDyPkyHZN/Z1gl9IIsOOwobX1zrdVGFO OokLgrj/KUwndMMGHQhdfuWpzQnOc2jaPDYAJIksXJukws1D/WiGz9eSdpGNubUi8fwY dEriuNCfcgykeKlT3T1d+92+Nx6ofziTtsm0B7u9LDrHeQQEv98Xb6PHe4o80kB4NqUA H3ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=nIr4h7HB; 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 a20si4245790ejg.72.2021.05.20.12.13.53; Thu, 20 May 2021 12:14:17 -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=nIr4h7HB; 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 S236076AbhETKcG (ORCPT + 99 others); Thu, 20 May 2021 06:32:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:51950 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235540AbhETKTP (ORCPT ); Thu, 20 May 2021 06:19:15 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7E62C619B2; Thu, 20 May 2021 09:47:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621504023; bh=utCbk+blntjf/cU7sZIjoED/DrtKfhd2Mvgji68r64w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nIr4h7HBkJLVavIdwREjEH7HEofELalVX+gmCy3NfC3TCgdEth0NWyEr0k113WLI7 vHP8jGntKbS33pRzDn0a+o+QqZHzQ1IQWOkdb3LV6qQUi6z+tvHpqP6KU5aUBs40QN gjDFfI6EdzUhZfz5MmpUxNW6zFdBf/v9ar4sE5CM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Seunghui Lee , Ulf Hansson Subject: [PATCH 4.14 025/323] mmc: core: Set read only for SD cards with permanent write protect bit Date: Thu, 20 May 2021 11:18:37 +0200 Message-Id: <20210520092120.973461769@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092120.115153432@linuxfoundation.org> References: <20210520092120.115153432@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 @@ -138,6 +138,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: /* @@ -172,6 +175,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",