Revision ccbcfedd

b/device_tree.c
72 72
    return NULL;
73 73
}
74 74

  
75
int qemu_devtree_setprop(void *fdt, const char *node_path,
76
                         const char *property, void *val_array, int size)
75
static int findnode_nofail(void *fdt, const char *node_path)
77 76
{
78 77
    int offset;
79 78

  
80 79
    offset = fdt_path_offset(fdt, node_path);
81
    if (offset < 0)
82
        return offset;
80
    if (offset < 0) {
81
        fprintf(stderr, "%s Couldn't find node %s: %s\n", __func__, node_path,
82
                fdt_strerror(offset));
83
        exit(1);
84
    }
85

  
86
    return offset;
87
}
88

  
89
int qemu_devtree_setprop(void *fdt, const char *node_path,
90
                         const char *property, void *val_array, int size)
91
{
92
    int r;
93

  
94
    r = fdt_setprop(fdt, findnode_nofail(fdt, node_path), property, val_array, size);
95
    if (r < 0) {
96
        fprintf(stderr, "%s: Couldn't set %s/%s: %s\n", __func__, node_path,
97
                property, fdt_strerror(r));
98
        exit(1);
99
    }
83 100

  
84
    return fdt_setprop(fdt, offset, property, val_array, size);
101
    return r;
85 102
}
86 103

  
87 104
int qemu_devtree_setprop_cell(void *fdt, const char *node_path,
88 105
                              const char *property, uint32_t val)
89 106
{
90
    int offset;
107
    int r;
91 108

  
92
    offset = fdt_path_offset(fdt, node_path);
93
    if (offset < 0)
94
        return offset;
109
    r = fdt_setprop_cell(fdt, findnode_nofail(fdt, node_path), property, val);
110
    if (r < 0) {
111
        fprintf(stderr, "%s: Couldn't set %s/%s = %#08x: %s\n", __func__,
112
                node_path, property, val, fdt_strerror(r));
113
        exit(1);
114
    }
95 115

  
96
    return fdt_setprop_cell(fdt, offset, property, val);
116
    return r;
97 117
}
98 118

  
99 119
int qemu_devtree_setprop_string(void *fdt, const char *node_path,
100 120
                                const char *property, const char *string)
101 121
{
102
    int offset;
122
    int r;
103 123

  
104
    offset = fdt_path_offset(fdt, node_path);
105
    if (offset < 0)
106
        return offset;
124
    r = fdt_setprop_string(fdt, findnode_nofail(fdt, node_path), property, string);
125
    if (r < 0) {
126
        fprintf(stderr, "%s: Couldn't set %s/%s = %s: %s\n", __func__,
127
                node_path, property, string, fdt_strerror(r));
128
        exit(1);
129
    }
107 130

  
108
    return fdt_setprop_string(fdt, offset, property, string);
131
    return r;
109 132
}
110 133

  
111 134
int qemu_devtree_nop_node(void *fdt, const char *node_path)
112 135
{
113
    int offset;
136
    int r;
114 137

  
115
    offset = fdt_path_offset(fdt, node_path);
116
    if (offset < 0)
117
        return offset;
138
    r = fdt_nop_node(fdt, findnode_nofail(fdt, node_path));
139
    if (r < 0) {
140
        fprintf(stderr, "%s: Couldn't nop node %s: %s\n", __func__, node_path,
141
                fdt_strerror(r));
142
        exit(1);
143
    }
118 144

  
119
    return fdt_nop_node(fdt, offset);
145
    return r;
120 146
}
121 147

  
122 148
int qemu_devtree_add_subnode(void *fdt, const char *name)
123 149
{
124
    int offset;
125 150
    char *dupname = g_strdup(name);
126 151
    char *basename = strrchr(dupname, '/');
127 152
    int retval;
......
133 158
    basename[0] = '\0';
134 159
    basename++;
135 160

  
136
    offset = fdt_path_offset(fdt, dupname);
137
    if (offset < 0) {
138
        return offset;
161
    retval = fdt_add_subnode(fdt, findnode_nofail(fdt, dupname), basename);
162
    if (retval < 0) {
163
        fprintf(stderr, "FDT: Failed to create subnode %s: %s\n", name,
164
                fdt_strerror(retval));
165
        exit(1);
139 166
    }
140 167

  
141
    retval = fdt_add_subnode(fdt, offset, basename);
142 168
    g_free(dupname);
143 169
    return retval;
144 170
}

Also available in: Unified diff