fdt_addresses.c (0898782247ae533d1f4e47a06bc5d4870931b284) fdt_addresses.c (0cec114e36606412908a35695a5db944cec2e3db)
1// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
2/*
3 * libfdt - Flat Device Tree manipulation
4 * Copyright (C) 2014 David Gibson <david@gibson.dropbear.id.au>
5 * Copyright (C) 2018 embedded brains GmbH
6 */
7#include "libfdt_env.h"
8
9#include <fdt.h>
10#include <libfdt.h>
11
12#include "libfdt_internal.h"
13
14static int fdt_cells(const void *fdt, int nodeoffset, const char *name)
15{
16 const fdt32_t *c;
1// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
2/*
3 * libfdt - Flat Device Tree manipulation
4 * Copyright (C) 2014 David Gibson <david@gibson.dropbear.id.au>
5 * Copyright (C) 2018 embedded brains GmbH
6 */
7#include "libfdt_env.h"
8
9#include <fdt.h>
10#include <libfdt.h>
11
12#include "libfdt_internal.h"
13
14static int fdt_cells(const void *fdt, int nodeoffset, const char *name)
15{
16 const fdt32_t *c;
17 int val;
17 uint32_t val;
18 int len;
19
20 c = fdt_getprop(fdt, nodeoffset, name, &len);
21 if (!c)
22 return len;
23
24 if (len != sizeof(*c))
25 return -FDT_ERR_BADNCELLS;
26
27 val = fdt32_to_cpu(*c);
18 int len;
19
20 c = fdt_getprop(fdt, nodeoffset, name, &len);
21 if (!c)
22 return len;
23
24 if (len != sizeof(*c))
25 return -FDT_ERR_BADNCELLS;
26
27 val = fdt32_to_cpu(*c);
28 if ((val <= 0) || (val > FDT_MAX_NCELLS))
28 if (val > FDT_MAX_NCELLS)
29 return -FDT_ERR_BADNCELLS;
30
29 return -FDT_ERR_BADNCELLS;
30
31 return val;
31 return (int)val;
32}
33
34int fdt_address_cells(const void *fdt, int nodeoffset)
35{
36 int val;
37
38 val = fdt_cells(fdt, nodeoffset, "#address-cells");
32}
33
34int fdt_address_cells(const void *fdt, int nodeoffset)
35{
36 int val;
37
38 val = fdt_cells(fdt, nodeoffset, "#address-cells");
39 if (val == 0)
40 return -FDT_ERR_BADNCELLS;
39 if (val == -FDT_ERR_NOTFOUND)
40 return 2;
41 return val;
42}
43
44int fdt_size_cells(const void *fdt, int nodeoffset)
45{
46 int val;

--- 53 unchanged lines hidden ---
41 if (val == -FDT_ERR_NOTFOUND)
42 return 2;
43 return val;
44}
45
46int fdt_size_cells(const void *fdt, int nodeoffset)
47{
48 int val;

--- 53 unchanged lines hidden ---