From patchwork Thu Nov 19 15:22:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 57023 Delivered-To: patches@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp3244821lbb; Thu, 19 Nov 2015 07:22:27 -0800 (PST) X-Received: by 10.28.11.71 with SMTP id 68mr11894637wml.77.1447946539988; Thu, 19 Nov 2015 07:22:19 -0800 (PST) Return-Path: Received: from mail-wm0-x233.google.com (mail-wm0-x233.google.com. [2a00:1450:400c:c09::233]) by mx.google.com with ESMTPS id dl6si11935891wjb.82.2015.11.19.07.22.19 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Nov 2015 07:22:19 -0800 (PST) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 2a00:1450:400c:c09::233 as permitted sender) client-ip=2a00:1450:400c:c09::233; Authentication-Results: mx.google.com; spf=pass (google.com: domain of eric.auger@linaro.org designates 2a00:1450:400c:c09::233 as permitted sender) smtp.mailfrom=eric.auger@linaro.org; dkim=pass header.i=@linaro-org.20150623.gappssmtp.com Received: by wmww144 with SMTP id w144so242970060wmw.1 for ; Thu, 19 Nov 2015 07:22:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=+a67LYZcOkfQOn9nOrqRstA5dW1nBhu4IQU1Pq53ELw=; b=lEJIU0UcPszcZ+nSHIK6KvhBYfGzUWEv+cwxeEKA2vtwbwZWWABGEA5ryZZPH9PTaQ zN2VETXvDXN9EiWdT9FgAiiUJGuxkmCpCd2dBk+0O/ce7rnABGSKHOOazCYPS7bl3JbY vWdD1hEBUBZJaJbvw7nk4BwSluHn12LqrW+85EI7oCnMN+YkHS8ygEiyyswRi7RIUCdR 2hzNOAU2GIFIoVDLqdVuTOKwlfkaHD57ubgQjcZUlogaj44eFvvzqPs7VxpZtuT2jDeb sVmbCV5gppSz8TFV8fVLrdFhy4nDE/0vcAlA5h7BUMh37LsaoaNZpr4ViXKc8HI6bQnW 8D/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+a67LYZcOkfQOn9nOrqRstA5dW1nBhu4IQU1Pq53ELw=; b=ZyWLDDOC7aFHev6jP8GjjCGlKm+OcO5yXvKz05L3tLgdWIcuBbrtMgSsasdjrQf4J7 jUDmEGG6nPh1n81SOjFdEtx1SJmU1OlDb8VzepmJ2DLuFBRaKcc2oRCX+La062/JX92c kC7pepyJr7+yx2ItAMzonwU3NPYuuf+ngaYERth9PqpDeeo+V3vFFulr74ZSpN0eGt/d 1nTtyv5MiBxlkNP9T+jFpJhv4B65eklV+tLbn8+/RN0djGbxNKiGwcKoQxQfhqkdoYUZ +9guExHZocDTIiYwkQfKuSMicLtCzME7jJPCdINO1iNNG2e+WXuaJjtkHMuUQzQZFC26 njFA== X-Gm-Message-State: ALoCoQk0tM/7wqKCBXn6JGkN91ytifdvoYXOO0pwN/d7MOgzQ6tHFUMpmTZo+1n023ZXLz1mZQI1 X-Received: by 10.28.184.134 with SMTP id i128mr11909509wmf.12.1447946539743; Thu, 19 Nov 2015 07:22:19 -0800 (PST) Return-Path: Received: from midway01-04-00.lavalab ([81.128.185.50]) by smtp.gmail.com with ESMTPSA id vr10sm8367221wjc.38.2015.11.19.07.22.18 (version=TLS1_1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Nov 2015 07:22:18 -0800 (PST) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, qemu-devel@nongnu.org, qemu-arm@nongnu.org, alex.williamson@redhat.com, peter.maydell@linaro.org Cc: patches@linaro.org, christoffer.dall@linaro.org, pbonzini@redhat.com, b.reynal@virtualopensystems.com, suravee.suthikulpanit@amd.com, thomas.lendacky@amd.com Subject: [RESEND RFC 4/6] device_tree: introduce qemu_fdt_getprop_optional Date: Thu, 19 Nov 2015 15:22:06 +0000 Message-Id: <1447946528-1533-5-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1447946528-1533-1-git-send-email-eric.auger@linaro.org> References: <1447946528-1533-1-git-send-email-eric.auger@linaro.org> 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(+) -- 1.8.3.2 Reviewed-by: Alex Bennée 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);