From patchwork Sun Nov 11 13:45:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Wahren X-Patchwork-Id: 10677635 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4D12114E2 for ; Sun, 11 Nov 2018 13:46:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3DC2D2A7FC for ; Sun, 11 Nov 2018 13:46:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 31D782A805; Sun, 11 Nov 2018 13:46:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD08F2A7FC for ; Sun, 11 Nov 2018 13:46:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728158AbeKKXfH (ORCPT ); Sun, 11 Nov 2018 18:35:07 -0500 Received: from mout.kundenserver.de ([212.227.126.131]:45797 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728118AbeKKXfH (ORCPT ); Sun, 11 Nov 2018 18:35:07 -0500 Received: from localhost.localdomain ([37.4.249.153]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MmyzH-1ffs9A1Vg7-00kBEY; Sun, 11 Nov 2018 14:46:07 +0100 From: Stefan Wahren To: Eric Anholt , Florian Fainelli , Ulf Hansson Cc: Phil Elwell , Michal Suchanek , linux-rpi-kernel@lists.infradead.org, linux-mmc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Stefan Wahren Subject: [PATCH 4/7] mmc: bcm2835: Avoid possible races on data requests Date: Sun, 11 Nov 2018 14:45:27 +0100 Message-Id: <1541943930-23873-5-git-send-email-stefan.wahren@i2se.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1541943930-23873-1-git-send-email-stefan.wahren@i2se.com> References: <1541943930-23873-1-git-send-email-stefan.wahren@i2se.com> X-Provags-ID: V03:K1:KWB6kUDC6PK+zr0Txk3LnIPqOB1mHiyDDpRX02xMmXpkye1u2ej XxLoNiy8h/6NpRX4kx4ptBvN2WnuQUbIcKRRap+SSmrJpZokC/eUZ4U3fRX00oT59JnCGTO R1CA+R56LznLPEncwoEnwrgNU6Y3Oo73Kk0ZQuYi25OnfOIIs6LhQwLFOs89NYq0oyj6mG5 3+HVT2+wsWa+1POvTSK2g== X-UI-Out-Filterresults: notjunk:1;V01:K0:GdGUkT90e2g=:lN8ROZoWnHbE4vpBdV5hcX MO4meNL5Ac62ZC0xEORLG84CMl4jD/fhf8Hbz+wmtpP57vGgVpbtLN7u2ksdXnVVSz5fcT40d igwnY9Fqo/XtLgpTT0eaJsGuwnsdVLSjcco5SJ2DVnlKnLQB4CJkS5Wr5WTTytMaM62sST9I2 Xd7XtDQf36+qSF9cfBLrGUcknYupHcoaZg4mzAU6rkYSCa5aiKJKbxUlR9TwyOGZbefBFX3hx C1Tr3HIuXKGDWJLBlXjjtyWHpCwccwN4nPUm9IaVSFSzf6paVfJe04MykTstyYl9V2u8lRfTU m+7VQW3shlXRSxg7xh63Bxz0b0qMq+UBx6a/MlSmjo5J9sgBNW1iZ9rPSlGf5vf5/xiRcM+42 dEf+Rm43UfvXLEw+yQH0FJ5sJFX4LinumJoSRIv9U0bgPBcqm9iWDZatHZZ+LyciWK7yzANyW gguGJjhaTAI/gcK7LecAAxaiT4vt2JapTVJ4ffT6E6OkyDPCRbYzX0XupBtuip59Qg84XVYko FuCwPwxeScKGjAHuB2K42MqEGOBeHWVpX1M83FzOA9MqKZruQRMwyLfJjprWoW56VQD34xE71 MHT56/QWsvC9mmOezcB5DyiRVEC0RdY5dcNnNseQCxTknsT7xvrFEmp8fwigf1ff5eciQNNrc duHGC1spzq1Us2ca5zED6OGKrFB7wSSQ0Sn7zW6IhsN0y9nLUxOlINR2cIOz4yoQWCF/poDWZ YMvHaxsPWjXfpxNn0S56akFQ01dy3vFHIbgeJ7HzR0FkqXzxtnCnJAB8V1HZX9ju1gZbsxpmu WcC4JMNYVPp3YifiYltvTZBDag4PA== Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There are two accesses on the data requests which are not protected by the mutex. So fix this accordingly. Signed-off-by: Stefan Wahren --- drivers/mmc/host/bcm2835.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/mmc/host/bcm2835.c b/drivers/mmc/host/bcm2835.c index 45724ef..1c60798 100644 --- a/drivers/mmc/host/bcm2835.c +++ b/drivers/mmc/host/bcm2835.c @@ -1064,10 +1064,12 @@ static void bcm2835_dma_complete_work(struct work_struct *work) { struct bcm2835_host *host = container_of(work, struct bcm2835_host, dma_work); - struct mmc_data *data = host->data; + struct mmc_data *data; mutex_lock(&host->mutex); + data = host->data; + if (host->dma_chan) { dma_unmap_sg(host->dma_chan->device->dev, data->sg, data->sg_len, @@ -1192,9 +1194,6 @@ static void bcm2835_request(struct mmc_host *mmc, struct mmc_request *mrq) return; } - if (host->use_dma && mrq->data && (mrq->data->blocks > PIO_THRESHOLD)) - bcm2835_prepare_dma(host, mrq->data); - mutex_lock(&host->mutex); WARN_ON(host->mrq); @@ -1218,6 +1217,9 @@ static void bcm2835_request(struct mmc_host *mmc, struct mmc_request *mrq) return; } + if (host->use_dma && mrq->data && (mrq->data->blocks > PIO_THRESHOLD)) + bcm2835_prepare_dma(host, mrq->data); + host->use_sbc = !!mrq->sbc && host->mrq->data && (host->mrq->data->flags & MMC_DATA_READ); if (host->use_sbc) {