Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp615743pxb; Thu, 23 Sep 2021 07:16:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw194xr5nKmCCdvIi3rLMnJu/z4LQVz8jtPlfdnUsnB3PKFKNohzMiv7367+uMwF4db5UCq X-Received: by 2002:a50:bec8:: with SMTP id e8mr5832133edk.231.1632406576815; Thu, 23 Sep 2021 07:16:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632406576; cv=none; d=google.com; s=arc-20160816; b=bICvLOD0/A9xerEdjPqXGeR7JV035tNkJPYHQwzUxmm7gANrKxad3bGSYf5MKADw+5 PW2Dao15Vzza1IPUbDpLnWG8i7deJDwUaB2g6NYMXOYbA9nkt282+IGwc8DPr22TIc5/ XNdsetBgwG3jfdHNNaHjDOF4WQJ3LzW7vCLgcvwIVWEcyjK8sH0tB9FF6tWqf/Hmd4Ju 8T3xnnqe0H8bvhU4gR2NQ0Cif5AVHwmJa+BgPE9/+SV3NET3sbYTK/zAJuX4hvnxpA8C B9fttG9uEuCNE2uhcwiBeEZYVLJhMDi8217u4qVDnNcJsvu1c9f4l4bj1jzmswiJiRdG 3HXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=d/BklBdNbTEz6Wn4mY6+X8+gCHGsddAyAjjSImemiX0=; b=dyixUe9EutbZzqZ7YjXI+SmxpejVewOgTAyAaIg/9HtcPjWC/qGcb+vX9XBvc59FG+ l6VDao/zKFKAGKkjYALg6Nk4vnkc1MZFIaUf3Bw0UIXf1CX4JalKYuvwAOayhMOutyi8 DIQVlugWuOFfqQ8+ENaXIqwt8IykHOyLKWSmQavTMqiCuwk6x5HtrDYo4i0ZY9Osuqe+ BLCUEU+bcwDRZ+8mwWR5trAoK19lRnGu/GZdOVJBMJkaSiN0VgWz0Z1nBXEL8SNmYk0P 5wImRSHMTdvsHPB/hxbe+N/Ml0a4LPefm5kASlAcu/8eLr58EQQYr0ABDWjyJgv254Yv +GOA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f20si5469394edj.364.2021.09.23.07.15.49; Thu, 23 Sep 2021 07:16:16 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241555AbhIWONp (ORCPT + 99 others); Thu, 23 Sep 2021 10:13:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241304AbhIWONn (ORCPT ); Thu, 23 Sep 2021 10:13:43 -0400 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2EF49C061574 for ; Thu, 23 Sep 2021 07:12:12 -0700 (PDT) Received: from ptx.hi.pengutronix.de ([2001:67c:670:100:1d::c0]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mTPSD-0006kc-MA; Thu, 23 Sep 2021 16:12:01 +0200 Received: from mtr by ptx.hi.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1mTPSA-0000L2-3T; Thu, 23 Sep 2021 16:11:58 +0200 Date: Thu, 23 Sep 2021 16:11:58 +0200 From: Michael Tretter To: Harini Katakam Cc: vkoul@kernel.org, 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: <20210923141158.GA30905@pengutronix.de> References: <20210914082817.22311-1-harini.katakam@xilinx.com> <20210914082817.22311-2-harini.katakam@xilinx.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20210914082817.22311-2-harini.katakam@xilinx.com> X-Sent-From: Pengutronix Hildesheim X-URL: http://www.pengutronix.de/ X-IRC: #ptxdist @freenode X-Accept-Language: de,en X-Accept-Content-Type: text/plain X-Uptime: 15:08:04 up 217 days, 16:31, 115 users, load average: 0.30, 0.52, 0.45 User-Agent: Mutt/1.10.1 (2018-07-13) X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::c0 X-SA-Exim-Mail-From: mtr@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Harini, On Tue, 14 Sep 2021 13:58:14 +0530, 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 > Reviewed-by: Radhey Shyam Pandey Thanks for the patch. Your SoB is missing in this and the other patches of this series. > --- > 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), Wouldn't it be easier to change the type of chan->desc_size to size_t? Maybe we could also just calculate the size of the descriptor pool during probe() to make the code more readable? I also noticed that there is the ZYNQMP_DMA_DESC_SIZE() macro, which is inconsistently used in the driver. Maybe you could cleanup this as well as you are at it? > &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), With a pre-calculated descriptor pool size, recalculating the size here wouldn't be necessary anymore. Michael > chan->desc_pool_v, chan->desc_pool_p); > kfree(chan->sw_desc_pool); > pm_runtime_mark_last_busy(chan->dev); > -- > 2.17.1 > > > _______________________________________________ > linux-arm-kernel mailing list > linux-arm-kernel@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel >