Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3515710pxf; Mon, 15 Mar 2021 11:15:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTEze9EF2gQgXLokKZq1EA9r/CZqTbT1nHDa4tqUVg8bVQ+MmCXue6QuGtufNZYVRmskWJ X-Received: by 2002:a17:906:ef2:: with SMTP id x18mr25636316eji.323.1615832140240; Mon, 15 Mar 2021 11:15:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615832140; cv=none; d=google.com; s=arc-20160816; b=kdKtgfUuhDUIcY54URXT5CmRrveL5hZuuncuSAmLvXCqoh5lPHGuGOG294pOEoDm8+ RhV3EHf56eSVieD6mLcPmOGs5P6QYF+zcgz22rJZZ15b4Uh0RXRfQCsQ4o3tjFIZWDS2 M9vA04vo09M0zqIfAj889TlpLJdgzdoZA8YKBj4tQzeE4ZkoSSUj12f5oGJEGXVOMGrG dWEZY+g2JxrfH6Yip72qNu5iTEHyTYSkOWV1OB0IqXW7bJTqaEMEpx/fwVtOrNUzl+Uo lb0udZpthB8JgWxpeqiun13s4MCVeoKW6R8KhzmHFeGkMJM76a1BijGK7FcWbpSTdc4R Tj5Q== 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=W6al/hF0iy997SomHkNPrFOHITMN+lgsjuEaclvWouM=; b=qoA6rJbwHOMYGJthbjnwscsnpsc7FuXJfceOBvdMoZ68YZzUu32idD4x5yo3xu99tg IiZTlb/YX1syaYzv0+aaGLFcxFKz1damhP040Am1SmI6KdXFPqKOUFkf4+VYSYLxgO1M chA22VkjuGzVcRkc4K+8oWXrsIy8K1YFkynt3eFVRmGKxuMql9GvU+hvyBOEd/JvQbUg WeDMx4RiQ1y6FZ1Vccllq8DmAo8Ny7X4/gJR8OzNeaYdTjRGCGYOsIrOI0Kturx2RVjZ 3q2uiYU13EBRohVzG+Smq7vNy/ZeiqTP/RWWcd8EeWMYL4HnO8eyalBUT4Lc3hdy0mbB UJig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KeBTg1fI; 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 j7si11631818ejc.237.2021.03.15.11.15.18; Mon, 15 Mar 2021 11:15:40 -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=KeBTg1fI; 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 S231724AbhCOOOl (ORCPT + 99 others); Mon, 15 Mar 2021 10:14:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:37540 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230425AbhCON7L (ORCPT ); Mon, 15 Mar 2021 09:59:11 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9583664F1E; Mon, 15 Mar 2021 13:58:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816719; bh=SeEx1BCJOUjqxYPZYyrkBUe9IDEKTvgxx0uGP38XcnU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KeBTg1fI2FnEEKbpt8dd9uOsJzvPjgM2mmrOMjMaPwFdptKCPij3oHcbPs4Uq/CYw EfOsD3y1GUqIxNhLitEo2idfeZt7jBkJNv4RWthehrdrqLfCPybgsqkZxBFPZAlAuN iRExAXhg8g6+ZDbu615IXT5AF7tphslpLDMELPk8= From: gregkh@linuxfoundation.org To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chaotian Jing , Ulf Hansson , Sasha Levin Subject: [PATCH 5.4 066/168] mmc: mediatek: fix race condition between msdc_request_timeout and irq Date: Mon, 15 Mar 2021 14:54:58 +0100 Message-Id: <20210315135552.537435625@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135550.333963635@linuxfoundation.org> References: <20210315135550.333963635@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: Greg Kroah-Hartman From: Chaotian Jing [ Upstream commit 0354ca6edd464a2cf332f390581977b8699ed081 ] when get request SW timeout, if CMD/DAT xfer done irq coming right now, then there is race between the msdc_request_timeout work and irq handler, and the host->cmd and host->data may set to NULL in irq handler. also, current flow ensure that only one path can go to msdc_request_done(), so no need check the return value of cancel_delayed_work(). Signed-off-by: Chaotian Jing Link: https://lore.kernel.org/r/20201218071611.12276-1-chaotian.jing@mediatek.com Signed-off-by: Ulf Hansson Signed-off-by: Sasha Levin --- drivers/mmc/host/mtk-sd.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/drivers/mmc/host/mtk-sd.c b/drivers/mmc/host/mtk-sd.c index 9d47a2bd2546..1254a5650cff 100644 --- a/drivers/mmc/host/mtk-sd.c +++ b/drivers/mmc/host/mtk-sd.c @@ -1020,13 +1020,13 @@ static void msdc_track_cmd_data(struct msdc_host *host, static void msdc_request_done(struct msdc_host *host, struct mmc_request *mrq) { unsigned long flags; - bool ret; - ret = cancel_delayed_work(&host->req_timeout); - if (!ret) { - /* delay work already running */ - return; - } + /* + * No need check the return value of cancel_delayed_work, as only ONE + * path will go here! + */ + cancel_delayed_work(&host->req_timeout); + spin_lock_irqsave(&host->lock, flags); host->mrq = NULL; spin_unlock_irqrestore(&host->lock, flags); @@ -1046,7 +1046,7 @@ static bool msdc_cmd_done(struct msdc_host *host, int events, bool done = false; bool sbc_error; unsigned long flags; - u32 *rsp = cmd->resp; + u32 *rsp; if (mrq->sbc && cmd == mrq->cmd && (events & (MSDC_INT_ACMDRDY | MSDC_INT_ACMDCRCERR @@ -1067,6 +1067,7 @@ static bool msdc_cmd_done(struct msdc_host *host, int events, if (done) return true; + rsp = cmd->resp; sdr_clr_bits(host->base + MSDC_INTEN, cmd_ints_mask); @@ -1254,7 +1255,7 @@ static void msdc_data_xfer_next(struct msdc_host *host, static bool msdc_data_xfer_done(struct msdc_host *host, u32 events, struct mmc_request *mrq, struct mmc_data *data) { - struct mmc_command *stop = data->stop; + struct mmc_command *stop; unsigned long flags; bool done; unsigned int check_data = events & @@ -1270,6 +1271,7 @@ static bool msdc_data_xfer_done(struct msdc_host *host, u32 events, if (done) return true; + stop = data->stop; if (check_data || (stop && stop->error)) { dev_dbg(host->dev, "DMA status: 0x%8X\n", -- 2.30.1