treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / scripts / dtc / libfdt / fdt_wip.c
blobf64139e0b3dc5010b28f71815ed6d97ddaa1de4a
1 // SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
2 /*
3 * libfdt - Flat Device Tree manipulation
4 * Copyright (C) 2006 David Gibson, IBM Corporation.
5 */
6 #include "libfdt_env.h"
8 #include <fdt.h>
9 #include <libfdt.h>
11 #include "libfdt_internal.h"
13 int fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset,
14 const char *name, int namelen,
15 uint32_t idx, const void *val,
16 int len)
18 void *propval;
19 int proplen;
21 propval = fdt_getprop_namelen_w(fdt, nodeoffset, name, namelen,
22 &proplen);
23 if (!propval)
24 return proplen;
26 if (proplen < (len + idx))
27 return -FDT_ERR_NOSPACE;
29 memcpy((char *)propval + idx, val, len);
30 return 0;
33 int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,
34 const void *val, int len)
36 const void *propval;
37 int proplen;
39 propval = fdt_getprop(fdt, nodeoffset, name, &proplen);
40 if (!propval)
41 return proplen;
43 if (proplen != len)
44 return -FDT_ERR_NOSPACE;
46 return fdt_setprop_inplace_namelen_partial(fdt, nodeoffset, name,
47 strlen(name), 0,
48 val, len);
51 static void fdt_nop_region_(void *start, int len)
53 fdt32_t *p;
55 for (p = start; (char *)p < ((char *)start + len); p++)
56 *p = cpu_to_fdt32(FDT_NOP);
59 int fdt_nop_property(void *fdt, int nodeoffset, const char *name)
61 struct fdt_property *prop;
62 int len;
64 prop = fdt_get_property_w(fdt, nodeoffset, name, &len);
65 if (!prop)
66 return len;
68 fdt_nop_region_(prop, len + sizeof(*prop));
70 return 0;
73 int fdt_node_end_offset_(void *fdt, int offset)
75 int depth = 0;
77 while ((offset >= 0) && (depth >= 0))
78 offset = fdt_next_node(fdt, offset, &depth);
80 return offset;
83 int fdt_nop_node(void *fdt, int nodeoffset)
85 int endoffset;
87 endoffset = fdt_node_end_offset_(fdt, nodeoffset);
88 if (endoffset < 0)
89 return endoffset;
91 fdt_nop_region_(fdt_offset_ptr_w(fdt, nodeoffset, 0),
92 endoffset - nodeoffset);
93 return 0;