Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1881069pxu; Thu, 17 Dec 2020 23:33:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJx7gietxHccpJIl2sar897mMQoR1ATo5YqtgdP/wu556Lyxx+qkgvUs4uHPRw/hvwOZJQcN X-Received: by 2002:a05:6402:404:: with SMTP id q4mr3094502edv.295.1608276781905; Thu, 17 Dec 2020 23:33:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608276781; cv=none; d=google.com; s=arc-20160816; b=d6MhjeLh1BkbY3U55mFyTYOZM10DFpcS3kAhsQc8uPA7eWA30WE1wXCa9pzuMB8VIh MBlgc/OyW58NmoReHIutbHXY+Cs//IzCvzFj4BsdJZbQ2qm4iVjP1aDvjFA9cv9IqQON fw9FEwxAVEKoQiBh+E1mlafoBuKIZKczQ6tJb/DEYuLIxtTDhMNlQnzECctXVzj4ETc+ 8hcTPV2YTSgUIUzTkjMjBftgH1v2BytWjcuWSHgAi6tkiYXHbURvc6qEW9C2RFmms9cM O7KNFFGcJqNUayXR24gjNG1485noZslfEWl3M+8rDkL7FDEr9rc2NPrvUxv2w7Sx8FmW A6lA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=3OOdIR0btNViP278aN1OXO6Mg/Lr/Y9y0dsKjgooeQM=; b=aIFLME88z4i+n++njdre84jrnuF55j3KA1v5b89tBjCxcRvmdM6QNapXvI4WwjmEGn l0urepWKqRIH10v0IbnL75IKG3rrruI8//wTT2Nsxz23EzqevcdbRlrOG1dFQwfv/nyW 2zQ9tXcwA/F2tk0qP4Jp72ol5NQ7mAFwQwnyOKo47mpWKvOowTembeAwjAMgIfx8flKd rYx3iT5N39fMCsXpZ7x8GvoKByPM1S8hq0LRFMmU/u1RQ1y7L9JYFDtdEyyzYOz+IX9G vIARL1UsxWcaVm13EZSJt977uLJhVKrG6H/kFBfqL2F6jk98zH6P1DV6pxPAetrwGDVQ 3gTQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bf17si5739073edb.344.2020.12.17.23.32.38; Thu, 17 Dec 2020 23:33:01 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732685AbgLRHRB (ORCPT + 99 others); Fri, 18 Dec 2020 02:17:01 -0500 Received: from mailgw02.mediatek.com ([210.61.82.184]:54995 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1732322AbgLRHRA (ORCPT ); Fri, 18 Dec 2020 02:17:00 -0500 X-UUID: e68527d1d73447cab287e8ae6f90a952-20201218 X-UUID: e68527d1d73447cab287e8ae6f90a952-20201218 Received: from mtkcas11.mediatek.inc [(172.21.101.40)] by mailgw02.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.14 Build 0819 with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1315769706; Fri, 18 Dec 2020 15:16:15 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs07n1.mediatek.inc (172.21.101.16) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 18 Dec 2020 15:16:13 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Fri, 18 Dec 2020 15:16:12 +0800 From: Chaotian Jing To: Ulf Hansson CC: Chaotian Jing , Matthias Brugger , , , , , Subject: [PATCH] mmc: mediatek: fix race condition between msdc_request_timeout and irq Date: Fri, 18 Dec 2020 15:16:11 +0800 Message-ID: <20201218071611.12276-1-chaotian.jing@mediatek.com> X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 de09c6347524..898ed1b023df 100644 --- a/drivers/mmc/host/mtk-sd.c +++ b/drivers/mmc/host/mtk-sd.c @@ -1127,13 +1127,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); @@ -1155,7 +1155,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 @@ -1176,6 +1176,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); @@ -1363,7 +1364,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 & @@ -1379,6 +1380,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.18.0