Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp958472pxb; Wed, 3 Mar 2021 22:31:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJzBGXtYEFqCp/NnZD3w/OzLfGwH64/ZAFaFB1+SuqHzXs1IXV2h1q7ASZLZ5H2HfyMDnlqn X-Received: by 2002:a17:907:2513:: with SMTP id y19mr2529709ejl.241.1614839514312; Wed, 03 Mar 2021 22:31:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614839514; cv=none; d=google.com; s=arc-20160816; b=Ug0KDgAHkJcxzp8tE5vqoB8Y5efP4ytx32HM8zxZG04tL1iut8bskJvMNghBesAYhL DIy7Ful56KNBt1Xc9YeDk4EOBGSRaxBkgaZDRQbsZFjBxdob3BI7CP2dwWQ73wL6JdAh X2PTVPouxT1kM92WRRbnbmLRc6gHYPHtvT0lqpHtDqt6pJulbiPWWp5wSzHXTzz+NrxT PyYq8jmcjXDFoKN/b4D598WseDmq3bA94CxLaEzxgamDS//Kvi2QJc8ZNN9oeTIsjJib T1pQQIBg9xy/UY4OCXTBwAYKMOsU/c20Di9661Em8BFK3P03KyjXyvzW3aJSO9ydVIfc 3TZA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1Xq7Xb2RviRkoVnCoHUsfwJvRjfSiTwEJYadS0RA2/Q=; b=HHeW5L8z/sJWSitW53z7Zd4VUqjnZ+9cWcWO+uluBKiFUlzjiPu3i7vaxBOyDReFgj vErdmou0Z9F4yohecyPfli5scr4t+bYiuHXYPnWGs9ucx5zbllQCXtyc3J4SbXdJPnjH 7npNh9aj7lKToU6efAkqeldt2I+Pmof0yo8RWmS7Bs24ohRcTC51IrpHE25tGCwD7fqm VYfUcemXfAbf1v0m7HjMjfWouffQeBWcu4dV1fwSdnmyimjE9qP6d5LJUV8QOnk479DT v0J6DNVsF4SBm7FemMoxtRO6qeED1ZURvtfh8PM1/9fnryEDTxMKBg8OEII1kaMMPpE1 i/RQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=WN+TQSR8; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h18si10206701ejd.89.2021.03.03.22.31.32; Wed, 03 Mar 2021 22:31:54 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=WN+TQSR8; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1579516AbhCBQ6d (ORCPT + 99 others); Tue, 2 Mar 2021 11:58:33 -0500 Received: from mail.kernel.org ([198.145.29.99]:47766 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377883AbhCBO1G (ORCPT ); Tue, 2 Mar 2021 09:27:06 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 937C564FD2; Tue, 2 Mar 2021 11:59:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1614686379; bh=Z5V6QxlYbSnVGsT/Zskji+exXNBQu9FvWIp6KdSxNg4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WN+TQSR8iCEBG9jWle9TwfWfHnKAk3Rcvyttxyez9JSD/msMSmyw++k+Pd0DGnA7I w61hK4pvGc2HAR5oE3K55s+w+J/2uJKfb9aAx/+7/aT9e99xRjFWVI43+zz9z8EDhW iMY0uodzNcCwJD4OL+i/rb33AmiehAL42H+28gsMDb2z/fxlizkQLcAFalayYE/Tui Cftnet43GPQZrVV7i7ZHvsshDOM+vgRgcBQPnpQdfLuOT4jVWgnVc8aIoSmbCr+8mg khA3htVcmxmKkkCOSVrMW+tRms22zPL4nAy8bnBZ0akHlnnwEhf2w08aAT9sde+ro9 gyvqdXuPDb0LA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Chaotian Jing , Ulf Hansson , Sasha Levin , linux-mmc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Subject: [PATCH AUTOSEL 4.4 2/8] mmc: mediatek: fix race condition between msdc_request_timeout and irq Date: Tue, 2 Mar 2021 06:59:29 -0500 Message-Id: <20210302115935.63777-2-sashal@kernel.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210302115935.63777-1-sashal@kernel.org> References: <20210302115935.63777-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 5ef25463494f..1770c8df9d1b 100644 --- a/drivers/mmc/host/mtk-sd.c +++ b/drivers/mmc/host/mtk-sd.c @@ -720,13 +720,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); @@ -747,7 +747,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 @@ -768,6 +768,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); @@ -942,7 +943,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 & @@ -958,6 +959,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