From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A0C6AC433DF for ; Thu, 15 Oct 2020 16:54:13 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 30EC12068D for ; Thu, 15 Oct 2020 16:54:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="RQeuMWZG" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 30EC12068D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Type: Content-Transfer-Encoding:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:From: References:To:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=0Fidb/1TK1pTwrfZGi087B+7H4FrsUPDs7xzEilHCcg=; b=RQeuMWZGBi6zcHlD7smLVx9QX jipY9IcGkRWom5czGOmAQhFnQ50MiOBSAqCn7KGwTDkS4RGnoCecUzOM6MhHp85oMj55lh7TdpjmF 4ZsXXbz4VEuagnILybNLHdvRdOK0loOMCQdAxRMthlyF+UdgNXWEcmweMFiEAOyHT0VfT5IcwDaMQ EM5G6bSyvpkwm4DGLK1war2yNIyv4vEoxyIf90knVRq30doG8RUK0HFEiL0O7ltxelhOwWQHPGdOJ TlArO43Rf9imjcrzY4Z7tXPgOL5q3LTIdMeteU0Yq5Az2BW3gOTkN9fynw96iy4+JlkuFdV+y/pwC maTCgw5zw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kT6Ug-00037G-8N; Thu, 15 Oct 2020 16:52:46 +0000 Received: from foss.arm.com ([217.140.110.172]) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kT6Ud-00036V-8Q; Thu, 15 Oct 2020 16:52:44 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id CFB08D6E; Thu, 15 Oct 2020 09:52:38 -0700 (PDT) Received: from [10.57.48.76] (unknown [10.57.48.76]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D8F013F71F; Thu, 15 Oct 2020 09:52:36 -0700 (PDT) Subject: Re: [PATCH 1/7] of: base: Add of_count_phandle_with_fixed_args() To: Rob Herring , Richard Fitzgerald References: <20201014145418.31838-1-rf@opensource.cirrus.com> <20201014145418.31838-2-rf@opensource.cirrus.com> From: Robin Murphy Message-ID: <90600a67-25e4-7933-35c3-f515deaee94f@arm.com> Date: Thu, 15 Oct 2020 17:52:35 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Thunderbird/78.3.2 MIME-Version: 1.0 In-Reply-To: Content-Language: en-GB X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201015_125243_391075_52FE079B X-CRM114-Status: GOOD ( 28.73 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Linux-ALSA , - , "linux-kernel@vger.kernel.org" , Mark Brown , Nicolas Saenz Julienne , linux-arm-kernel , "moderated list:BROADCOM BCM2835 ARM ARCHITECTURE" Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 :/ Robin. >> + } >> + >> + rc = of_phandle_iterator_init(&it, np, list_name, NULL, cells_count); >> + if (rc) >> + return rc; >> + >> + while ((rc = of_phandle_iterator_next(&it)) == 0) >> + cur_index += 1; >> + >> + if (rc != -ENOENT) >> + return rc; >> + >> + return cur_index; >> +} >> +EXPORT_SYMBOL(of_count_phandle_with_fixed_args); >> + >> /** >> * __of_add_property - Add a property to a node without lock operations >> */ >> diff --git a/include/linux/of.h b/include/linux/of.h >> index 5cf7ae0465d1..9f315da4e9da 100644 >> --- a/include/linux/of.h >> +++ b/include/linux/of.h >> @@ -377,6 +377,8 @@ extern int of_parse_phandle_with_fixed_args(const struct device_node *np, >> struct of_phandle_args *out_args); >> extern int of_count_phandle_with_args(const struct device_node *np, >> const char *list_name, const char *cells_name); >> +extern int of_count_phandle_with_fixed_args(const struct device_node *np, >> + const char *list_name, int cells_count); >> >> /* phandle iterator functions */ >> extern int of_phandle_iterator_init(struct of_phandle_iterator *it, >> @@ -886,6 +888,13 @@ static inline int of_count_phandle_with_args(struct device_node *np, >> return -ENOSYS; >> } >> >> +static inline int of_count_phandle_with_fixed_args(const struct device_node *np, >> + const char *list_name, >> + int cells_count) >> +{ >> + return -ENOSYS; >> +} >> + >> static inline int of_phandle_iterator_init(struct of_phandle_iterator *it, >> const struct device_node *np, >> const char *list_name, >> -- >> 2.20.1 >> > > _______________________________________________ > linux-arm-kernel mailing list > linux-arm-kernel@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel