Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2453502imu; Thu, 10 Jan 2019 14:34:39 -0800 (PST) X-Google-Smtp-Source: ALg8bN5zYi6Awx1r3FwqHJqu8DVooJhw6BNa1V7GnOvpC9x6nqOjObn63LbFa6zO4npEnOUKj8ys X-Received: by 2002:a63:6150:: with SMTP id v77mr10829073pgb.266.1547159679883; Thu, 10 Jan 2019 14:34:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547159679; cv=none; d=google.com; s=arc-20160816; b=SqJ8J9do98ye9OAbX4+xFnCsTs9ZWySX/0DlO0mRJIqtZMoUG226UrfnCLYe3W6tcs OFJkl3HO5hN9qQ7mZvpqM0x6hSEsDoaYnnMjxXwac+I3wIczXcimkevs3GGrErJHuHBC wTVi966Gn/daG46TNxmpZE0kqG1VjYV0sn7FUsJPzEBhOt8cao5vou4qNKey6rqSXzwZ 4ldvSSzd9B5iB1SGJrcjnIUcNBCusJJ26eAlvJFYVSNYtm6rBeQBfAT0lMdeIsAykVkK b+w0m9rTnWm/lUm0EXljcQ7nkdQoeOZrhhhxDwbgOXqvOSS4GLwmcj4kjGUmNf9DGI3+ VsuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=U3HCQlu52kLavno/YB+dfn90fwFxF0gMqTd49DNwwMw=; b=X4pOPXrOQyWfCQc6EhC49Tp3lbn5LLGHKMg2Ykvg6DzDHQYRlQKHLbCiQRHb9iIUr/ XQQPZaAWNWMwPkY7iWAmRxJsF8MVTt1rey1d07jPUnZyrYwDwbdrrHnOmzyLhHM41C87 s5Tl3TA1DDZBxihT6GgQ64k6zFVxRJebhkGFZmOe9AprWQLuzlqFnlOXpVvx6NHLMThB bzMzVoD2QdwdqlCvrbzlzcTEDdyVvA6wWMhD1VaQ2EefNQNdeghdov2tZR9jmsVduwfX sAd3BTgwpFRcgJmrAQSifW05HfojjIz0ufiPSYNpWZM8cndHOT8iI3BhFZnEEXb27X5U Aphw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w11si28171137pfk.210.2019.01.10.14.34.24; Thu, 10 Jan 2019 14:34:39 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728275AbfAJSk2 (ORCPT + 99 others); Thu, 10 Jan 2019 13:40:28 -0500 Received: from relay5-d.mail.gandi.net ([217.70.183.197]:52839 "EHLO relay5-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727737AbfAJSk2 (ORCPT ); Thu, 10 Jan 2019 13:40:28 -0500 X-Originating-IP: 88.190.179.123 Received: from localhost (unknown [88.190.179.123]) (Authenticated sender: repk@triplefau.lt) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 830221C0007; Thu, 10 Jan 2019 18:40:24 +0000 (UTC) From: Remi Pommarel To: Ulf Hansson , Kevin Hilman Cc: Elie Roudninski , linux-mmc@vger.kernel.org, linux-amlogic@lists.infradead.org, linux-kernel@vger.kernel.org, Remi Pommarel Subject: [PATCH] mmc: meson-gx: Free irq in release() callback Date: Thu, 10 Jan 2019 19:49:08 +0100 Message-Id: <20190110184908.27413-1-repk@triplefau.lt> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Because the irq was requested through device managed resources API (devm_request_threaded_irq()) it was freed after meson_mmc_remove() completion, thus after mmc_free_host() has reclaimed meson_host memory. As this irq is IRQF_SHARED, while using CONFIG_DEBUG_SHIRQ, its handler get called by free_irq(). So meson_mmc_irq() was called after the meson_host memory reclamation and was using invalid memory. We ended up with the following scenario: device_release_driver() meson_mmc_remove() mmc_free_host() /* Freeing host memory */ ... devres_release_all() devm_irq_release() __free_irq() meson_mmc_irq() /* Uses freed memory */ To avoid this, the irq is released in meson_mmc_remove() before mmc_free_host() gets called. This fixes https://marc.info/?l=linux-mmc&m=154707415208716. Signed-off-by: Remi Pommarel --- drivers/mmc/host/meson-gx-mmc.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/mmc/host/meson-gx-mmc.c b/drivers/mmc/host/meson-gx-mmc.c index c2690c1a50ff..412cfd16bf15 100644 --- a/drivers/mmc/host/meson-gx-mmc.c +++ b/drivers/mmc/host/meson-gx-mmc.c @@ -179,6 +179,8 @@ struct meson_host { struct sd_emmc_desc *descs; dma_addr_t descs_dma_addr; + int irq; + bool vqmmc_enabled; }; @@ -1231,7 +1233,7 @@ static int meson_mmc_probe(struct platform_device *pdev) struct resource *res; struct meson_host *host; struct mmc_host *mmc; - int ret, irq; + int ret; mmc = mmc_alloc_host(sizeof(struct meson_host), &pdev->dev); if (!mmc) @@ -1276,8 +1278,8 @@ static int meson_mmc_probe(struct platform_device *pdev) goto free_host; } - irq = platform_get_irq(pdev, 0); - if (irq <= 0) { + host->irq = platform_get_irq(pdev, 0); + if (host->irq <= 0) { dev_err(&pdev->dev, "failed to get interrupt resource.\n"); ret = -EINVAL; goto free_host; @@ -1331,9 +1333,8 @@ static int meson_mmc_probe(struct platform_device *pdev) writel(IRQ_CRC_ERR | IRQ_TIMEOUTS | IRQ_END_OF_CHAIN, host->regs + SD_EMMC_IRQ_EN); - ret = devm_request_threaded_irq(&pdev->dev, irq, meson_mmc_irq, - meson_mmc_irq_thread, IRQF_SHARED, - NULL, host); + ret = devm_request_threaded_irq(&pdev->dev, host->irq, meson_mmc_irq, + meson_mmc_irq_thread, IRQF_SHARED, NULL, host); if (ret) goto err_init_clk; @@ -1387,6 +1388,7 @@ static int meson_mmc_remove(struct platform_device *pdev) /* disable interrupts */ writel(0, host->regs + SD_EMMC_IRQ_EN); + devm_free_irq(host->dev, host->irq, host); dma_free_coherent(host->dev, SD_EMMC_DESC_BUF_LEN, host->descs, host->descs_dma_addr); -- 2.20.1