Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp560708pxj; Thu, 20 May 2021 16:15:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx0z418GA7/ZCConl18QI508rkz2HB2WwXev30cZ3LVHW44yjksvVyn0yY6uqqyiftKibdl X-Received: by 2002:aa7:c845:: with SMTP id g5mr7585608edt.219.1621552533200; Thu, 20 May 2021 16:15:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621552533; cv=none; d=google.com; s=arc-20160816; b=fuJNWyQaUo7NQ2KOozTbBoejLNEEu9En5ZLCSE0KBQ6aKsrpv4ilL4XdNR6Q/cemTn zMtz8w5BdLndSxnBKRcVgBpxvhEvpyEm/X4XaSsskHYJShF+KDAz1i6o1W+5M6JnlacV lTsT0pe61Fx+650E0p4sApTEIS0h+FRv0ycFo/n2WmXFT8M2cz9Zj8MiGwIACClY91mG Tw4auxP7rO1XcOtaPjsxi6XGsjQNkXt3M+fq6o1rXijXn02ErCJZm2h2ptBiUdYnGOf+ OsXtx7YrivN+dd+eohTwUsCwT97vgE0bKSLnxqxMTWOBywMiwH9mSlWRFWJFjTv6PBTp RN4w== 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=gJF4nv5s6gGcDxPCzFh/yuRIzu/aszbM5L13LOUVATsDtVtiT6SMEgwfOpoS1DOYAP TbUjoS2USKZTY+AZ+3p9E1HyU1lb0T32SBsd5a1Jvsp+xC56gRwCLPq6zSzcdcUuzJ+X Lv1Ug/5cJu9ygmdAMOuMfIWJkdFAoIBYT8C79/OoNfO/ZriB9xRKRC/Tza3EvIbyNLLT P+A4RGYL0+qPwOizp+l7su73txZCOBAgAQKUUe3ezyqX/H1JclkIL1zULUk7t+u/cmyM Z3iSMBcKLBINRfauf4izZU5RP/e9UyQstkaeB+6BMqKhR/m9VYi0NO3HZSzlWs1WMuVh vzgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LgsUcLgc; 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 x8si3799364ejw.54.2021.05.20.16.15.07; Thu, 20 May 2021 16:15:33 -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=LgsUcLgc; 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 S239810AbhETL16 (ORCPT + 99 others); Thu, 20 May 2021 07:27:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:39630 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239494AbhETLIB (ORCPT ); Thu, 20 May 2021 07:08:01 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id BA6D16100A; Thu, 20 May 2021 10:06:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621505168; bh=utCbk+blntjf/cU7sZIjoED/DrtKfhd2Mvgji68r64w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LgsUcLgc1COmgA9sBQN2JxehryXLSQ4LUVjza5js7kh4PzEhpztRBAI64O0MNKPIy CAx4NfYaCafHbGmTsG4fU6jr4sJnzP7JIRLAZkeQhbsWceEhJcGu/x35MDvYyUeweu mGxQ+7/fhWa1sUaczX5D4+TsJY7uGX1NYlC5mwOA= 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.4 013/190] mmc: core: Set read only for SD cards with permanent write protect bit Date: Thu, 20 May 2021 11:21:17 +0200 Message-Id: <20210520092102.613855441@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092102.149300807@linuxfoundation.org> References: <20210520092102.149300807@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",