From patchwork Tue Mar 22 17:58:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joerg Roedel X-Patchwork-Id: 8644571 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 7E9E0C0553 for ; Tue, 22 Mar 2016 18:02:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8DB972034B for ; Tue, 22 Mar 2016 18:02:34 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A1835201ED for ; Tue, 22 Mar 2016 18:02:32 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aiQbm-0007x8-FJ; Tue, 22 Mar 2016 18:00:46 +0000 Received: from 8bytes.org ([2a01:238:4383:600:38bc:a715:4b6d:a889] helo=theia.8bytes.org) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aiQaW-0005sc-4C for linux-arm-kernel@lists.infradead.org; Tue, 22 Mar 2016 17:59:33 +0000 Received: by theia.8bytes.org (Postfix, from userid 1000) id CBE576721; Tue, 22 Mar 2016 18:58:35 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=8bytes.org; s=mail-1; t=1458669515; bh=kFlDIVoNQ423wTvLMTWL6RRO2COHaDZ+PuT6oDIp3bM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GaTpkfjyXOBZjE8P5FZnZQbIrI+NKHw/8SB04/90o/IJUS7iNZFe1wrZHVRtQpzcg /qN0WVMrWE3N3ngS0q2fyZsp2g7UoGRvZRavtN6iso+5OX86hn5zYUIoFxzl9ek9Vn ES90tP+J8k+nTbKINGAX5QZakyVvrkhXhJxKM6QR1vi3zl6ULq8ghVUmejEtpCv3fL NR3yk4Xol+hzaT27sVjpkLmj6i376hM0ohZlprRmNDcOR8qAqABWbtVzgaWT1gTAug z6uH/OV3GAvr2qiwt/etS0xJPSiFY61Pus74mG7NPqWcsKIJVauHdLMjpzVMN2TYU2 x9nVH7hAVzbrQ== From: Joerg Roedel To: Rob Herring , grant.likely@linaro.org Subject: [PATCH 5/6] of: Introduce of_phandle_iterator_args() Date: Tue, 22 Mar 2016 18:58:28 +0100 Message-Id: <1458669509-7178-6-git-send-email-joro@8bytes.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1458669509-7178-1-git-send-email-joro@8bytes.org> References: <1458669509-7178-1-git-send-email-joro@8bytes.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160322_105928_661656_27C1AFF9 X-CRM114-Status: GOOD ( 13.66 ) X-Spam-Score: -2.0 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, jroedel@suse.de, Will Deacon , linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Joerg Roedel This helper function can be used to copy the arguments of a phandle to an array. Signed-off-by: Joerg Roedel --- drivers/of/base.c | 29 +++++++++++++++++++++++------ include/linux/of.h | 10 ++++++++++ 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/drivers/of/base.c b/drivers/of/base.c index 471d3d9..008988b 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -1533,6 +1533,23 @@ err: return -EINVAL; } +int of_phandle_iterator_args(struct of_phandle_iterator *it, + uint32_t *args, + int size) +{ + int i, count; + + count = it->cur_count; + + if (WARN_ON(size < count)) + count = size; + + for (i = 0; i < count; i++) + args[i] = be32_to_cpup(it->cur++); + + return count; +} + static int __of_parse_phandle_with_args(const struct device_node *np, const char *list_name, const char *cells_name, @@ -1556,13 +1573,13 @@ static int __of_parse_phandle_with_args(const struct device_node *np, goto err; if (out_args) { - int i; - if (WARN_ON(it.cur_count > MAX_PHANDLE_ARGS)) - it.cur_count = MAX_PHANDLE_ARGS; + int c; + + c = of_phandle_iterator_args(&it, + out_args->args, + MAX_PHANDLE_ARGS); out_args->np = it.node; - out_args->args_count = it.cur_count; - for (i = 0; i < it.cur_count; i++) - out_args->args[i] = be32_to_cpup(it.cur++); + out_args->args_count = c; } else { of_node_put(it.node); } diff --git a/include/linux/of.h b/include/linux/of.h index 05e38ed..c91f8b1 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -359,6 +359,9 @@ extern int of_phandle_iterator_init(struct of_phandle_iterator *it, int cell_count); extern int of_phandle_iterator_next(struct of_phandle_iterator *it); +extern int of_phandle_iterator_args(struct of_phandle_iterator *it, + uint32_t *args, + int size); extern void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align)); extern int of_alias_get_id(struct device_node *np, const char *stem); @@ -648,6 +651,13 @@ static inline int of_phandle_iterator_next(struct of_phandle_iterator *it) return -ENOSYS; } +static inline int of_phandle_iterator_args(struct of_phandle_iterator *it, + uint32_t *args, + int size) +{ + return 0; +} + static inline int of_alias_get_id(struct device_node *np, const char *stem) { return -ENOSYS;