Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp4246994pxb; Mon, 25 Oct 2021 00:00:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzUQ43Pw3m5/Wj5ZvBdoyqkR+LSHsH+zyPf1APAqtfcItOyiuQ33Qz96A4eV2xgEC3Dyc9/ X-Received: by 2002:aa7:cb92:: with SMTP id r18mr24512314edt.282.1635145213440; Mon, 25 Oct 2021 00:00:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635145213; cv=none; d=google.com; s=arc-20160816; b=A7Tr1j+F3uQakM6j8TpnTx4zDCaGhdyRVGj/rqyWWbQF5AkdZakRVZ8Cr8YvMs/H55 aYtQhujcRMx6THkJlDos+3LHRoMex5JuXpOTALUeXgbICi101Uji2fU+0Z0pEwijMmIV aKbmDV1EiL//CcPn0QItQnAgFCcRmycjivs17UA3BhhBh+QO30B9AtGIFalbhDtxt7Xl 6LezeTqFifAg5BFp88ECgekoxU6tIeNH1IsIaaK9fl8QclUh+dOWC+SDEbVIfhJ7glZS 7+65jUXLcCJOfRcWZh2Xb8NbuHjA8joz4l5YVjJy03VxWZweO5QOEQEew5a0SMdUMh1D 1r+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=DbOfBhRREpuOCtf1FIhtpVubYgMQxOlqNhr7I8WB8OU=; b=Cm4fxJwte3B69mDkdu2QsBwDigee85EE0OVE8M0BkiuxEQG/PLM5w468f5yJ7Q+MZ6 qqjYMUbGiE3OaE27tu+cGDKfo6K/eLQ9enBSAsnFzMoq2G0SrV7KeW+1WbJ0hayv7Cmk ePUAno/dV8fUziD3rqRlsJRv7MMZAo427mfY8o71OtU1rZYWBOk1pBJTNJ3oOKEFs5hs mQXMst2YZB4pAWXRuLj/M8Wr5+AJeE776MhIQskfB/j1OXLqV6CgHu5sBs4XKkZ2tVKb KxMW9zn1SJ6JBbITTrxrqmf1SCdyGGsbJQAUeBodJw6IrpuYlFqwx5zvN7bP3WIvqFTz c0Wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=E3HGJ0X8; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d6si13811501edp.299.2021.10.24.23.59.49; Mon, 25 Oct 2021 00:00:13 -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=@kernel.org header.s=k20201202 header.b=E3HGJ0X8; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229992AbhJYGNA (ORCPT + 99 others); Mon, 25 Oct 2021 02:13:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:40626 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229850AbhJYGM7 (ORCPT ); Mon, 25 Oct 2021 02:12:59 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C06936023D; Mon, 25 Oct 2021 06:10:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1635142237; bh=htjBfDAv/fbf9E0uZNabYl3KsNaiUTRrvgCjUk0Ec04=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=E3HGJ0X8Z47zZOrQl2+GK+0V+9R/+ONSk8UadSPQPRsIsmBG9tOD5J3OpeEQLQjJ9 V7TdkbUSu3FunLXNCpguIwBT32gNlXNzzD/ITEH+rZM7ny79nLeZVQ6QdH1U1xzyg5 mOGgAAnwcZcZsW+Fc8uNgjGG0e5CALTsHz+DToeI4If+z7O+ZbeHyDiTASlldfH3Bq u675CeNJSwy8sUtgrTVh0s+a2Q9w0zL0eJBlbesH0YInqz/8VUAeW2amStkvP2rKQV f4ji8KJo3V8+jle0AmnxCQ8CcGZ1fnq78Zk6tonne7PLOcHw/yig3Q97nP26Zk8VOU R2UlzFJbr0Wdw== Date: Mon, 25 Oct 2021 11:40:33 +0530 From: Vinod Koul To: Harini Katakam Cc: romain.perier@gmail.com, allen.lkml@gmail.com, yukuai3@huawei.com, dmaengine@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, harinikatakamlinux@gmail.com, michal.simek@xilinx.com, radhey.shyam.pandey@xilinx.com, shravya.kumbham@xilinx.com Subject: Re: [PATCH 1/4] dmaengine: zynqmp_dma: Typecast the variable to handle overflow Message-ID: References: <20210914082817.22311-1-harini.katakam@xilinx.com> <20210914082817.22311-2-harini.katakam@xilinx.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210914082817.22311-2-harini.katakam@xilinx.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 14-09-21, 13:58, Harini Katakam wrote: > From: Shravya Kumbham > > In zynqmp_dma_alloc/free_chan_resources functions there is a > potential overflow in the below expressions. > > dma_alloc_coherent(chan->dev, (2 * chan->desc_size * > ZYNQMP_DMA_NUM_DESCS), > &chan->desc_pool_p, GFP_KERNEL); > > dma_free_coherent(chan->dev,(2 * ZYNQMP_DMA_DESC_SIZE(chan) * > ZYNQMP_DMA_NUM_DESCS), > chan->desc_pool_v, chan->desc_pool_p); > > The arguments desc_size and ZYNQMP_DMA_NUM_DESCS are 32 bit. Though > this overflow condition is not observed but it is a potential problem > in the case of 32-bit multiplication. Hence fix it by using typecast. > > Addresses-Coverity: Event overflow_before_widen. > Signed-off-by: Shravya Kumbham Patch was sent by Harini Katakam and SOB not available for person sending this patch, sorry cant accept it with s-o-b... > Reviewed-by: Radhey Shyam Pandey > --- > drivers/dma/xilinx/zynqmp_dma.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/drivers/dma/xilinx/zynqmp_dma.c b/drivers/dma/xilinx/zynqmp_dma.c > index 5fecf5aa6e85..2d0eba25739d 100644 > --- a/drivers/dma/xilinx/zynqmp_dma.c > +++ b/drivers/dma/xilinx/zynqmp_dma.c > @@ -490,7 +490,8 @@ static int zynqmp_dma_alloc_chan_resources(struct dma_chan *dchan) > } > > chan->desc_pool_v = dma_alloc_coherent(chan->dev, > - (2 * chan->desc_size * ZYNQMP_DMA_NUM_DESCS), > + ((size_t)(2 * chan->desc_size) * > + ZYNQMP_DMA_NUM_DESCS), > &chan->desc_pool_p, GFP_KERNEL); > if (!chan->desc_pool_v) > return -ENOMEM; > @@ -677,7 +678,8 @@ static void zynqmp_dma_free_chan_resources(struct dma_chan *dchan) > zynqmp_dma_free_descriptors(chan); > spin_unlock_irqrestore(&chan->lock, irqflags); > dma_free_coherent(chan->dev, > - (2 * ZYNQMP_DMA_DESC_SIZE(chan) * ZYNQMP_DMA_NUM_DESCS), > + ((size_t)(2 * ZYNQMP_DMA_DESC_SIZE(chan)) * > + ZYNQMP_DMA_NUM_DESCS), > chan->desc_pool_v, chan->desc_pool_p); > kfree(chan->sw_desc_pool); > pm_runtime_mark_last_busy(chan->dev); > -- > 2.17.1 -- ~Vinod