From patchwork Wed Jul 27 22:39:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Dooks X-Patchwork-Id: 12930845 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 56450C04A68 for ; Wed, 27 Jul 2022 22:41:29 +0000 (UTC) Received: from localhost ([::1]:36704 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oGpia-0006Rl-1d for qemu-devel@archiver.kernel.org; Wed, 27 Jul 2022 18:41:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33132) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oGpgU-0003gt-9t; Wed, 27 Jul 2022 18:39:18 -0400 Received: from cpc152649-stkp13-2-0-cust121.10-2.cable.virginm.net ([86.15.83.122]:52748 helo=luna) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oGpgR-0007uj-Gs; Wed, 27 Jul 2022 18:39:17 -0400 Received: from ben by luna with local (Exim 4.96) (envelope-from ) id 1oGpgI-002cQt-0E; Wed, 27 Jul 2022 23:39:06 +0100 From: Ben Dooks To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, Alistair Francis , qemu-arm@nongnu.org, Ben Dooks Subject: [PATCH v3 1/5] device_tree: add qemu_fdt_setprop_strings() helper Date: Wed, 27 Jul 2022 23:39:01 +0100 Message-Id: <20220727223905.624285-2-qemu@ben.fluff.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220727223905.624285-1-qemu@ben.fluff.org> References: <20220727223905.624285-1-qemu@ben.fluff.org> MIME-Version: 1.0 Received-SPF: none client-ip=86.15.83.122; envelope-from=ben@luna.fluff.org; helo=luna X-Spam_score_int: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 5.0 requ) BAYES_00=-1.9, FSL_HELO_NON_FQDN_1=0.001, HELO_NO_DOMAIN=0.001, KHOP_HELO_FCRDNS=0.187, PDS_RDNS_DYNAMIC_FP=0.001, RCVD_IN_SORBS_DUL=0.001, RDNS_DYNAMIC=0.982, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Add a helper to set a property from a set of strings to reduce the following code: static const char * const clint_compat[2] = { "sifive,clint0", "riscv,clint0" }; qemu_fdt_setprop_string_array(fdt, nodename, "compatible", (char **)&clint_compat, ARRAY_SIZE(clint_compat)); Signed-off-by: Ben Dooks --- v3; - fix return value for the call - add better help text v2: - fix node/path in comment --- include/sysemu/device_tree.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/include/sysemu/device_tree.h b/include/sysemu/device_tree.h index ef060a9759..83bdfe390e 100644 --- a/include/sysemu/device_tree.h +++ b/include/sysemu/device_tree.h @@ -87,6 +87,25 @@ int qemu_fdt_setprop_string(void *fdt, const char *node_path, int qemu_fdt_setprop_string_array(void *fdt, const char *node_path, const char *prop, char **array, int len); +/** + * qemu_fdt_setprop_strings: set a property from a set of strings + * + * @fdt: pointer to the dt blob + * @path: node name + * @prop: property array + * + * This is a helper for the qemu_fdt_setprop_string_array() function + * which takes a va-arg set of strings instead of having to setup a + * single use string array. + */ +#define qemu_fdt_setprop_strings(fdt, path, prop, ...) \ + ({ int __ret; do { \ + static const char * const __strs[] = { __VA_ARGS__ }; \ + __ret = qemu_fdt_setprop_string_array(fdt, path, prop, \ + (char **)&__strs, ARRAY_SIZE(__strs)); \ + } while(0); __ret; }) + + int qemu_fdt_setprop_phandle(void *fdt, const char *node_path, const char *property, const char *target_node_path);