Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3523414pxf; Mon, 15 Mar 2021 11:27:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwx2ruP9ZHM+faQO+H0vPbJ5Ces7GiA50IX7bTygmbYZ9k1iibvmXnLhsyTnIhw9xdfahPT X-Received: by 2002:a17:906:3c50:: with SMTP id i16mr25594019ejg.175.1615832847074; Mon, 15 Mar 2021 11:27:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615832847; cv=none; d=google.com; s=arc-20160816; b=DrrdDQfFigN/1Zj7qfweVXQhF3n+Yr0txN04f8KjhfbkulbsZVjFdIgLs5hKDwVlBf bIzlqpQax5X1lbBU0/vpdVE15DPFq34IyRp0pPoAQ913m8ZMyVDD2mnxOt4zmW5/SMGW jW269X+5f+SC1clt9NjF6EzfEVeB1yCv/BFaIEB94u8mYsMBH0XZ0RZcvNYnRnlkopWN MA0HdpdrRla0haQeec9FWnkKcPvm9P9sPEdSN5dq61smXBuSZDM7hEKGrRKdDpoX+ACi WU6hF9O7fA/oIBGhwpWqJwToPsQaAGRMfTZDrusqHfcjFSleMC1t+q7Roa2vLNMIiTD7 75lQ== 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=Pet6tvn6V/P1nkdiRY/rBO44Q6Z8bbF5U6xkHk/L3bA=; b=HdPdqB541587bgOkcD2sM4OjV97//mRlh1nLHQhtXBpruO2EqnA/vDHXXACbQc1qFz c2gTZgfslP2Tj6BK7UZceyuWLizLd7Bp0qO/cZ93cUDYiDmpbkr0u/WuPkQ/9oCxKssK aHsYSd+A2qi4miBbkKAo+0IFJIpOtgvMC/HjCTO7gfJx3awqh0ic85r7Uu36ycjWSbhY 4ljTCREaIsu5DfUWTU7crXFzoqr0I+tTFrrQuH4rPFERSkgIsT8prTCoh5e9J9v7jJRD TstYGpTymN0r+uFP+4nUyUg3J0P8rNsw7GyLHQ5s4ofTSB+0edMbxF1Gdn7eOX1qy4KD P9Dw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FcJ3jNcw; 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 ot6si12074034ejb.337.2021.03.15.11.26.59; Mon, 15 Mar 2021 11:27:27 -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=FcJ3jNcw; 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 S235146AbhCOO3f (ORCPT + 99 others); Mon, 15 Mar 2021 10:29:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:37582 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232979AbhCOOA3 (ORCPT ); Mon, 15 Mar 2021 10:00:29 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2748B64F06; Mon, 15 Mar 2021 13:59:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816800; bh=D1PiA+M4iRzzEEoFXNnIFPKLpdvVYmCc9yT9KFEC9VU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FcJ3jNcwUK6F+GPxb2Fen0Qqxb4lB8LiUjqaHPdwnw2APoKhPfAwXABmiY6wh5yRf oh/NQOotlpLwMJX0LqOnbO1UK1FfdmrEQYL6nPpLcMC/PdYW9FEkNbUalN9vTxoYvb LaZ8GuxwzDMPR6ekx/viDj0JbMa5jjFTE1cxqlck= 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.11 132/306] mmc: mediatek: fix race condition between msdc_request_timeout and irq Date: Mon, 15 Mar 2021 14:53:15 +0100 Message-Id: <20210315135512.114324488@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135507.611436477@linuxfoundation.org> References: <20210315135507.611436477@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 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.30.1