From 69bed6c2418f484561263aadbb886ffb925e6b38 Mon Sep 17 00:00:00 2001 From: Andre Przywara Date: Fri, 18 Jun 2021 18:20:28 +0100 Subject: dtc: Wrap phandle validity check In several places we check for a returned phandle value to be valid, for that it must not be 0 or "-1". Wrap this check in a static inline function in dtc.h, and use ~0U instead of -1 on the way, to keep everything in the unsigned realm. Signed-off-by: Andre Przywara Message-Id: <20210618172030.9684-4-andre.przywara@arm.com> Signed-off-by: David Gibson --- dtc.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'dtc.h') diff --git a/dtc.h b/dtc.h index 47664f2..cf2c6ac 100644 --- a/dtc.h +++ b/dtc.h @@ -51,6 +51,11 @@ extern int annotate; /* annotate .dts with input source location */ typedef uint32_t cell_t; +static inline bool phandle_is_valid(cell_t phandle) +{ + return phandle != 0 && phandle != ~0U; +} + static inline uint16_t dtb_ld16(const void *p) { const uint8_t *bp = (const uint8_t *)p; -- cgit v1.2.1