From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0379EC432C0 for ; Tue, 3 Dec 2019 22:59:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CB71821555 for ; Tue, 3 Dec 2019 22:59:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1575413989; bh=VeOfFR/MlblkVzYBRlCoJb5qQ47Er/IwMm3cLCj+7mM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=d1CfbaTe6YlrK+al9pTQlUcmOobc9txSkoGz0yvo35dKpU264Nyq98tQVQgDv9HYV 95AIN/2/oo90bf+PgrSGVkS2arOSXHvxh2pUU/uWKySCJIPdXZbPZI1qQYFNZJtxH7 upTxDKOgwmtOZ8W7Zkqqsu7ncGHUJIW+kPM02G/Q= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730602AbfLCW7C (ORCPT ); Tue, 3 Dec 2019 17:59:02 -0500 Received: from mail.kernel.org ([198.145.29.99]:55472 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728845AbfLCW64 (ORCPT ); Tue, 3 Dec 2019 17:58:56 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D5CD220656; Tue, 3 Dec 2019 22:58:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1575413935; bh=VeOfFR/MlblkVzYBRlCoJb5qQ47Er/IwMm3cLCj+7mM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Oi2zhyF0kp6Cmvw5tTHjt20ILNQNreX9HI/0LxSk2GwDnkQNSa/Ck4uVV3tEfLkbP vg1ZLKjIRcaSstR9Pi9jNVawtyTN06HEGabEEWP5E4NRlocclMLGKTRz6o+K584Wtf Xg71o8TokdRltTmvCOAorcP6kBjM0Ae3L1KpN8/M= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pierre-Yves MORDRET , Vinod Koul , Mathieu Poirier Subject: [PATCH 4.19 319/321] dmaengine: stm32-dma: check whether length is aligned on FIFO threshold Date: Tue, 3 Dec 2019 23:36:25 +0100 Message-Id: <20191203223443.738270452@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191203223427.103571230@linuxfoundation.org> References: <20191203223427.103571230@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Pierre-Yves MORDRET commit cc832dc8e32785a730ba07c3a357e17c201a5df8 upstream. When a period length is not multiple of FIFO some data may be stuck within FIFO. Burst/FIFO Threshold/Period or buffer length check has to be hardened In any case DMA will grant any request from client but will degraded any parameters whether awkward. Signed-off-by: Pierre-Yves MORDRET Signed-off-by: Vinod Koul Signed-off-by: Mathieu Poirier Signed-off-by: Greg Kroah-Hartman --- drivers/dma/stm32-dma.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) --- a/drivers/dma/stm32-dma.c +++ b/drivers/dma/stm32-dma.c @@ -308,20 +308,12 @@ static bool stm32_dma_fifo_threshold_is_ static bool stm32_dma_is_burst_possible(u32 buf_len, u32 threshold) { - switch (threshold) { - case STM32_DMA_FIFO_THRESHOLD_FULL: - if (buf_len >= STM32_DMA_MAX_BURST) - return true; - else - return false; - case STM32_DMA_FIFO_THRESHOLD_HALFFULL: - if (buf_len >= STM32_DMA_MAX_BURST / 2) - return true; - else - return false; - default: - return false; - } + /* + * Buffer or period length has to be aligned on FIFO depth. + * Otherwise bytes may be stuck within FIFO at buffer or period + * length. + */ + return ((buf_len % ((threshold + 1) * 4)) == 0); } static u32 stm32_dma_get_best_burst(u32 buf_len, u32 max_burst, u32 threshold,