Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp642852pxb; Wed, 3 Feb 2021 14:01:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJzPdH2Anmf1vdo78zBF78+Mzab44g2f+03b+8LtOZP6gkO58fUWiKrTh1jXTY+aH8eX5w2p X-Received: by 2002:a17:906:2bc2:: with SMTP id n2mr5137468ejg.381.1612389693898; Wed, 03 Feb 2021 14:01:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612389693; cv=none; d=google.com; s=arc-20160816; b=EEvw6Mn1EpcHUYSHq8lL58h/sZPTFJYaQ7m94Mt8lmLeW8VxUZdpHMNi7sPWg2QCn8 WdvSen25HkCE1Iydq1ZWyiyr+2pa955NYdio3aUfHKLCFgo2cioFLmtwIYuLN7jqgkBQ WZdqcrZtlGB2s69NenLY+pXSL1GR8hb/5i/kH9iCAJril1T/Lmgd5K1PKBRao2hr/RWq zsE5tOLQxG+GdQCA0bQpUyV8O8fPfu7SLOkaS97xiPWO4ofoTV8tvkBRGMdGKRz1ml8z LcvsW0t1M+CqRLyje47mRkoElPr+vuwNGshfbwbBTwn8BadA4BsZsBhIvON8+eVbmZxn dpjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=w0ELnjcsqAoFlkxI+LU8aqcUHPM67N31KnUI2zZorBw=; b=oukSIpUmN3FsqJfGZqRURvGCu/EyWzThM/TPek3rJoVEXo65X+3DO5lVuD15awCXtX l58cI5plVVRvDbC0XT25Kg9pX4VU3iJ/LpptpllacAjjuvbSRJ39wXuY6sWmYbsjAkj2 UzVyGtmjSPz152go5xm5j3YJrZsMuRLeMB7eZDbhQ3UbesbhmiNmBNRvOyUwnXrVQm2L kZf6HVSbK9vp5kjiQzTmFsu9ZkT2GVXmYCA9mYErTiLkVBqLlvkl3Nu/HzSgAQ0XU8/d ESu8K8OEwNtpopnmcc5I7BAe3kj4hbaFdN0BK0a1oW+LR2Q+aRbCaxQeUYdrq+/PwL4o gYBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@synopsys.com header.s=mail header.b=ENRW7mrv; 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=synopsys.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s1si614858ejv.304.2021.02.03.14.01.09; Wed, 03 Feb 2021 14:01:33 -0800 (PST) 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=@synopsys.com header.s=mail header.b=ENRW7mrv; 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=synopsys.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232713AbhBCV75 (ORCPT + 99 others); Wed, 3 Feb 2021 16:59:57 -0500 Received: from smtprelay-out1.synopsys.com ([149.117.73.133]:60262 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232578AbhBCV7W (ORCPT ); Wed, 3 Feb 2021 16:59:22 -0500 Received: from mailhost.synopsys.com (mdc-mailhost1.synopsys.com [10.225.0.209]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id A84C040494; Wed, 3 Feb 2021 21:58:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1612389501; bh=26bcMb1hhhSb/6zwC97LYr49GH4oBhX47qSAAxTu+pw=; h=From:To:Subject:Date:In-Reply-To:References:In-Reply-To: References:From; b=ENRW7mrv1cpANCM8T/OohSKUTaRnrXJVIRU8l0Oq1/F7c9kQFfiWwXqDK6J8IkpJO j7I8Gd7Gyn5xxq756bbjdW2krXnF7VYOq/iBim5JjoH7jFGnAIA/s/G1VHr9pQXVKY yHPqLPX1z/g1qCifw72SGedEX5oUfPX7fzikAlIkdhOdsowr8bxVJiUfa9DOl1NbOk wxek/wuFBWjNRcBCAnJSe8lkxS3u5yE/xq44kgjgZzwYkVUNYo4q8lvNnjFSzq91Hm C3kO+ejVK2mgzZgGRdjgmUwoz2CTAHMohFZnzNU9Y7Dp8znKoDH465qtJD5DeMZ+bC WTs1gspPALodw== Received: from de02dwia024.internal.synopsys.com (de02dwia024.internal.synopsys.com [10.225.19.81]) by mailhost.synopsys.com (Postfix) with ESMTP id 7B7FDA024A; Wed, 3 Feb 2021 21:58:20 +0000 (UTC) X-SNPS-Relay: synopsys.com From: Gustavo Pimentel To: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, dmaengine@vger.kernel.org, Vinod Koul , Dan Williams , Bjorn Helgaas , Gustavo Pimentel Subject: [PATCH v4 07/15] dmaengine: dw-edma: Improve number of channels check Date: Wed, 3 Feb 2021 22:57:58 +0100 Message-Id: <1a42fc97b18012925454013a64b901e06683c77b.1612389406.git.gustavo.pimentel@synopsys.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It was added some extra checks to ensure that the driver doesn't try to use more DMA channels than actually are available in hardware. Signed-off-by: Gustavo Pimentel --- drivers/dma/dw-edma/dw-edma-core.c | 21 +++++++++------------ drivers/dma/dw-edma/dw-edma-core.h | 2 ++ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/drivers/dma/dw-edma/dw-edma-core.c b/drivers/dma/dw-edma/dw-edma-core.c index 0fe3835..5495cf7 100644 --- a/drivers/dma/dw-edma/dw-edma-core.c +++ b/drivers/dma/dw-edma/dw-edma-core.c @@ -914,19 +914,16 @@ int dw_edma_probe(struct dw_edma_chip *chip) raw_spin_lock_init(&dw->lock); - if (!dw->wr_ch_cnt) { - /* Find out how many write channels are supported by hardware */ - dw->wr_ch_cnt = dw_edma_v0_core_ch_count(dw, EDMA_DIR_WRITE); - if (!dw->wr_ch_cnt) - return -EINVAL; - } + dw->wr_ch_cnt = min_t(u16, dw->wr_ch_cnt, + dw_edma_v0_core_ch_count(dw, EDMA_DIR_WRITE)); + dw->wr_ch_cnt = min_t(u16, dw->wr_ch_cnt, EDMA_MAX_WR_CH); - if (!dw->rd_ch_cnt) { - /* Find out how many read channels are supported by hardware */ - dw->rd_ch_cnt = dw_edma_v0_core_ch_count(dw, EDMA_DIR_READ); - if (!dw->rd_ch_cnt) - return -EINVAL; - } + dw->rd_ch_cnt = min_t(u16, dw->rd_ch_cnt, + dw_edma_v0_core_ch_count(dw, EDMA_DIR_READ)); + dw->rd_ch_cnt = min_t(u16, dw->rd_ch_cnt, EDMA_MAX_RD_CH); + + if (!dw->wr_ch_cnt && !dw->rd_ch_cnt) + return -EINVAL; dev_vdbg(dev, "Channels:\twrite=%d, read=%d\n", dw->wr_ch_cnt, dw->rd_ch_cnt); diff --git a/drivers/dma/dw-edma/dw-edma-core.h b/drivers/dma/dw-edma/dw-edma-core.h index f72ebaa..650b1c7 100644 --- a/drivers/dma/dw-edma/dw-edma-core.h +++ b/drivers/dma/dw-edma/dw-edma-core.h @@ -15,6 +15,8 @@ #include "../virt-dma.h" #define EDMA_LL_SZ 24 +#define EDMA_MAX_WR_CH 8 +#define EDMA_MAX_RD_CH 8 enum dw_edma_dir { EDMA_DIR_WRITE = 0, -- 2.7.4