From patchwork Wed Mar 3 12:20:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 392060 Delivered-To: patches@linaro.org Received: by 2002:a02:290e:0:0:0:0:0 with SMTP id p14csp5078145jap; Wed, 3 Mar 2021 04:20:58 -0800 (PST) X-Received: by 2002:a19:4942:: with SMTP id l2mr14626250lfj.95.1614774058785; Wed, 03 Mar 2021 04:20:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614774058; cv=none; d=google.com; s=arc-20160816; b=eMYshs8JPNlrBGA75b45GbWdkwW0kkvd9eeNaJcghCCzjceqSIp8VpcnGxilRV2oXC Jv7ZGS2whpO8SqhqDNRpjK5R9HhkviVsq7iwoFbjaQm9+/bM7fayGCTNpADgrEc2PrCw OpGkVuRRBcyqKS+hP+lo3gUWh9+ajRbkQSk9Ttb1cqSMwj8yz8Q4PyWDdJlXnmP/Rtb5 EHSY02NSQvdzoSIacbpKuAmR7qTBDo11093t48zm6CcUf86pSKmKoU67zEVlntrbOm92 6QU2q8bzusuUI6hEDFDbu7kyJV/Nna7SnOp+hEykJuS52FTf0kmgam2cumkMSsSvEL99 YS/Q== 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=lD9APgZ2jhcnYCgOIeOpXqVPb3v1Goo0x0OpO8dXVPQ=; b=xwk/9AKPEFPJENX+rSNjfvkHMtFj6G6Y48ycSJ7vWupknHSzv0KJ77lUO7Fsunie/m ZkXgbfTpZ6OrjilxW40uaqskiMtc3x+wQeub6h50/1ebTAeIc/kw098ZvkeEXkikMFUq SuXlO1n1dSJ7YtH37ObGs8xGtO0qKYvZf6xRYKaF3S3n3QIKdB8So91ov0yqaQzkvv6x o80FR2Ozj0M7/iA0C8MpLwpuStNtRbJhL1tVVaP+0d/a+PYx4Roe3lOZe33F27Xcjv9D fmBXk4E5XaLp7JBl7cjxKZW9Ikaua4FSc4I60RZ/CUTgpQe92CDRbLgkGCebYbbj7Uyt HHhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=esW4B307; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 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-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id n4sor192403lfq.85.2021.03.03.04.20.58 for (Google Transport Security); Wed, 03 Mar 2021 04:20:58 -0800 (PST) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=esW4B307; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 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=lD9APgZ2jhcnYCgOIeOpXqVPb3v1Goo0x0OpO8dXVPQ=; b=esW4B307jxAwSGPOl0hNyuol71pvJKogmDuDaPA54yUJHJrM3nvwlFIuL76Nlwalq/ JWvdwuMpCdt6kJxkcvncGDud3z4yWyIU7w7upwmK2SfZ8BzGT4KxzUKEwDLGDK4NgMBD Dyg1n8aN5Bf+NI2Gdd8qNo7LLBPs+v6oYG77/Md9QOtMh0VmEoXipcjlg9v1keeTWI46 XvKBEgV5v/mm1zCgpyBcHhed7kEXdyNW3s2Jv8amuGzPWPI8sZgu6I/H3mVejToMTd4Y egFkwDlKjBvoQ9mGdiauhpLF9mOAnYEL69HP+kh6FlQivqEqHerwiqVP3RpLgece0tU8 1M+Q== 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=lD9APgZ2jhcnYCgOIeOpXqVPb3v1Goo0x0OpO8dXVPQ=; b=GklRYjmiBuA2BvhVr4R4U0817TNrDKUdSp8y4gBdSJVFNZDQHBhCZTcS/PZoLelnkh WG1X9iiRQ/tSVYv/JfRXynljoMpFBD8qawUJE0gp2udca6nU7l74qsyT8y9XCHr9Iyek GyV7zilZvOb3jLlvyhxfR3dmBj/cwIMrA2XMXhHxzaK/kBYsPb/3gyzZU8XAD3hJrkOe cTQXBNeVGEI+tTLz7eWfWQrOqXMnkArPlvUOuxUi642vfqrL4mZMDDKLHrNoQHSiBdvr wHwfTIPramBAmp+bEOerTqeh0NDjDiovOoPzDCps+7AGfj6CE/B69Z7xatmZ86C2NS2j VCYg== X-Gm-Message-State: AOAM532M8V69YaT/oiCKFjfYqchd2PZFpbdAJfCbLhqt5kill31RS0Px B+EdSKU6mx14E9+EgtnLq4KgCXsTgEQ4lbjC X-Google-Smtp-Source: ABdhPJz3ZN1+8FheWJZpyLBpnGV/RnMW3VOVx9DzzJOy9r0WPzdCqF3RuL4kdnjCbeNNFO44GRKE7w== X-Received: by 2002:a05:6512:3055:: with SMTP id b21mr14618790lfb.356.1614774058409; Wed, 03 Mar 2021 04:20:58 -0800 (PST) Return-Path: Received: from localhost.localdomain (h-155-4-129-234.NA.cust.bahnhof.se. [155.4.129.234]) by smtp.gmail.com with ESMTPSA id d3sm811519lfq.249.2021.03.03.04.20.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Mar 2021 04:20:57 -0800 (PST) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Adrian Hunter , linux-kernel@vger.kernel.org Subject: [PATCH 3/3] mmc: block: Fix error path in mmc_blk_probe() Date: Wed, 3 Mar 2021 13:20:49 +0100 Message-Id: <20210303122049.151986-4-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210303122049.151986-1-ulf.hansson@linaro.org> References: <20210303122049.151986-1-ulf.hansson@linaro.org> MIME-Version: 1.0 Returning zero to indicate success, when we actually have failed to probe is wrong. As a matter of fact, it leads to that mmc_blk_remove() gets called at a card removal and then triggers "NULL pointer dereference" splats. This is because mmc_blk_remove() relies on data structures and pointers to be setup from mmc_blk_probe(), of course. There have been no errors reported about this, which is most likely because mmc_blk_probe() never fails like this. Nevertheless, let's fix the code by propagating the error codes correctly and prevent us from leaking memory by calling also destroy_workqueue() in the error path. Signed-off-by: Ulf Hansson --- drivers/mmc/core/block.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) -- 2.25.1 diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index 39308b35a1fb..02b656305042 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -2876,6 +2876,7 @@ static void mmc_blk_remove_debugfs(struct mmc_card *card, static int mmc_blk_probe(struct mmc_card *card) { struct mmc_blk_data *md, *part_md; + int ret = 0; /* * Check that the card supports the command class(es) we need. @@ -2893,19 +2894,24 @@ static int mmc_blk_probe(struct mmc_card *card) } md = mmc_blk_alloc(card); - if (IS_ERR(md)) - return PTR_ERR(md); + if (IS_ERR(md)) { + ret = PTR_ERR(md); + goto out_free; + } - if (mmc_blk_alloc_parts(card, md)) + ret = mmc_blk_alloc_parts(card, md); + if (ret) goto out; dev_set_drvdata(&card->dev, md); - if (mmc_add_disk(md)) + ret = mmc_add_disk(md); + if (ret) goto out; list_for_each_entry(part_md, &md->part, part) { - if (mmc_add_disk(part_md)) + ret = mmc_add_disk(part_md); + if (ret) goto out; } @@ -2926,10 +2932,12 @@ static int mmc_blk_probe(struct mmc_card *card) return 0; - out: +out: mmc_blk_remove_parts(card, md); mmc_blk_remove_req(md); - return 0; +out_free: + destroy_workqueue(card->complete_wq); + return ret; } static void mmc_blk_remove(struct mmc_card *card)