diff options
author | Marc-André Lureau <marcandre.lureau@redhat.com> | 2023-02-28 14:53:12 +0400 |
---|---|---|
committer | David Gibson <david@gibson.dropbear.id.au> | 2023-03-01 18:43:15 +1100 |
commit | 6f8b28f496093156ae126b434ed753094943da03 (patch) | |
tree | 4cca5d79b64f4b58eb784f04b14768f3d7b7274e /livetree.c | |
parent | fd68bb8c56587114fa6eeed39c36c4b347a6a5fc (diff) | |
download | dtc-6f8b28f496093156ae126b434ed753094943da03.zip dtc-6f8b28f496093156ae126b434ed753094943da03.tar.gz dtc-6f8b28f496093156ae126b434ed753094943da03.tar.bz2 |
livetree: fix leak spotted by ASAN
./dtc -I dts -O dtb -o overlay_base_manual_symbols.test.dtb /home/elmarco/src/dtc/tests/overlay_base_manual_symbols.dts
../data.c:109:2: runtime error: null pointer passed as argument 2, which is declared to never be null
=================================================================
==933317==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 24 byte(s) in 1 object(s) allocated from:
#0 0x7f49a2aba6af in __interceptor_malloc (/lib64/libasan.so.8+0xba6af)
#1 0x43183d in xmalloc ../util.h:45
#2 0x43482f in data_add_marker ../data.c:230
#3 0x449bb8 in get_node_phandle ../livetree.c:632
#4 0x421058 in fixup_phandle_references ../checks.c:627
#5 0x41b0ba in check_nodes_props ../checks.c:141
#6 0x41b1c8 in check_nodes_props ../checks.c:144
#7 0x41b9f1 in run_check ../checks.c:181
#8 0x430a68 in process_checks ../checks.c:2057
#9 0x436abd in main ../dtc.c:327
#10 0x7f49a30d850f in __libc_start_call_main (/lib64/libc.so.6+0x2750f)
Only create data when necessary, and do not alias it.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
[dwg: Small fixup for a slightly different approach to adjacent cleanups]
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'livetree.c')
-rw-r--r-- | livetree.c | 29 |
1 files changed, 18 insertions, 11 deletions
@@ -617,10 +617,25 @@ struct node *get_node_by_ref(struct node *tree, const char *ref) return target; } +static void add_phandle_property(struct node *node, + const char *name, int format) +{ + struct data d; + + if (!(phandle_format & format)) + return; + if (get_property(node, name)) + return; + + d = data_add_marker(empty_data, TYPE_UINT32, NULL); + d = data_append_cell(d, node->phandle); + + add_property(node, build_property(name, d, NULL)); +} + cell_t get_node_phandle(struct node *root, struct node *node) { static cell_t phandle = 1; /* FIXME: ick, static local */ - struct data d = empty_data; if (phandle_is_valid(node->phandle)) return node->phandle; @@ -630,16 +645,8 @@ cell_t get_node_phandle(struct node *root, struct node *node) node->phandle = phandle; - d = data_add_marker(d, TYPE_UINT32, NULL); - d = data_append_cell(d, phandle); - - if (!get_property(node, "linux,phandle") - && (phandle_format & PHANDLE_LEGACY)) - add_property(node, build_property("linux,phandle", d, NULL)); - - if (!get_property(node, "phandle") - && (phandle_format & PHANDLE_EPAPR)) - add_property(node, build_property("phandle", d, NULL)); + add_phandle_property(node, "linux,phandle", PHANDLE_LEGACY); + add_phandle_property(node, "phandle", PHANDLE_EPAPR); /* If the node *does* have a phandle property, we must * be dealing with a self-referencing phandle, which will be |