Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3523513pxf; Mon, 15 Mar 2021 11:27:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwdUgbL+qbRE91rsdfKSZpfuWbYYSnaFZAnRuj1U8WQi7a4igFGSPPKIE8pWU/htxfR8wlJ X-Received: by 2002:a17:906:ecf3:: with SMTP id qt19mr24806688ejb.467.1615832853414; Mon, 15 Mar 2021 11:27:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615832853; cv=none; d=google.com; s=arc-20160816; b=IwJwCv4bZrevHPpcynsJBcFCnyfs49UYr5Qq1LGI4ti77xWUtux9oAIcZrMW1pvLCj ++JnV73Zc3KagPiSRJmb0sa4VOOW/KZoig0dmfe6iYZMHBzPPsfGwCN+HbKNwRlvCqhv QeM6mRjX6rWALiff9/qcQbHUWpEBb5KTDq3o50bN+nWCso4GlAS9YMvgnVmdyYptfuDI NqItAcjWdEaarSb4mKZC+U92369I/oE097HNPn7LEUjuGbqipoF2s04jH7QQTZ70NaTP 8AywgUo5p3Bl7fpmXSPszfc1MSeAbJfrxd3D+Q3m2lHIBTTx2+XNsPQzIU2c77Me1gPo DdDg== 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=ZXNZ3hViJaG5PIlQkfG5tkDPr+GD4PouYyTgNS435k8=; b=VLpdQnyvJK+zIkE/Iri66BmGebL1fwF4MkkxFBydB+Hbx0O636mD10Y3gF6lnxjtAo UTqmc/Bj82nLx5t9gotUsRjSvJbEFuE/r0lQTLBarkiwfU9YBnLKQM2AyhPthMBoU9Yo PSbuhJDhKHfhTeZ+++2nECLGpQozG31Cqnts/Zv4l5gKJ+/GPcorJ9Cwu1YWbY89WJxZ 6XZQCsNpM+pZ/mYATnkcvAIECzewQUVVG4b3cNDRKxQelK1zFWi2D2E8HnsHJ/TFpbbh txdLbgDUvsCmE3fIx84M+DulLRjR1mZtt5OlwRYHYDmd7aU4R+HCMMLkj46Vqv7z449l gVjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KyxArfUs; 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 gb35si12588792ejc.351.2021.03.15.11.27.03; Mon, 15 Mar 2021 11:27:33 -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=KyxArfUs; 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 S239237AbhCOO2A (ORCPT + 99 others); Mon, 15 Mar 2021 10:28:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:36788 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232119AbhCOOAm (ORCPT ); Mon, 15 Mar 2021 10:00:42 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5090364F90; Mon, 15 Mar 2021 14:00:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816828; bh=wEEQlQ4L0PU89i5t+tVx+7qzfChUGHaXwvK1uzRbHZU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KyxArfUsHgzFfuSMeqebr4f4s3ax/gP2VTg8N/X4Rv8fQ5SFLnXLuYklzaQZymeRl pDiM+EY5B0/z2PWujGsvz4AZeGmOWAHNYnA41hx483kRs71oz2iJKGzmvRpi/rYau7 XNDZQ9PPFA0R0tPOvRFNIIpxTAndXFVxnPZ5Y990= 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.10 137/290] mmc: mediatek: fix race condition between msdc_request_timeout and irq Date: Mon, 15 Mar 2021 14:53:50 +0100 Message-Id: <20210315135546.543875131@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135541.921894249@linuxfoundation.org> References: <20210315135541.921894249@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 004fbfc23672..dc84e2dff408 100644 --- a/drivers/mmc/host/mtk-sd.c +++ b/drivers/mmc/host/mtk-sd.c @@ -1101,13 +1101,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); @@ -1129,7 +1129,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 @@ -1150,6 +1150,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); @@ -1337,7 +1338,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 & @@ -1353,6 +1354,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