From patchwork Thu Apr 30 09:16:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 185882 Delivered-To: patches@linaro.org Received: by 2002:a92:3d9a:0:0:0:0:0 with SMTP id k26csp1839041ilf; Thu, 30 Apr 2020 02:16:59 -0700 (PDT) X-Received: by 2002:ac2:418b:: with SMTP id z11mr755408lfh.30.1588238219000; Thu, 30 Apr 2020 02:16:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588238218; cv=none; d=google.com; s=arc-20160816; b=CHeEACa+syCBIuMVSMTM4df5EmOXrgsndyn6PclAywA9rwLKDbycaIDg0tIXN4qr6y 9OCARj9iwmJTrDA/+TXWv4aH5qipzzr2ISvkL7XWRlpLoNIOSalgIeHfgM4HIgj4dRUJ dx0gAnLOD5Jc6e/Rp1NQLmuobW9ybObmrxlYhZIhk2EsdRSrtLuI92q0drczHzYbODe1 V9QGFbZOofR/oEzVtW9RoABIOGnTXOriJou8eNeHzMxsyla0eUxd/OG1auPhy0fCkVcf J25KBOyhdXAe3GSRm3fBO2SuYKnOXrYgUHvj+YBKnu00FVv5mq60At2nqBUnxAofzAUA cQcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=qAMZhL85o785efprM1NP2kmSTjnBd3DKp3TTm2/2pLw=; b=oykNnnvbdDR5Gp9Qly/Qltnvp/2KQ84Ux9b+mtd9efcmaMC3tc5CoTI+B3Qy6WwW7T 9ARM8LQhTMROrzKPjxItPDl6PqDUm4jW210jFj04VGQTVJ9Mka+VViBfUxwVOLwnbqMC hD/yrme1TMXIXDzTyR3tx8eFKoRvmwmSZru65+4/256WzIrp0xPD6jf4n+LFWxIWnAwZ YLh4HpZa8G/jZzwjbq7QOP3OE5iR2VQH58BIx6kwmz6gSVvFjIDi/1fgyyORqi0GS0qd CFYaD/44O8D/ZBCkDpZZsEQZcNxKyKwAUWDtEBD+J/fviGAMrYa3Op7s4Xf05Vy6HnQl PkYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VUHf05to; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id m5sor3636653lji.11.2020.04.30.02.16.58 for (Google Transport Security); Thu, 30 Apr 2020 02:16:58 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VUHf05to; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qAMZhL85o785efprM1NP2kmSTjnBd3DKp3TTm2/2pLw=; b=VUHf05tojt/8dBM7x8qriL+LZ5NSWiYL6ASfP0/qa6Z9WAiEfoL0VwjcYukMjohKAb IL3ataGrAGmqEvD+4NaBt2zCS/93XwBYOhc8YeP4b+2KAhUtSCWGHgcunC686tBuERjN JksemGXqBS/YkvykkQvS0KcGJ86LWPedSfqGfw8zWHtGAkLRMhkhr2GGLkz3YzbEtzVw /RNA47eQ6QSFWQVl0WCRRZHBN5EHtQcn4P3YphuQjrDURAjexH30bXSaiy1wluST12zj QX9GIE3S1R+B5Te/YJFb4HrtTuurnNQP8SJUQi6y8lyZRv1o6N9eqE6uXTpPgXCxIULc 8reg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qAMZhL85o785efprM1NP2kmSTjnBd3DKp3TTm2/2pLw=; b=pNV0ztU2YBAMoDjXvnarKJUjnWCdvHaTxH0R9OIjWJ5FI6FeYikf12a897YWSovjyI pRIsToTHqUP6p+RgUz47SL7h4Eu4dLjf2j6WKNyCTNJnqkvBnww+AA1DzQ3iswgQRnHg NQUYxZYAkUm+iJ3UHwQjiwHjftkcSVihJ6Ez8AwY8YKUoSmqTuWWewoTp8TlJlz//DTe g/07Yn8Z58oZtlbM4iRcKtpIxg4vDvyqI8WHEHiteIZGawT8d63g7+laXKlUw9+sJ+qe nzCU9Ly6ww+YPiCznixqAlQEBr9usTdGrsd8JCaI0JCCM/FLa1YkLTsaiUyJBBl6UyD7 Lwwg== X-Gm-Message-State: AGi0PuYCUuJis/M9gLrY8ri32x0T2rdCnGUUglNYS3FaciZw7oeHXWzu z1BnTBQSQaIAfSDC/E5vZ/FGG4dbLt5W/A== X-Google-Smtp-Source: APiQypL+uEyUbsga+hXMGToa54CpmX3+zYfupgtWwqH5J1W083jmsUWfJ/eXZguHDsGCrMriqPsXAg== X-Received: by 2002:a2e:9948:: with SMTP id r8mr1637670ljj.1.1588238218547; Thu, 30 Apr 2020 02:16:58 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-98-128-181-7.NA.cust.bahnhof.se. [98.128.181.7]) by smtp.gmail.com with ESMTPSA id x29sm4417818lfn.64.2020.04.30.02.16.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Apr 2020 02:16:57 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Adrian Hunter , Douglas Anderson , Matthias Kaehlcke , Shawn Lin , Yong Mao , Chaotian Jing , stable@vger.kernel.org Subject: [PATCH 1/4] mmc: sdio: Fix potential NULL pointer error in mmc_sdio_init_card() Date: Thu, 30 Apr 2020 11:16:37 +0200 Message-Id: <20200430091640.455-2-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200430091640.455-1-ulf.hansson@linaro.org> References: <20200430091640.455-1-ulf.hansson@linaro.org> MIME-Version: 1.0 During some scenarios mmc_sdio_init_card() runs a retry path for the UHS-I specific initialization, which leads to removal of the previously allocated card. A new card is then re-allocated while retrying. However, in one of the corresponding error paths we may end up to remove an already removed card, which likely leads to a NULL pointer exception. So, let's fix this. Fixes: 5fc3d80ef496 ("mmc: sdio: don't use rocr to check if the card could support UHS mode") Cc: Signed-off-by: Ulf Hansson --- drivers/mmc/core/sdio.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) -- 2.20.1 diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c index ebb387aa5158..d35679e6e6aa 100644 --- a/drivers/mmc/core/sdio.c +++ b/drivers/mmc/core/sdio.c @@ -718,9 +718,8 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr, /* Retry init sequence, but without R4_18V_PRESENT. */ retries = 0; goto try_again; - } else { - goto remove; } + return err; } /* From patchwork Thu Apr 30 09:16:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 185883 Delivered-To: patches@linaro.org Received: by 2002:a92:3d9a:0:0:0:0:0 with SMTP id k26csp1839099ilf; Thu, 30 Apr 2020 02:17:01 -0700 (PDT) X-Received: by 2002:a2e:9bc4:: with SMTP id w4mr1678284ljj.178.1588238221701; Thu, 30 Apr 2020 02:17:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588238221; cv=none; d=google.com; s=arc-20160816; b=AMyPvLYYRg/XwCEDGSoorM1DOj83usyl02SKKX0CXA1+yVDSn7vfRvFEoRaW2GxB0t 0QgRYzYmCbYJCVSIWEyhl5csDq+I27rSMPrinzzH1gGjkxBhtwMOHtoRrknHFTE6L9G4 BQgX/lRwletxzE5iKbOM4NjU1CRKGVluPb5kQ7LpTJ6k4YjUd7Oe9MLXkPcFTBQpy77v +mcWV6nbc5xFCS4eFSYa8Pi/kE1LEbRZd1UIgQ/oSCVOjIN/0ZKPqNemWCwoWelPjak4 /BphjhRtp25F1FCdO/vF5NT3RQxUxVkCA1FFPaW2bqeyo5KLsRxKN0QV/T32HDfzElGj Z5kw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=89RWgm3Up3ro7S0Yk5yseNEuoMg10aAHaWqeBrHIt/g=; b=S+bcfNqjhXPlFnMui70GRqG+xxyIxe0G3uBiEBn90OyRBXn+x2V8m38tVS3YRlBcHO r1yFc5XlfelT067Qu3oX+PCchiG7PjMqQgqlWrwd2pa9M4BN4TGNmFZQrR1pnTjTuJKR 7pr6gTkbTysjK8kUH2+1j8a6DWy4FAe0OdGmyOldUROM4m3601v33g8oSTaw+pweP3o+ IOa0/uExVXYhDgjyLSt1LDkySxJPOVDJcogNjhJYAgqZcaJa/kFeaGn4hNlLJXNlnDnt OFR3VuaTRZRo2V+l7kkc5IFTJkToLkJUN4nE4d04Pbyp9VcyTXR6nXdzmkSpWZJtjKer HuTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Gy1jjxtW; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id b16sor3662509ljk.10.2020.04.30.02.17.01 for (Google Transport Security); Thu, 30 Apr 2020 02:17:01 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Gy1jjxtW; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=89RWgm3Up3ro7S0Yk5yseNEuoMg10aAHaWqeBrHIt/g=; b=Gy1jjxtW2kqnP8wl1z0ZePoqRxHvAmq/BvkprWs+HY3KgER1UNhmbkrUE7RD0LPgKY uQtnZBz1J2mSeu+eT0etLN/FfcwGvsrKL4Nrx5zOfWwpjtrdUrOmR5LvHJTno8WFY1k3 x5OrsN21NVJFhFWc6Jc1u0idkK5MhkHDkviaR36/JUS11GwLtlMbbWzWdLn1mqqlHkxk qoKHmX++K4izXqqhMg9SiOPnBduBWKoAjdSwopuGIeT+I7EmZMA9t0pQAKvTM/7TrJkQ 9akLeyXPv/jMDk5GbMhZIhuk1XGs8Ikdd5/BrlBTuB01ck/qt+eY5t8JYwesIAbi7Twf 47fA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=89RWgm3Up3ro7S0Yk5yseNEuoMg10aAHaWqeBrHIt/g=; b=uWek7etsA1qTXxGaGC8QXwboV/yRJR73W5qQfo+we8JZ9ha3nesuPCqZVWKph9pxZI 8Rescu7GmY5spOdfLdHlPkd9KR+PePWGN9VkqvRJxTssiX3dqGeLBRj3Unr7VTb59sZQ Tq/C7RriOSk7WaTS0ENzlVOK62IwwcIyW4NTz0Utqijktnqdq2Fgx3Z2TPnIHrVU7GoR +codoDXgEXgs4NIsTM7WuaeRYHCJH3SxshbzcW3w6BSEtAIatbb1dOQviOqfJmDIuuG9 Ej86TTT5suln02g+h3wOqUfUfTzIBouNc+FDIONpY+md44yG8IB1/GUsweU6Pb2bWU/0 0AgA== X-Gm-Message-State: AGi0PuYPMwBlYI0AD0pp1SVhXuYnAPr+T8YDJz7+yP5aUWWv0of0kzG7 VGpA+YATlzu/1R/6E5CTlGspiuoS X-Google-Smtp-Source: APiQypJmzs15jBI6elZWL1N97UEwVf7+JRqsPJCAid1U0Zizuu6vh6vZY2dgafQFqaaUTqSk+T5ZsA== X-Received: by 2002:a05:651c:50e:: with SMTP id o14mr1644456ljp.52.1588238220685; Thu, 30 Apr 2020 02:17:00 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-98-128-181-7.NA.cust.bahnhof.se. [98.128.181.7]) by smtp.gmail.com with ESMTPSA id x29sm4417818lfn.64.2020.04.30.02.16.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Apr 2020 02:17:00 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Adrian Hunter , Douglas Anderson , Matthias Kaehlcke , Shawn Lin , Yong Mao , Chaotian Jing , stable@vger.kernel.org Subject: [PATCH 2/4] mmc: sdio: Fix several potential memory leaks in mmc_sdio_init_card() Date: Thu, 30 Apr 2020 11:16:38 +0200 Message-Id: <20200430091640.455-3-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200430091640.455-1-ulf.hansson@linaro.org> References: <20200430091640.455-1-ulf.hansson@linaro.org> MIME-Version: 1.0 Over the years, the code in mmc_sdio_init_card() has grown to become quite messy. Unfortunate this has also lead to that several paths are leaking memory in form of an allocated struct mmc_card, which includes additional data, such as initialized struct device for example. Unfortunate, it's a too complex task find each offending commit. Therefore, this change fixes all memory leaks at once. Cc: Signed-off-by: Ulf Hansson --- drivers/mmc/core/sdio.c | 58 +++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 31 deletions(-) -- 2.20.1 diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c index d35679e6e6aa..20eed28ea60d 100644 --- a/drivers/mmc/core/sdio.c +++ b/drivers/mmc/core/sdio.c @@ -584,7 +584,7 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr, */ err = mmc_send_io_op_cond(host, ocr, &rocr); if (err) - goto err; + return err; /* * For SPI, enable CRC as appropriate. @@ -592,17 +592,15 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr, if (mmc_host_is_spi(host)) { err = mmc_spi_set_crc(host, use_spi_crc); if (err) - goto err; + return err; } /* * Allocate card structure. */ card = mmc_alloc_card(host, NULL); - if (IS_ERR(card)) { - err = PTR_ERR(card); - goto err; - } + if (IS_ERR(card)) + return PTR_ERR(card); if ((rocr & R4_MEMORY_PRESENT) && mmc_sd_get_cid(host, ocr & rocr, card->raw_cid, NULL) == 0) { @@ -610,19 +608,15 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr, if (oldcard && (oldcard->type != MMC_TYPE_SD_COMBO || memcmp(card->raw_cid, oldcard->raw_cid, sizeof(card->raw_cid)) != 0)) { - mmc_remove_card(card); - pr_debug("%s: Perhaps the card was replaced\n", - mmc_hostname(host)); - return -ENOENT; + err = -ENOENT; + goto mismatch; } } else { card->type = MMC_TYPE_SDIO; if (oldcard && oldcard->type != MMC_TYPE_SDIO) { - mmc_remove_card(card); - pr_debug("%s: Perhaps the card was replaced\n", - mmc_hostname(host)); - return -ENOENT; + err = -ENOENT; + goto mismatch; } } @@ -677,7 +671,7 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr, if (!oldcard && card->type == MMC_TYPE_SD_COMBO) { err = mmc_sd_get_csd(host, card); if (err) - return err; + goto remove; mmc_decode_cid(card); } @@ -704,7 +698,12 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr, mmc_set_timing(card->host, MMC_TIMING_SD_HS); } - goto finish; + if (oldcard) + mmc_remove_card(card); + else + host->card = card; + + return 0; } /* @@ -730,16 +729,14 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr, goto remove; if (oldcard) { - int same = (card->cis.vendor == oldcard->cis.vendor && - card->cis.device == oldcard->cis.device); - mmc_remove_card(card); - if (!same) { - pr_debug("%s: Perhaps the card was replaced\n", - mmc_hostname(host)); - return -ENOENT; + if (card->cis.vendor == oldcard->cis.vendor && + card->cis.device == oldcard->cis.device) { + mmc_remove_card(card); + card = oldcard; + } else { + err = -ENOENT; + goto mismatch; } - - card = oldcard; } card->ocr = ocr_card; mmc_fixup_device(card, sdio_fixup_methods); @@ -800,16 +797,15 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr, err = -EINVAL; goto remove; } -finish: - if (!oldcard) - host->card = card; + + host->card = card; return 0; +mismatch: + pr_debug("%s: Perhaps the card was replaced\n", mmc_hostname(host)); remove: - if (!oldcard) + if (oldcard != card) mmc_remove_card(card); - -err: return err; } From patchwork Thu Apr 30 09:16:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 185884 Delivered-To: patches@linaro.org Received: by 2002:a92:3d9a:0:0:0:0:0 with SMTP id k26csp1839126ilf; Thu, 30 Apr 2020 02:17:03 -0700 (PDT) X-Received: by 2002:a19:f611:: with SMTP id x17mr1515114lfe.51.1588238223606; Thu, 30 Apr 2020 02:17:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588238223; cv=none; d=google.com; s=arc-20160816; b=phau8nVrR6l+jx9oGMRFwhB8LurpdtFauKMJLN1UNTpQ9mWKcRsjgmK2cGiOGV8Ftx pCoLRM+SMuIWH7CqMGMZZ7Auq0v83S1bAh83e8fgj4PQXaFQ3XuEO0QXtkhVFOviGjxe jq+OyuLJpFoQJw7Sqv+zmnybrCU1xHUBazVj5zE2tvD4cOjNLUZRWeHMQ8Ea4x+BTz/1 I94iV79cRsWqVMwIMjl2g6uLMX3TioHzxpuCRzmTmy4IXfOiEqwBHuXsP/Xw+HYRsZwo 27UXgY6ERAkuxK+x5ImdQ/oDqsaQZ3/V12C1sZeo9xrNRG75S/4YbwQbDXL03EgOXoPK /4YA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=OYtBS8/bdD7KI7PkR78/ZukbdqMPK7h5qCtkWF9k0YU=; b=cLkez+yEOcgbk5vSH9V+HYwZMzD59wR5MbFrgTZd/cy1s8p7hs5sRZ93PT7M+XAZ9U GfpwTAI/ctQC+dEzYcRTsuN8hpJRCvO/eCiNztpv3+sXrHh7MOOjOXZTxdBZYft6HoRr J6/cwYGdiH2C3nUodq56X7m3Sfl6OPH9VDEfb2lqGXFvbVkyK6H//2ohQ6CYDC15v7Oo LLkpRHu+P5JtpSBQgjN1DcVxZKwuKADGdEcIOx56y13KbGmDblqjO44ed/8hOsoPiJ6f eYLOkdiyYlL3YGOR/htYLW3U9jJX2jGZb2SK7Lm+o/qDUXHZWWWinPqZVGQK9rJCYakN FZhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=c6hkv6C0; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id y14sor3611459ljc.1.2020.04.30.02.17.03 for (Google Transport Security); Thu, 30 Apr 2020 02:17:03 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=c6hkv6C0; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OYtBS8/bdD7KI7PkR78/ZukbdqMPK7h5qCtkWF9k0YU=; b=c6hkv6C0TY7SlLSo0HHsD8TibtF+oxLni1E/8ReD3pQTWO1T+s68/ye2YNSPbhofo0 X3/0IBH1kA3BmL7drTNNrGx4WSPP+XEQwbcx4WLf60zc/AEM7m21upvdkXH6+JF8tgJh L+3m0HnIPAoUBDbzwzuCIwbv5C3nlbovQ07c6FAeJ+Q3tb27gorLxkuoM3YF43L+qJ81 pFTfxQsu97W7PR6zrq0LVXUN/WvAITdYI/ES/fhvnlM1s6heFZlH7w31qUhmslgUKvgV Dg6a7/R5C3XRWi5Mej+w+8VHsNtCQY1/d6rjCixiW7i7TdMDb4OgsmGtqa6f2nBGxQcn rPKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OYtBS8/bdD7KI7PkR78/ZukbdqMPK7h5qCtkWF9k0YU=; b=qarYVKekLnOSzmF+uaCtWYNv+bc/xkrOW9Sq46i5QprqcOae3FZ/IYMl2vENV3JArD fauSvfmy+2GW2ZluELSSNINHQFX9Z7B3Wvdsf7fHS5BEHPlaNZQyKviR4X/X7xDb6xI9 BtoNKyTf+0y+H38/a+LHwsh5/YtRlrLxXdbOa5io7/4/RmX1qksRMNnbzP3Nz5pM/rZQ zwHjofDgBaKbFDHC6R/ecfQCNCGppYCJ0iSKTma4SmtLUCGmDV6nKpst3cOWBOGTafra wNd8tM/+VkI8EW6ImqyZYosn/9rWeEMEaJ8kBgwdny7kbAXSmQ+EhSlVUSCeCnJ9hmrB 08OQ== X-Gm-Message-State: AGi0Pubr1g2rS/HsjhQEYYqKH2+sOkCUHFyNdFpu90Js8QuFxgTawZks Jz6W/Ol0RhR6t5JW0Rwtg1rzg7e/ X-Google-Smtp-Source: APiQypJXJNEDjnXvxoxl/55gotG0f2jHRvoKAQlg+Ap/uoeQIwlR5mebUgjpTdjde8nWPTOnwUBhdQ== X-Received: by 2002:a2e:760c:: with SMTP id r12mr1502937ljc.139.1588238223120; Thu, 30 Apr 2020 02:17:03 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-98-128-181-7.NA.cust.bahnhof.se. [98.128.181.7]) by smtp.gmail.com with ESMTPSA id x29sm4417818lfn.64.2020.04.30.02.17.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Apr 2020 02:17:02 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Adrian Hunter , Douglas Anderson , Matthias Kaehlcke , Shawn Lin , Yong Mao , Chaotian Jing Subject: [PATCH 3/4] mmc: sdio: Re-use negotiated OCR mask when re-sending CMD8 Date: Thu, 30 Apr 2020 11:16:39 +0200 Message-Id: <20200430091640.455-4-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200430091640.455-1-ulf.hansson@linaro.org> References: <20200430091640.455-1-ulf.hansson@linaro.org> MIME-Version: 1.0 While initializing an SDIO card in mmc_sdio_init_card(), we may need to retry the UHS-I specific initialization, in case the first attempt fails. This leads to resending a CMD8, but also to restart from scratch with the so called OCR mask negotiations. This is unnecessary as we already have a negotiated OCR mask, so let's use that instead. In this way, the behaviour also becomes more consistent with other similar paths. Signed-off-by: Ulf Hansson --- drivers/mmc/core/sdio.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) -- 2.20.1 diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c index 20eed28ea60d..853ac65f0485 100644 --- a/drivers/mmc/core/sdio.c +++ b/drivers/mmc/core/sdio.c @@ -543,12 +543,12 @@ static int mmc_sdio_init_uhs_card(struct mmc_card *card) return err; } -static void mmc_sdio_resend_if_cond(struct mmc_host *host, +static void mmc_sdio_resend_if_cond(struct mmc_host *host, u32 ocr, struct mmc_card *card) { sdio_reset(host); mmc_go_idle(host); - mmc_send_if_cond(host, host->ocr_avail); + mmc_send_if_cond(host, ocr); mmc_remove_card(card); } @@ -640,7 +640,7 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr, if (rocr & ocr & R4_18V_PRESENT) { err = mmc_set_uhs_voltage(host, ocr_card); if (err == -EAGAIN) { - mmc_sdio_resend_if_cond(host, card); + mmc_sdio_resend_if_cond(host, ocr_card, card); retries--; goto try_again; } else if (err) { @@ -712,7 +712,7 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr, */ err = sdio_read_cccr(card, ocr); if (err) { - mmc_sdio_resend_if_cond(host, card); + mmc_sdio_resend_if_cond(host, ocr_card, card); if (ocr & R4_18V_PRESENT) { /* Retry init sequence, but without R4_18V_PRESENT. */ retries = 0; From patchwork Thu Apr 30 09:16:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 185885 Delivered-To: patches@linaro.org Received: by 2002:a92:3d9a:0:0:0:0:0 with SMTP id k26csp1839187ilf; Thu, 30 Apr 2020 02:17:06 -0700 (PDT) X-Received: by 2002:a2e:2a82:: with SMTP id q124mr1625273ljq.155.1588238226353; Thu, 30 Apr 2020 02:17:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588238226; cv=none; d=google.com; s=arc-20160816; b=HBvIvfzUJtcvbYrdatqLQUiQMZYuHz8RvkFHUBl91mjJYwbiXMEBi/ccpG8guIHUSw MI5K67zwIV9apjI/b5y2YxdPn+8r7L5REFYEoI34ds7yq3+RPe079qTBdVDxxQkL4FDh XHZO7AGSylARz8bbuRa/cS2weDea10xiNEEF+YvjrI7wb4H7ptF0Xlzpg4yZL2hh6VzB ukU+8jKwkWfQWSrE6gRX5b30VIKp6vGyaz0K96yIAHrRynCyYcnTawntqfUn6UUQGvat tkdMLhA9M3iujuViG8WaIfSkVUDjtdIqHqXO3y7lIFG+KKXGxT2rhLrm7jONbuNHZ+eq w9tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=Ff43pht+qFHl5p036giswtCScSev0q0blJQXIZAKC20=; b=edN9HRSE/pIat+fO+m+HG8cnI0pYkZ5lOI62cytot3YFqOY47GASSy+FCALi5BsmD1 kFPMSlFesFlmhekGCvodEinZ5UsLLGXxT23FoF1jQbJUcEvMonL/9D3/zP/efqCy/lS7 qN5wQ81d3TqqhFsoB6uLmu2rz/jLEAKYp5dToE0HF26/4RqX+ZiXxWaIPvecyzmiy608 auD1Myqv6Odk6WY82WE9DQGy1q2BhZ/6O1tetCRhhC/8Jxn9rXnt/yMjmnawHcgwvLBZ GXGJBoNQxPNSznUD6Ls3WjinXODw0yXRmGDi4MNEaLjctF/JNFUmuX6BaRtrNJCsVMcu qhNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Og8/7JTJ"; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id b16sor3662656ljk.10.2020.04.30.02.17.06 for (Google Transport Security); Thu, 30 Apr 2020 02:17:06 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Og8/7JTJ"; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ff43pht+qFHl5p036giswtCScSev0q0blJQXIZAKC20=; b=Og8/7JTJYJemv2CsNUPSFYiakr+xBKDCkgdArRX5Xqf35BpVUW/YTXupVdJW7jepfl hemhXC/stNJ6O0+mecD9PPxCkdboCy2YVdazPoDE+VCy6Eu+mIRVWgL+4pPHUoU1gMLn /k/a5OJZBXk0ZSHQqEljU7pfPnb6JkEuoLY/uKj41xmUjQYu3pt3XbaMqUQTXv4qYQsQ MXYKcGgCOijeKWwGWzCXWy0n+phZinbiR1QSgqVQ0z3rXkP8dpg+qLmPJFuXCVha8ZSS 0m+I2G0mrv7jsuOiP0zjy4g10oRfkMdM7Ei6yyMpXbglrPvczNFdn2+32+FCNIc1Dgdg 9OMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ff43pht+qFHl5p036giswtCScSev0q0blJQXIZAKC20=; b=dH2Zc01BuX7a3eGQUXNK52PlWitiS7aLKaHXGBylr2VttdICiD++5L38jEkL/xrNqU saRFpjGEX9HppBA36gdNJNiBAT61f4fYgISshOn9UcVqRpaksSTtx41AVrT9spBiRn2O ynJSCsi2EJJ9Y1qUdVTZ/x5FPQ9gM2yjzmj2OdFa7zya4qiuhpFuhI/428mwqUi8CbyJ Re1co/2NisSrtNe+v0lE/n5YCyVUnBj/0Z/prlfajz6hd9GhVd9vnwJVQH6cRTEHg3Xz 30BrvsQtS4TcRawKeepynwXATKXHbAOX09nos15BP5meT7ggg71LoxKmLBn5yYfURKDC HkFA== X-Gm-Message-State: AGi0Puakut+BsAtOVBi30Hgnbwo4/MeWnMoRZk3L+imd3Fi9plS7F5Zb 4CPYSKG8yFx+fx5W5YZWbfN0U6ai X-Google-Smtp-Source: APiQypI4IAdq5+e05nE8kgL8WQZa2DSx7F72JWKaL9wKVw6y33UQxZsjKluwOrxRzqWBKQ6Pn7r7Uw== X-Received: by 2002:a2e:9791:: with SMTP id y17mr1631612lji.174.1588238225886; Thu, 30 Apr 2020 02:17:05 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-98-128-181-7.NA.cust.bahnhof.se. [98.128.181.7]) by smtp.gmail.com with ESMTPSA id x29sm4417818lfn.64.2020.04.30.02.17.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Apr 2020 02:17:05 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Adrian Hunter , Douglas Anderson , Matthias Kaehlcke , Shawn Lin , Yong Mao , Chaotian Jing Subject: [PATCH 4/4] mmc: sdio: Align the initialization commands in retry path for UHS-I Date: Thu, 30 Apr 2020 11:16:40 +0200 Message-Id: <20200430091640.455-5-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200430091640.455-1-ulf.hansson@linaro.org> References: <20200430091640.455-1-ulf.hansson@linaro.org> MIME-Version: 1.0 According to the comment in mmc_sdio_reinit_card(), some SDIO cards may require a "[CMD5,5,3,7] init sequence", which isn't always obeyed in mmc_sdio_init_card(). Especially, when we end up retrying the UHS-I specific initialization, there is a missing CMD5. Let's update the code to make the behaviour consistent and let's also take the opportunity to clean up the code a bit, to avoid open coding. Signed-off-by: Ulf Hansson --- drivers/mmc/core/sdio.c | 53 ++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 27 deletions(-) -- 2.20.1 diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c index 853ac65f0485..435de47a6ee0 100644 --- a/drivers/mmc/core/sdio.c +++ b/drivers/mmc/core/sdio.c @@ -543,13 +543,33 @@ static int mmc_sdio_init_uhs_card(struct mmc_card *card) return err; } -static void mmc_sdio_resend_if_cond(struct mmc_host *host, u32 ocr, - struct mmc_card *card) +static int mmc_sdio_pre_init(struct mmc_host *host, u32 ocr, + struct mmc_card *card) { + if (card) + mmc_remove_card(card); + + /* + * Reset the card by performing the same steps that are taken by + * mmc_rescan_try_freq() and mmc_attach_sdio() during a "normal" probe. + * + * sdio_reset() is technically not needed. Having just powered up the + * hardware, it should already be in reset state. However, some + * platforms (such as SD8686 on OLPC) do not instantly cut power, + * meaning that a reset is required when restoring power soon after + * powering off. It is harmless in other cases. + * + * The CMD5 reset (mmc_send_io_op_cond()), according to the SDIO spec, + * is not necessary for non-removable cards. However, it is required + * for OLPC SD8686 (which expects a [CMD5,5,3,7] init sequence), and + * harmless in other situations. + * + */ + sdio_reset(host); mmc_go_idle(host); mmc_send_if_cond(host, ocr); - mmc_remove_card(card); + return mmc_send_io_op_cond(host, 0, NULL); } /* @@ -640,7 +660,7 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr, if (rocr & ocr & R4_18V_PRESENT) { err = mmc_set_uhs_voltage(host, ocr_card); if (err == -EAGAIN) { - mmc_sdio_resend_if_cond(host, ocr_card, card); + mmc_sdio_pre_init(host, ocr_card, card); retries--; goto try_again; } else if (err) { @@ -712,7 +732,7 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr, */ err = sdio_read_cccr(card, ocr); if (err) { - mmc_sdio_resend_if_cond(host, ocr_card, card); + mmc_sdio_pre_init(host, ocr_card, card); if (ocr & R4_18V_PRESENT) { /* Retry init sequence, but without R4_18V_PRESENT. */ retries = 0; @@ -813,28 +833,7 @@ static int mmc_sdio_reinit_card(struct mmc_host *host) { int ret; - /* - * Reset the card by performing the same steps that are taken by - * mmc_rescan_try_freq() and mmc_attach_sdio() during a "normal" probe. - * - * sdio_reset() is technically not needed. Having just powered up the - * hardware, it should already be in reset state. However, some - * platforms (such as SD8686 on OLPC) do not instantly cut power, - * meaning that a reset is required when restoring power soon after - * powering off. It is harmless in other cases. - * - * The CMD5 reset (mmc_send_io_op_cond()), according to the SDIO spec, - * is not necessary for non-removable cards. However, it is required - * for OLPC SD8686 (which expects a [CMD5,5,3,7] init sequence), and - * harmless in other situations. - * - */ - - sdio_reset(host); - mmc_go_idle(host); - mmc_send_if_cond(host, host->card->ocr); - - ret = mmc_send_io_op_cond(host, 0, NULL); + ret = mmc_sdio_pre_init(host, host->card->ocr, NULL); if (ret) return ret;