From patchwork Sun Nov 11 20:23:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Wahren X-Patchwork-Id: 10677851 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 9E68D14BD for ; Sun, 11 Nov 2018 20:25:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 90CA42969C for ; Sun, 11 Nov 2018 20:25:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8516B296F9; Sun, 11 Nov 2018 20:25:23 +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=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3A73F2969C for ; Sun, 11 Nov 2018 20:25:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=w/Gzy1FdXFoZZY/Bdgo4ocm33xnvBLknyOEQrYDJjx8=; b=AnOOH/JlAJanb/zGv8Tbhr5LUU zhx/OjHDpTA+1ZN4gwSeeDWVgEHvlQ5b700sWdpjiUYxzkXMAtqOBCK20C8Cz7VIX9OtfFjhm43QL Xn2eIdUXsmnEjJ4vN+c2GJ200/15T1/0eGCESCALXHcN5dVIfQTEXzzhuCLfDTra0py+5hc8tXRiZ VeEkvMwNwmyYOMh7qoN4/GtOx96Y+Swupzns5QIJnWRuyu4kcFPTRiRQI7vOLJb6ahc53c/VWEGn5 CQKE7XPssSzcb8TnIRBhX5ChXO5V5J7hV8I6Mo467mbYpK1W7LtEkplA2JhZKcRJ3PkFXIya3Plqp gLf70yzQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gLwIE-0003TU-1P; Sun, 11 Nov 2018 20:25:14 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gLwHv-0002cV-24; Sun, 11 Nov 2018 20:24:55 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=zHxxLEQsiHEhh7PVXEVNqUUxYM7wDjcAIJtcwJyNRQo=; b=DOPYo4t1y5vxpvZmFdW6hMyoZ pBOQEji74bYHR5OwkWKuoDPpZlQiQRU21mZwp08MZHufSo0j5CcZapSY9kRCb5KszFqO98vRCYDCW XP8SZxnfZV1eZ8OEGp82f8cQzrGl2FOpjKZNP1KX+0w2ibjMqcqZHppwTME1L96PAqzdexyzWJdGd ofA4EK/v+6FQohG4RSPQX465ZGIiui3r/C1O0WKGVim2eK+cE1wVK88X+rhHk1BoNRP/5MOpaX/v3 O51RexHgFZ+0YlkVQTCb/Zfgd93BZb5XL/ewyaDlkmVuqCpSWOgj5jgrSkad88yRtx9A29PIbzWdB JahBPzjOA==; Received: from mout.kundenserver.de ([212.227.126.187]) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gLwHr-000149-RY; Sun, 11 Nov 2018 20:24:53 +0000 Received: from localhost.localdomain ([37.4.249.153]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MvsyF-1fX0UR1Q9v-00ssSz; Sun, 11 Nov 2018 21:24:32 +0100 From: Stefan Wahren To: Eric Anholt , Florian Fainelli , Ulf Hansson Subject: [PATCH V2 4/7] mmc: bcm2835: Avoid possible races on data requests Date: Sun, 11 Nov 2018 21:23:56 +0100 Message-Id: <1541967839-2847-5-git-send-email-stefan.wahren@i2se.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1541967839-2847-1-git-send-email-stefan.wahren@i2se.com> References: <1541967839-2847-1-git-send-email-stefan.wahren@i2se.com> X-Provags-ID: V03:K1:ZLc6V0DmkpQIP44hYwa3HseRh7CvRoA9oKdzKs8yIsk8165B4Wj xh/v/qDrvpHbc6Mo7+ESlJoA7iV2QBpKIYXkV+l+LxP1hUGn0iO44fmLP2qBvLJtZvx/Ojh 06wOufM/u9ZWw0FVd6z87NbwhQC+r0Hdx+GWumlgWYq9lppFAMYe+6pIqLKFwesssADK3OS 0MJwlz/he/7bB9DxhEcnw== X-UI-Out-Filterresults: notjunk:1;V01:K0:lLFqbCq1JEc=:4dOYlMJrif5X850MHJ4IKv SsggGIkb+7xoay8mJWO2ixu2r0n0ZJp/p5GCqVWB8a8GEJ5AXj04izOlxindxB0yxAXLfOtEY +MADRnLwkXLIyvJ52YOhbudb4v+KVS8LnZmdnl+7dYi8ILPPI8K1YyOA0Atm0Sc1zKCyzyrb+ HXYtIBmpCCeoXAn6iF9KtPShMQN90JkCkhQDCTtvuHKB4+XasgiJQqwLvDbMhUTfAiHKRbT6A Ret67MCTcoBZMJ8Lv5IVe96pGyj6/IftFJwD456d201u/qlGUEcsrQlXoVDZyYQINncWlmCe9 nhfpQF8UozqPck8kat7pUYNcoUck660Ob7tS+eW6IQxtgNKjjkiaYgE0VlcnBWXS46anJouuq rFWawTXHFsLU6SVpIIVC5wCmDIOpgnWg2E5Dg6O3JtD4JPpSw9V3hM8L34Ii6DfWsvPAlJ46O kCFiB/zfxUDXTLqed/nM9eufpPmQGlkRVnwoBNh18c7patPv1MzAU94KuN0ciq4QgoPk400rI 5AOu/Eb9ck9CqDcZnI9x3PGjBoRgf0O/cvmqP67kgt1u17W9OEGaqHaEkXh+xLTDICpauVWMp kOXBFyQ2SWK4jxt/C1uNgcghWG4r8UDxx9LFHZA0Ut2oGO2bW8qkpXlRBI11lvMuK3P+jSSXu 8ZdD0IA/lvl6PXMOo1Zs7F+mho7h8yoB6XvVBOO8Mh8VonIPfeFZAQOrF/WP5SI3te/r5jk8v wI7Eoz+v7SK4TMhwvTrIv+Q6zGYykDWUFqpehDe/ZhMpdl/XnD0H+Z9jGWgv6Wyi6Rmwc2JEJ 6Xq84VFzxbb0yps5VJcK6at8C/JGA== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181111_202451_956461_704341B1 X-CRM114-Status: GOOD ( 11.96 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stefan Wahren , Phil Elwell , linux-mmc@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, Michal Suchanek , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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) {