Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1370353pxb; Fri, 21 Jan 2022 16:46:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJzD6EcKL3oCTHUo1bQbnC3eGrRoRY8mR/FtRrr4baDVRKwNmHyQi/MncRoriDdswUStmvFx X-Received: by 2002:a62:14d5:0:b0:4c7:43cb:863 with SMTP id 204-20020a6214d5000000b004c743cb0863mr5776449pfu.23.1642812415744; Fri, 21 Jan 2022 16:46:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642812415; cv=none; d=google.com; s=arc-20160816; b=K0I9iolvdvPAutcg/63itJQYDry66zgupbDDED6xCRXv2FgwjXB6qKZwMe/BRw8NMG pelsr01/ucVfX2EriMVc58GM6ilO+QyvnCQCJZdG9AAOJ/IrWruKcqbb/GUynILWOSnj sAsywuuwDEzCezz5SuJYHUv34BqpdhFQ3qseF/tH+olxyvY7C49jFWhLQAp/UUqeIRDh eFwoD52fDlAwDu7abOd+icqpx19H7mz8Zij4eJZ+MuJ6dc5+YF4H/4lLveqsSg4Nebw0 MPA15rmmYCWAxT8LxP9ZdLQqSCkWJay2zsCV2oKBg6xuDe87THdEbjYiTwithHS7DkmO QXdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=O8w6xWRpa7rbpkggVeukinLzBFh9GxZQwFDGtpRnC44=; b=SkU0JN7Tq2VRp6Is5VT6pm3Qntn9iMNVClJ8i8h2wOGtVwJNz8tQK6vghIYBf2jYR4 mfZzcKc1S8yBVq/ijaFJEmg1iKGslyn1/ohSLx8xJyq7EAZCMYWlJHtX+FR7zxB7Vs5P VaNsofYTWlLeNyr2kBZ+VL7uIc+TVRzgpII/LEWs7E/M4E5D+8cBnN6LxIAhoI4KPwPy +WJj5Tt5/I//+PpAR6Y9RttpE4T31jgyL5LGyRhOA1J9LFstEExU8CYtr698IqnslKRX HfhMqrsBZvF2aPx5e86Y3bjcXDMwUDr5G2dhY1nha9xQ1ZbOqnf/OzF0hOwWAUJUNCT0 95kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=m52NB69o; 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 s198si7166093pgs.316.2022.01.21.16.46.44; Fri, 21 Jan 2022 16:46:55 -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=@sifive.com header.s=google header.b=m52NB69o; 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 S1380013AbiAUK33 (ORCPT + 99 others); Fri, 21 Jan 2022 05:29:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380006AbiAUK31 (ORCPT ); Fri, 21 Jan 2022 05:29:27 -0500 Received: from mail-yb1-xb2d.google.com (mail-yb1-xb2d.google.com [IPv6:2607:f8b0:4864:20::b2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5BDCC061401 for ; Fri, 21 Jan 2022 02:29:27 -0800 (PST) Received: by mail-yb1-xb2d.google.com with SMTP id k31so24686832ybj.4 for ; Fri, 21 Jan 2022 02:29:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=O8w6xWRpa7rbpkggVeukinLzBFh9GxZQwFDGtpRnC44=; b=m52NB69onp/zx9ahchIitMVkr5LhjxaNcYFjkdcinu6bnm9NAQJTjMrHBbkgeM9OfC HXftb2G62xf1sm5KLZvxgQ3rvesY+Sc/YcBdei2LGNQPra9qIgiu+UDhbDLA/VlfLBNt skF2g3Rsb9f2kPHcPaRq4sQv1t9DmTSjopwjSJ3rTiLL8Eua0dYVlPgXR0O7SbecPdOj 6s2IrOUSUF9GNbarrDN+oMV7NtJ0sWXDzbFR7oEP8DyZq8+FHuynvTWwPi7p5nB5xNwS gYi+WSDxq/CnJBmKrW3oQXzXVfOQqViHni+3d2n5l4giZdSD6XLNDjEMoA6tfnqg5H1N /vOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=O8w6xWRpa7rbpkggVeukinLzBFh9GxZQwFDGtpRnC44=; b=y4JJfpybXwhhKaDMmRLJc8TveLfnR67NoPTrEUf2Gn17E6MFVCnqKJUePi1CX4y/O/ PrrT/k/W9SQG4GqxHcCT5c6FpPMCIBjPD4K5bW3dfl/UhTq4VWMen0KpvUxEyOHxhOnf E27gvKrRfxeW8G5BmAGbOYehUTL97GklpevIqjQ/MK5vwCVdvTtPnkWr/IKeF7BVBV0x a6YgZy6VaZhTtwBikbloaDRcD/bNad4LGGi0r48uC+zk+Tt52pOJe4CQFgppUoD3LMMh sWuw8co6OLbojfkaUFFWEg39k73mpZ1udK52X0NwLS8mNVzjnUYM3iLhYzUT3adXsBb8 R6aQ== X-Gm-Message-State: AOAM531vd3KtwAPx0G6j4fHcq6hvz7CPRDaXe7ORRBS49T0ViYR3aIZe iqEK5m9ngOw+iUjSkHbP6qKHaG8eH17pNBu++n9l/w== X-Received: by 2002:a25:2507:: with SMTP id l7mr5166575ybl.526.1642760966773; Fri, 21 Jan 2022 02:29:26 -0800 (PST) MIME-Version: 1.0 References: <0d0b0a3ad703f5ef50611e2dd80439675bda666a.1642383007.git.zong.li@sifive.com> In-Reply-To: From: Zong Li Date: Fri, 21 Jan 2022 18:29:15 +0800 Message-ID: Subject: Re: [PATCH v4 3/3] dmaengine: sf-pdma: Get number of channel by device tree To: Geert Uytterhoeven Cc: Palmer Dabbelt , Rob Herring , Paul Walmsley , Albert Ou , Krzysztof Kozlowski , Conor Dooley , Bin Meng , Green Wan , Vinod , dmaengine , "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" , "linux-kernel@vger.kernel.org List" , linux-riscv Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 21, 2022 at 4:33 PM Geert Uytterhoeven wrote: > > Hi Zong, Palmer, > > On Fri, Jan 21, 2022 at 3:21 AM Zong Li wrote: > > On Fri, Jan 21, 2022 at 2:52 AM Palmer Dabbelt wrote: > > > On Sun, 16 Jan 2022 17:35:28 PST (-0800), zong.li@sifive.com wrote: > > > > It currently assumes that there are always four channels, it would > > > > cause the error if there is actually less than four channels. Change > > > > that by getting number of channel from device tree. > > > > > > > > For backwards-compatible, it uses the default value (i.e. 4) when there > > > > is no 'dma-channels' information in dts. > > > > > > Some of the same wording issues here as those I pointed out in the DT > > > bindings patch. > > > > > > > Signed-off-by: Zong Li > > > > > --- a/drivers/dma/sf-pdma/sf-pdma.c > > > > +++ b/drivers/dma/sf-pdma/sf-pdma.c > > > > @@ -482,9 +482,7 @@ static void sf_pdma_setup_chans(struct sf_pdma *pdma) > > > > static int sf_pdma_probe(struct platform_device *pdev) > > > > { > > > > struct sf_pdma *pdma; > > > > - struct sf_pdma_chan *chan; > > > > struct resource *res; > > > > - int len, chans; > > > > int ret; > > > > const enum dma_slave_buswidth widths = > > > > DMA_SLAVE_BUSWIDTH_1_BYTE | DMA_SLAVE_BUSWIDTH_2_BYTES | > > > > @@ -492,13 +490,21 @@ static int sf_pdma_probe(struct platform_device *pdev) > > > > DMA_SLAVE_BUSWIDTH_16_BYTES | DMA_SLAVE_BUSWIDTH_32_BYTES | > > > > DMA_SLAVE_BUSWIDTH_64_BYTES; > > > > > > > > - chans = PDMA_NR_CH; > > > > - len = sizeof(*pdma) + sizeof(*chan) * chans; > > > > - pdma = devm_kzalloc(&pdev->dev, len, GFP_KERNEL); > > > > + pdma = devm_kzalloc(&pdev->dev, sizeof(*pdma), GFP_KERNEL); > > > > if (!pdma) > > > > return -ENOMEM; > > > > > > > > - pdma->n_chans = chans; > > > > + ret = of_property_read_u32(pdev->dev.of_node, "dma-channels", > > > > + &pdma->n_chans); > > > > + if (ret) { > > > > + dev_notice(&pdev->dev, "set number of channels to default value: 4\n"); > > > > + pdma->n_chans = PDMA_MAX_NR_CH; > > > > + } > > > > + > > > > + if (pdma->n_chans > PDMA_MAX_NR_CH) { > > > > + dev_err(&pdev->dev, "the number of channels exceeds the maximum\n"); > > > > + return -EINVAL; > > > > > > Can we get away with just using only the number of channels the driver > > > actually supports? ie, just never sending an op to the channels above > > > MAX_NR_CH? That should leave us with nothing to track. > > In theory we can... > > > It might be a bit like when pdma->n_chans is bigger than the maximum, > > set the pdma->chans to PDMA_MAX_NR_CH, then we could ensure that we > > don't access the channels above the maximum. If I understand > > correctly, I gave the similar thought in the thread of v2 patch, and > > there are some discussions on that, but this way seems to lead to > > hard-to-track problems. > > ... but that would mean that when a new variant appears that supports > more channels, no error is printed, and people might not notice > immediately that the higher channels are never used. > I guess people might need to follow the dt-bindings, so they couldn't specify the number of channels to the value which is more than maximum. But as you mentioned, if people don't notice that and specify it more than maximum, they wouldn't be aware that the higher channels are never used. It seems to me that we could keep returning the error there, or show a warning message and use PDMA_MAX_NR_CH in that situation, both looks good to me. > Gr{oetje,eeting}s, > > Geert > > -- > Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org > > In personal conversations with technical people, I call myself a hacker. But > when I'm talking to journalists I just say "programmer" or something like that. > -- Linus Torvalds