From patchwork Mon Oct 12 16:48:41 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 54807 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by patches.linaro.org (Postfix) with ESMTPS id CE5DA23001 for ; Mon, 12 Oct 2015 16:49:03 +0000 (UTC) Received: by wijq8 with SMTP id q8sf36761943wij.1 for ; Mon, 12 Oct 2015 09:49:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=DiYPKq2ytaDeJAavsZbokLPrhIC7zy+kGIXT4hN1oNA=; b=HCoaFfzP3Coo3NpJSrcSXYtbjqL300zjWXmg0nROhES9yYjMtZs1rfPbVFFXS297Ku WsW/9UIemKKi2fK1UXP+ZZc75t3+20tMG/3RQLLzEkIMNBl+7fHVyjaTRtUZxo+Fz6mv 9UCwOYS6bxZwswmnmfDVyfAsWdaHETf0ns0TFaOR8Vw6wH0ZP7vAju963OaBmQkWVp1O qpSSgkH2Dq4DzpycKRZlNnnFNE9RCvJROGX0GHr0yZeHN+K9VLJ9eHMcZW3ChqTRjngO R0amiv5P3E+wHuQsXG85TwLJpeAmS+aYv1oAKvPiQ/MZhMuHgRWu7hM6A/VvAEaOD/vR B88A== X-Gm-Message-State: ALoCoQk+GJlFufwN2EulXLRk+wkZ0sp2w2cceEbpJFGka7wB5xcrMKHdJUkO5Ugk8CS7QqRYYmO8 X-Received: by 10.194.192.71 with SMTP id he7mr2284423wjc.2.1444668543184; Mon, 12 Oct 2015 09:49:03 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.23.155 with SMTP id 27ls564313lfx.49.gmail; Mon, 12 Oct 2015 09:49:03 -0700 (PDT) X-Received: by 10.25.167.138 with SMTP id q132mr8430217lfe.15.1444668543032; Mon, 12 Oct 2015 09:49:03 -0700 (PDT) Received: from mail-lb0-f180.google.com (mail-lb0-f180.google.com. [209.85.217.180]) by mx.google.com with ESMTPS id m8si9641910lfm.14.2015.10.12.09.49.03 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Oct 2015 09:49:03 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.180 as permitted sender) client-ip=209.85.217.180; Received: by lbbk10 with SMTP id k10so36802789lbb.0 for ; Mon, 12 Oct 2015 09:49:02 -0700 (PDT) X-Received: by 10.25.40.130 with SMTP id o124mr8232475lfo.41.1444668542931; Mon, 12 Oct 2015 09:49:02 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.59.35 with SMTP id w3csp1650590lbq; Mon, 12 Oct 2015 09:49:02 -0700 (PDT) X-Received: by 10.180.39.136 with SMTP id p8mr16679886wik.10.1444668539751; Mon, 12 Oct 2015 09:48:59 -0700 (PDT) Received: from mail-wi0-f171.google.com (mail-wi0-f171.google.com. [209.85.212.171]) by mx.google.com with ESMTPS id lp12si17083284wic.50.2015.10.12.09.48.59 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Oct 2015 09:48:59 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 209.85.212.171 as permitted sender) client-ip=209.85.212.171; Received: by wijq8 with SMTP id q8so66644128wij.0 for ; Mon, 12 Oct 2015 09:48:59 -0700 (PDT) X-Received: by 10.194.222.227 with SMTP id qp3mr36896611wjc.36.1444668539570; Mon, 12 Oct 2015 09:48:59 -0700 (PDT) Received: from localhost.localdomain.home (LCaen-156-56-7-90.w80-11.abo.wanadoo.fr. [80.11.198.90]) by smtp.gmail.com with ESMTPSA id xt1sm20805130wjb.32.2015.10.12.09.48.57 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 12 Oct 2015 09:48:58 -0700 (PDT) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, qemu-devel@nongnu.org, alex.williamson@redhat.com Cc: patches@linaro.org, christoffer.dall@linaro.org, pbonzini@redhat.com, b.reynal@virtualopensystems.com, suravee.suthikulpanit@amd.com, thomas.lendacky@amd.com Subject: [RFC 4/6] device_tree: introduce qemu_fdt_getprop_optional Date: Mon, 12 Oct 2015 16:48:41 +0000 Message-Id: <1444668523-2252-5-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1444668523-2252-1-git-send-email-eric.auger@linaro.org> References: <1444668523-2252-1-git-send-email-eric.auger@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: eric.auger@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.180 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Current qemu_fdt_getprop exits if the property is not found. It is sometimes needed to read an optional property, in which case we do not wish to exit but simply returns a null value. This is what this new qemu_fdt_getprop_optional function does. Signed-off-by: Eric Auger --- device_tree.c | 17 +++++++++++++++++ include/sysemu/device_tree.h | 2 ++ 2 files changed, 19 insertions(+) diff --git a/device_tree.c b/device_tree.c index f184e3c..a318683 100644 --- a/device_tree.c +++ b/device_tree.c @@ -280,6 +280,23 @@ const void *qemu_fdt_getprop(void *fdt, const char *node_path, return r; } +const void *qemu_fdt_getprop_optional(void *fdt, const char *node_path, + const char *property, bool optional, int *lenp) +{ + int len; + const void *r; + if (!lenp) { + lenp = &len; + } + r = fdt_getprop(fdt, findnode_nofail(fdt, node_path), property, lenp); + if (!r && !optional) { + error_report("%s: Couldn't get %s/%s: %s", __func__, + node_path, property, fdt_strerror(*lenp)); + exit(1); + } + return r; +} + uint32_t qemu_fdt_getprop_cell(void *fdt, const char *node_path, const char *property) { diff --git a/include/sysemu/device_tree.h b/include/sysemu/device_tree.h index f9e6e6e..10cbe8e 100644 --- a/include/sysemu/device_tree.h +++ b/include/sysemu/device_tree.h @@ -34,6 +34,8 @@ int qemu_fdt_setprop_phandle(void *fdt, const char *node_path, const char *target_node_path); const void *qemu_fdt_getprop(void *fdt, const char *node_path, const char *property, int *lenp); +const void *qemu_fdt_getprop_optional(void *fdt, const char *node_path, + const char *property, bool optional, int *lenp); uint32_t qemu_fdt_getprop_cell(void *fdt, const char *node_path, const char *property); uint32_t qemu_fdt_get_phandle(void *fdt, const char *path);