Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3518931pxf; Mon, 15 Mar 2021 11:20:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzJqBF5IfRvhnIvKyLzQ4scNziL2S7Vur6aX8KwLqoi5TwcdIMRTcgNtaBgIRa0swxS+i6N X-Received: by 2002:a05:6402:2058:: with SMTP id bc24mr31876494edb.243.1615832441177; Mon, 15 Mar 2021 11:20:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615832441; cv=none; d=google.com; s=arc-20160816; b=Gu4eGY/RzQiOokc0Bfmqy6uT5YW2foJCG3arSAph4BEvu9q+4G1gaY2sQ7hzmpSqcA 1k72qGMc+1MZd5j13ctOTOUaRMSf9KwfLmWTx5YJoNKuXOgd+R7IpqkL0HiNwU0CYxQ0 6CsmLAicXSy7D6i2aqwaGtMsmRT4NHV9H24iJlQBHFslRDZTvjYXgQw7BfVvDThDzmLs MCdg+awEswFvaJTQY+3IqaLCL62hkbuyVXB+fd/H0Y4SAm9JvVKZPWPDq7/c8zkQNqfD h9RGY3PXSlXKv81DfNWSPSx4KjCOR5fnb3SqH/aP6hYmHaLciTKKtJCIG0emZbC1Gq6L lj9w== 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=2RSn2FYzPOvyv6qGHJDkQbhDTjfL646FP0BTcb1z/tU=; b=od478skqbt9p7gDHep+8TG1+eI5qUiNVMKrTI6gtT2LTjg0FDz0kEgYtt8Ks5bhW/8 15PKy7kErXKTmdGYYjBiNdUa0TEQYotT/i3jGFQCim+G3xnuQY0BjlIY/TuaH2XpsFao rpRPbRanftQR96doVUKQc2Is/HMmzzL8UMDDD7roeKmnWt5miCpb/xLtuD6VMeGgRzrZ /rB3THrzdap/gvw8I5Ue4xqHcEY5/J4LETisu2LStU+j4K6m4MfSpOg8TBHHcUfiH4zq p8wKRp7TPMP+0d9l08XlrhH3sRRLD70ZIGNNpc7ckIZrMyDHALVXmBMtIv87L7BX3SlI cJ/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=znFUWBQ5; 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 ot6si12051747ejb.337.2021.03.15.11.20.18; Mon, 15 Mar 2021 11:20:41 -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=znFUWBQ5; 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 S237598AbhCOOTJ (ORCPT + 99 others); Mon, 15 Mar 2021 10:19:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:37632 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231286AbhCON7p (ORCPT ); Mon, 15 Mar 2021 09:59:45 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5C47F64F6D; Mon, 15 Mar 2021 13:59:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816751; bh=T5wvFzsGYzArj4n7CriyzkjOCCV3mQtkBavvzvnzmp0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=znFUWBQ5WwqBaWPMevMSVY85bTBdp0SyF+Bp3+YUMwfk2D6AXWSZqThgYex47P5S2 cEYSVA9ovt4BVz41VNKAQ3fQRkkI3J/gUZGnvsKGTcVJ1j6GPAYDxyuy7aXW76cH6s oj8n3HZnzSZJpdm/3AIMgHXVxjydGR+Scad3Dbg0= 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 4.19 045/120] mmc: mediatek: fix race condition between msdc_request_timeout and irq Date: Mon, 15 Mar 2021 14:56:36 +0100 Message-Id: <20210315135721.467709232@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135720.002213995@linuxfoundation.org> References: <20210315135720.002213995@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 9ecf86ba4bb0..967e47770af6 100644 --- a/drivers/mmc/host/mtk-sd.c +++ b/drivers/mmc/host/mtk-sd.c @@ -928,13 +928,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); @@ -952,7 +952,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 @@ -973,6 +973,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); @@ -1154,7 +1155,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 & @@ -1170,6 +1171,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