Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp1205012pxu; Fri, 16 Oct 2020 06:35:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzwwGMPWWG0vuppcDzLWK+gQ2QmjcBs1n4ydQIhet6ZUYvOwB5XrxvzcPC5yj+OBpBbp5o7 X-Received: by 2002:a05:6402:384:: with SMTP id o4mr3933303edv.387.1602855334612; Fri, 16 Oct 2020 06:35:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602855334; cv=none; d=google.com; s=arc-20160816; b=HAXttkKOc9AX8nAka9aTfetN2kKmhwekrS1GmQUxDNJbfs7Xkj5VZXvnt1ko8LPj+M 9roJ+ZZFQZ8l4VfsMeKhhA7f5VQZN+6ICBFtSUIk7wPrDv+xThY8igXDzwP14fLgCanM NTei28E4Utwny4WzssU1e45mh6SLiF54sOu7ZrrQTMwSv6f2XqWkre5Ai5chlkgsUydo ZKyhkL8SukKBOmj76SoOBiBPOf62+padZ+VDvb9J9Vm+R79KaRTua2JjGb9MMyCeeJN3 D+KuL+qmr7B9XMThaR8RCo7UBS8QhgeNWPdQJU+XnCUFRf8iFAnqrfBnypUd3WNpg9eL 1cvg== 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=hrZFlc2HwDobarYDVw/MStM5iukiemEJJ/SvvXunqbk=; b=iEPmQizoVHuv88CGcPGxGMK1gvvGRydBYnnzoWKkDb7gTY0iuimj+5JXjJRei7YISS 19oO+sw10JfGrmPcw2LCS5UWV9XukCCs2rs6j4a1JqW4BxZdW/p6ldpdTz245Wan+RjQ b+MPM5KSqp0Q3Evt2FD2FUVxPyPdaBQzY0faGVhTLLzKxMnnGNfUt9vsobyWPL86Wulk If3nOdxzSeGIB9jeyQOOdw+AkHjV5rRYz/kRjRjAk26PrpKq/veQFdjrBFWLmSGeS57p YG7cNVwbroCszU9zjs1J9yYDeU4kwVnSsJKuGYU8Xr/0X1q56XubK/Qgy4IZ+0p5HYT9 4IOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=uI2me769; 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 h26si1762085ejd.572.2020.10.16.06.35.12; Fri, 16 Oct 2020 06:35:34 -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=default header.b=uI2me769; 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 S2408085AbgJPNcB (ORCPT + 99 others); Fri, 16 Oct 2020 09:32:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:42404 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2408074AbgJPNcA (ORCPT ); Fri, 16 Oct 2020 09:32:00 -0400 Received: from mail-oi1-f181.google.com (mail-oi1-f181.google.com [209.85.167.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D433E21527; Fri, 16 Oct 2020 13:31:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602855120; bh=jHgolZn+yVwazInZpUXsUIXLz+WFq+LCgt1cjWpEkcA=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=uI2me769AwM75eyyDkh95DsmJO9h6Qvu8z0Ayc7beFMa6u/y6sPTX58dfz9663RqB 2zP0XAvHzdeE75ZAtl270HHG5NqWq89oDsrxpoLa+652g3AM6k+qlqenzQba0AHyAX Fk5C7pqNZ14YtAy/k6zL/cWuHXg3qD5gkOKP2phA= Received: by mail-oi1-f181.google.com with SMTP id 16so2411031oix.9; Fri, 16 Oct 2020 06:31:59 -0700 (PDT) X-Gm-Message-State: AOAM531+LIxpTqrMmcL/XbCzmpoGptAhH0QLmFIKyG8bSoLXt/8YLBoH MuYoHrJzKLiIuTsl5v29o+6kFpt6Qw74P+kGgQ== X-Received: by 2002:a54:4f89:: with SMTP id g9mr2514377oiy.106.1602855119044; Fri, 16 Oct 2020 06:31:59 -0700 (PDT) MIME-Version: 1.0 References: <20201014145418.31838-1-rf@opensource.cirrus.com> <20201014145418.31838-2-rf@opensource.cirrus.com> <90600a67-25e4-7933-35c3-f515deaee94f@arm.com> In-Reply-To: <90600a67-25e4-7933-35c3-f515deaee94f@arm.com> From: Rob Herring Date: Fri, 16 Oct 2020 08:31:47 -0500 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 1/7] of: base: Add of_count_phandle_with_fixed_args() To: Robin Murphy , Richard Fitzgerald Cc: devicetree@vger.kernel.org, Linux-ALSA , - , "linux-kernel@vger.kernel.org" , Mark Brown , linux-arm-kernel , Nicolas Saenz Julienne , "moderated list:BROADCOM BCM2835 ARM ARCHITECTURE" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 15, 2020 at 11:52 AM Robin Murphy wrote: > > On 2020-10-14 19:39, Rob Herring wrote: > > On Wed, Oct 14, 2020 at 9:54 AM Richard Fitzgerald > > wrote: > >> > >> Add an equivalent of of_count_phandle_with_args() for fixed argument > >> sets, to pair with of_parse_phandle_with_fixed_args(). > >> > >> Signed-off-by: Richard Fitzgerald > >> --- > >> drivers/of/base.c | 42 ++++++++++++++++++++++++++++++++++++++++++ > >> include/linux/of.h | 9 +++++++++ > >> 2 files changed, 51 insertions(+) > >> > >> diff --git a/drivers/of/base.c b/drivers/of/base.c > >> index ea44fea99813..45d8b0e65345 100644 > >> --- a/drivers/of/base.c > >> +++ b/drivers/of/base.c > >> @@ -1772,6 +1772,48 @@ int of_count_phandle_with_args(const struct device_node *np, const char *list_na > >> } > >> EXPORT_SYMBOL(of_count_phandle_with_args); > >> > >> +/** > >> + * of_count_phandle_with_fixed_args() - Find the number of phandles references in a property > >> + * @np: pointer to a device tree node containing a list > >> + * @list_name: property name that contains a list > >> + * @cell_count: number of argument cells following the phandle > >> + * > >> + * Returns the number of phandle + argument tuples within a property. It > >> + * is a typical pattern to encode a list of phandle and variable > >> + * arguments into a single property. > >> + */ > >> +int of_count_phandle_with_fixed_args(const struct device_node *np, > >> + const char *list_name, > >> + int cells_count) > >> +{ > > > > Looks to me like you can refactor of_count_phandle_with_args to handle > > both case and then make this and of_count_phandle_with_args simple > > wrapper functions. > > Although for just counting the number of phandles each with n arguments > that a property contains, isn't that simply a case of dividing the > property length by n + 1? The phandles themselves will be validated by > any subsequent of_parse_phandle*() call anyway, so there doesn't seem > much point in doing more work then necessary here. > > >> + struct of_phandle_iterator it; > >> + int rc, cur_index = 0; > >> + > >> + if (!cells_count) { > >> + const __be32 *list; > >> + int size; > >> + > >> + list = of_get_property(np, list_name, &size); > >> + if (!list) > >> + return -ENOENT; > >> + > >> + return size / sizeof(*list); > > Case in point - if it's OK to do exactly that for n == 0, then clearly > we're *aren't* fussed about validating anything, so the n > 0 code below > is nothing more than a massively expensive way to check for a nonzero > remainder :/ Indeed. We should just generalize this. It can still be refactored to shared code. It's probably worthwhile to check for a remainder here IMO. Rob