From patchwork Mon Jun 13 15:07:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 9173365 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 78C5E6075D for ; Mon, 13 Jun 2016 15:08:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6A99320499 for ; Mon, 13 Jun 2016 15:08:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5EFAE25EF7; Mon, 13 Jun 2016 15:08:04 +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=-6.9 required=2.0 tests=BAYES_00,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 54AB820499 for ; Mon, 13 Jun 2016 15:08:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1422835AbcFMPIB (ORCPT ); Mon, 13 Jun 2016 11:08:01 -0400 Received: from mout.kundenserver.de ([212.227.126.131]:53774 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1422810AbcFMPIA (ORCPT ); Mon, 13 Jun 2016 11:08:00 -0400 Received: from wuerfel.lan. ([78.42.132.4]) by mrelayeu.kundenserver.de (mreue004) with ESMTPA (Nemesis) id 0M6yZd-1bOen60x7t-00wpdy; Mon, 13 Jun 2016 17:07:13 +0200 From: Arnd Bergmann To: Vinod Koul Cc: Arnd Bergmann , Dan Williams , Michal Simek , =?UTF-8?q?S=C3=B6ren=20Brinkmann?= , Kedareswara rao Appana , Laurent Pinchart , dmaengine@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] dma: xilinx-vdma: add some sanity checks Date: Mon, 13 Jun 2016 17:07:33 +0200 Message-Id: <1465830523-2484498-1-git-send-email-arnd@arndb.de> X-Mailer: git-send-email 2.7.0 X-Provags-ID: V03:K0:R7pkTIgePAUVBaZtZUW5I19UAsTzBLJ0SYXQYdsDlKTihH6mSPM TuBtRuMFHtyUlaJxbvsr4iYoo+LdCZZKBiuEXzNC8q0D4sBPUNyRxIUFVFuxulT6LryidwC QQyTAsPL4A0vE55+bqYA103ATXzbOTm6bLFkSWvdwXEgUFzMjD3OMZPkypfEaehwxFNuvYY w8sCsI/gnsETToZkIdfng== X-UI-Out-Filterresults: notjunk:1; V01:K0:5PA49ccAd/w=:SNk/dHXqDaDxeYN8TlueEe FpMlIq24w2DF/+fUEu04MdosJrUZC6eRoYiX8yx4q36WXcTIi+fHmNvKKzl1sjABlaWCETz/Z lP9JSrtj0lzJ+WIfIqH3j1Y+VjYEJNalkBgq+j5w0TmHdnI5bnO+G5QvMxlnyoXh28ka3dTMx OOZ7SvB0e343GqWzTuIqxvlZplYbagSq0/qTJJFKP8zeipesW+zw8r/rAfBdnSmo0DJGMS5ll 3+wFmJBmKxJ+zjdJilczENR6M/PJ7i/aXuWGujLAcyAYb+jJoVVQ9TIzqXRF0VqwpmA+WNWci YfkWzKmPfO6iKBFZtLGBZa2vuQEsfM7aCMQeGDopJE6yRmLFlk16274UfxIkHlZKSrRiGAFlv I7hC4fue1LkqpOkkjTQVKBEpBMjaRU11IQRHiTwSM0D/aeklwEjLaEqsJVvwwInGnO3O533sm d7ag+eQsSFjZeCJTUwG9mqVEfKsilmvZDSHbkghDpTF7g6F43oFTn+QJmQlJ1AlqLcVcIFSkg yU/wl7KjpjCl04LIK79C8MoHWzXXCZCClzs5YZHjurpEVGGz/VtrrN/bMA7jt/RbReaCIrxZN EJcmSnp3px37RCj30DylWqhPLvQ5VqQiQT0dItsSV7Bhl7ygYeDjsyTDxSZXyfjr/yTzc3xWc oDO1TrK3SKzEWr3FwHovMQp371OQNbsOs+dc2VNqGN6J+LlQ0pBoMhp6GHIhLhoFdLqQ= Sender: dmaengine-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The newly added xilinx_dma_prep_dma_cyclic function sometimes causes a gcc warning about the use of the segment function in case we never run into the inner loop of the function: dma/xilinx/xilinx_vdma.c: In function 'xilinx_dma_prep_dma_cyclic': dma/xilinx/xilinx_vdma.c:1808:23: error: 'segment' may be used uninitialized in this function [-Werror=maybe-uninitialized] segment->hw.control |= XILINX_DMA_BD_SOP; This can only happen if the period len is zero (which would cause other problems earlier), or if the buffer is shorter than a period. Neither of them should ever happen, but by adding an explicit check for these two cases, we can abort in a more controlled way, and the compiler is able to see that we never use uninitialized data. Signed-off-by: Arnd Bergmann --- drivers/dma/xilinx/xilinx_vdma.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/dma/xilinx/xilinx_vdma.c b/drivers/dma/xilinx/xilinx_vdma.c index 0f5b38a0e46f..2ac3253bc823 100644 --- a/drivers/dma/xilinx/xilinx_vdma.c +++ b/drivers/dma/xilinx/xilinx_vdma.c @@ -1745,8 +1745,14 @@ static struct dma_async_tx_descriptor *xilinx_dma_prep_dma_cyclic( int i; u32 reg; + if (!period_len) + return NULL; + num_periods = buf_len / period_len; + if (!num_periods) + return NULL; + if (!is_slave_direction(direction)) return NULL;