Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3475721imu; Mon, 14 Jan 2019 03:47:22 -0800 (PST) X-Google-Smtp-Source: ALg8bN5IXVDm+ZouA7KDceQvb3zhcEd5JRNE/yCT0qA5gDnafwz47BBhgabR8Cq4+DGMJG/uici4 X-Received: by 2002:a62:c21c:: with SMTP id l28mr24728368pfg.74.1547466442013; Mon, 14 Jan 2019 03:47:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547466442; cv=none; d=google.com; s=arc-20160816; b=g4h9e/1KG+PsDYFNC/9IjWZsXYLZQbfRT3LEKijRlM1/oSto7LiSfp4vOobzB7RqBT XUbOadepYaCxAR++t0uLn1neiHLRkEWafxNNS5+GvU8w4AOWTqA88HMVBS/+jLNaH4lY rirFhzir2ishvLUCc2hKmjoj2Wb8m29ZK4wbLfELaZuQ+9+giaGXFfGRfkMcrEgrX6mF xaX6XeeO9AfcOdPlK5Ms7ZK7Xl+KCDxQTmuhUqZaHsP+r8Vr8KXGfUTJe02Tyaha3va0 7C7gdqISe4QgRrF7dvMvch9pwxg3xoeLkIlsPM2wsPpSikiI46QZpAH3wbchN9QqBQcy DXBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=N5GvtAoNZhHeEA8ikbHXVTVTkT55HDIL3P0c9+r9xsI=; b=O6OOZu7fgPtFnqPgSn5BMo7Mhx6VYZaShv238tFIFlMgkdO78DELJ+Ycm/VqSz3Kai tRFfMTjzT7vnq2ffhLYxwsEB/BcKKPsZMyiaBsSE5I6UoLFSAFVjY92BIUpR1wYgOh3e SBGTjKHbYGNDA2RI/gGAf0ZVxppJGFptnOXUTuw3Gqa+HiqOJEwzudMCm1oikBAUoKKy bgffheyw70d1zRFRZIQitWyy7vodzh75pPwc+7vn4Vn+XBcnYggecqM4jP8SwH07OXMN IeY9gO0bCHU+cqkahEtdu+qAQOL+EHMZBKHJWnIbfqyict+pkiMhGJBAbIOvncSGtmrV ZRTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KefybJFj; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 62si178090plc.87.2019.01.14.03.47.06; Mon, 14 Jan 2019 03:47:21 -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; dkim=pass header.i=@linaro.org header.s=google header.b=KefybJFj; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726823AbfANLpr (ORCPT + 99 others); Mon, 14 Jan 2019 06:45:47 -0500 Received: from mail-vk1-f193.google.com ([209.85.221.193]:33224 "EHLO mail-vk1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726339AbfANLpo (ORCPT ); Mon, 14 Jan 2019 06:45:44 -0500 Received: by mail-vk1-f193.google.com with SMTP id d201so4790261vka.0 for ; Mon, 14 Jan 2019 03:45:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=N5GvtAoNZhHeEA8ikbHXVTVTkT55HDIL3P0c9+r9xsI=; b=KefybJFjQ5uTsZA+RPmXnykbQPKiSXuF4LGHDS/hMoWeJMOmoe3DJe3pFiGJg8T5g0 No+u54vx9Vzq8d2qBPZZ03Nw5wd3zKnC6KLVN3FlAtxocK9qSH8ujnTyZU49t42YWKPU PVW69dcND6nwDPotgLqQFdp6sa17B2sMP6Pbc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=N5GvtAoNZhHeEA8ikbHXVTVTkT55HDIL3P0c9+r9xsI=; b=WJpN5xHKv/y6GFcQDYAOA8njIIRaZ6yrymt31hdzVBEYC32YJeRkO255N2o7A1Ga5/ pftXj62rkqg1sgNIDO8QLvjIbrBKLh9gbDU5pkHI8YiQYiNALgcYkbLkZJ2Wl5aQwUvZ lKhK7DIB09j9PoOP1nl7I0pquFuuSe/S6DT4yWwolCx7WjnkCaocGsFuXuS/vncgUU8X aGZ2N6ENGKf5wZWUIXhWIZvtusgY5xGft4riNYq/Z+WxCIUvg1RRwzn5cGGGkbqSRAgN b8v3ciMnYm9/KKPyDGotTepHyD7F52r6olh+c/SqZxN8EBnV5ncuqn/je1u9ZmvnUzuf 7BGQ== X-Gm-Message-State: AJcUukeNQ07MqnJ+JgJq3YkmfgITH1x5+iEf0R3RptWo5FaPYXuJHqE2 aJbmL63s9JWXVPhfAEEhGgO7P9aRntcQbsAeLHkMlA== X-Received: by 2002:a1f:298e:: with SMTP id p136mr9453367vkp.40.1547466343611; Mon, 14 Jan 2019 03:45:43 -0800 (PST) MIME-Version: 1.0 References: <20190110230135.19555-1-repk@triplefau.lt> In-Reply-To: <20190110230135.19555-1-repk@triplefau.lt> From: Ulf Hansson Date: Mon, 14 Jan 2019 12:45:07 +0100 Message-ID: Subject: Re: [PATCH v2] mmc: meson-gx: Free irq in release() callback To: Remi Pommarel Cc: Kevin Hilman , Elie Roudninski , "linux-mmc@vger.kernel.org" , "open list:ARM/Amlogic Meson..." , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 10 Jan 2019 at 23:52, Remi Pommarel wrote: > > 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() and in > mseon_mmc_probe() error path before mmc_free_host() gets called. > > This fixes https://marc.info/?l=linux-mmc&m=154707415208716. > > Signed-off-by: Remi Pommarel Applied for fixes! I also added a stable tag and a reported-by tag from Elie, thanks! Kind regards Uffe > --- > Changes since v1: > - Fix it also in the error handling of probe callback > --- > drivers/mmc/host/meson-gx-mmc.c | 18 +++++++++++------- > 1 file changed, 11 insertions(+), 7 deletions(-) > > diff --git a/drivers/mmc/host/meson-gx-mmc.c b/drivers/mmc/host/meson-gx-mmc.c > index c2690c1a50ff..f115d7c63ffe 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 = request_threaded_irq(host->irq, meson_mmc_irq, > + meson_mmc_irq_thread, IRQF_SHARED, NULL, host); > if (ret) > goto err_init_clk; > > @@ -1351,7 +1352,7 @@ static int meson_mmc_probe(struct platform_device *pdev) > if (host->bounce_buf == NULL) { > dev_err(host->dev, "Unable to map allocate DMA bounce buffer.\n"); > ret = -ENOMEM; > - goto err_init_clk; > + goto err_free_irq; > } > > host->descs = dma_alloc_coherent(host->dev, SD_EMMC_DESC_BUF_LEN, > @@ -1370,6 +1371,8 @@ static int meson_mmc_probe(struct platform_device *pdev) > err_bounce_buf: > dma_free_coherent(host->dev, host->bounce_buf_size, > host->bounce_buf, host->bounce_dma_addr); > +err_free_irq: > + free_irq(host->irq, host); > err_init_clk: > clk_disable_unprepare(host->mmc_clk); > err_core_clk: > @@ -1387,6 +1390,7 @@ static int meson_mmc_remove(struct platform_device *pdev) > > /* disable interrupts */ > writel(0, host->regs + SD_EMMC_IRQ_EN); > + free_irq(host->irq, host); > > dma_free_coherent(host->dev, SD_EMMC_DESC_BUF_LEN, > host->descs, host->descs_dma_addr); > -- > 2.20.1 >