From patchwork Thu Jan 17 00:00:11 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kim Phillips X-Patchwork-Id: 213110 X-Patchwork-Delegate: vanbaren@cideas.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id C11492C0082 for ; Thu, 17 Jan 2013 11:18:04 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 270804A101; Thu, 17 Jan 2013 01:18:03 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id TK2AoQo92Doi; Thu, 17 Jan 2013 01:18:02 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id C172E4A106; Thu, 17 Jan 2013 01:18:00 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 11F624A106 for ; Thu, 17 Jan 2013 01:17:58 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Avzx7+-te-5V for ; Thu, 17 Jan 2013 01:17:56 +0100 (CET) X-Greylist: delayed 943 seconds by postgrey-1.27 at theia; Thu, 17 Jan 2013 01:17:54 CET X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from db3outboundpool.messaging.microsoft.com (db3ehsobe005.messaging.microsoft.com [213.199.154.143]) by theia.denx.de (Postfix) with ESMTPS id 074C74A113 for ; Thu, 17 Jan 2013 01:17:54 +0100 (CET) Received: from mail28-db3-R.bigfish.com (10.3.81.234) by DB3EHSOBE008.bigfish.com (10.3.84.28) with Microsoft SMTP Server id 14.1.225.23; Thu, 17 Jan 2013 00:02:47 +0000 Received: from mail28-db3 (localhost [127.0.0.1]) by mail28-db3-R.bigfish.com (Postfix) with ESMTP id B70AD4600EB; Thu, 17 Jan 2013 00:02:47 +0000 (UTC) X-Forefront-Antispam-Report: CIP:70.37.183.190; KIP:(null); UIP:(null); IPV:NLI; H:mail.freescale.net; RD:none; EFVD:NLI X-SpamScore: 0 X-BigFish: VS0(zzzz1ee6h1de0h1202h1e76h1d1ah1d2ahzz8275bhz2dh2a8h668h839h944hd24he5bhf0ah1220h1288h12a5h12a9h12bdh137ah139eh13b6h1441h1504h1537h162dh1631h1758h1898h1155h) Received: from mail28-db3 (localhost.localdomain [127.0.0.1]) by mail28-db3 (MessageSwitch) id 1358380966197936_619; Thu, 17 Jan 2013 00:02:46 +0000 (UTC) Received: from DB3EHSMHS018.bigfish.com (unknown [10.3.81.225]) by mail28-db3.bigfish.com (Postfix) with ESMTP id 2B54E4200E0; Thu, 17 Jan 2013 00:02:46 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by DB3EHSMHS018.bigfish.com (10.3.87.118) with Microsoft SMTP Server (TLS) id 14.1.225.23; Thu, 17 Jan 2013 00:02:44 +0000 Received: from az84smr01.freescale.net (10.64.34.197) by 039-SN1MMR1-001.039d.mgd.msft.net (10.84.1.13) with Microsoft SMTP Server (TLS) id 14.2.318.3; Thu, 17 Jan 2013 00:02:42 +0000 Received: from x9.am.freescale.net (x9.am.freescale.net [10.82.120.9]) by az84smr01.freescale.net (8.14.3/8.14.0) with SMTP id r0H02gMs026578; Wed, 16 Jan 2013 17:02:42 -0700 Date: Wed, 16 Jan 2013 18:00:11 -0600 From: Kim Phillips To: Message-ID: <20130116180011.0f835f5136abe6553afe8da8@freescale.com> Organization: Freescale Semiconductor, Inc. X-Mailer: Sylpheed 3.2.0 (GTK+ 2.24.13; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-OriginatorOrg: freescale.com Subject: [U-Boot] [PATCH 5/5 v2] common/fdt_support.c: sparse fixes X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de trivial: fdt_support.c:89:64: warning: Using plain integer as NULL pointer fdt_support.c:325:65: warning: Using plain integer as NULL pointer fdt_support.c:352:65: warning: Using plain integer as NULL pointer For the following bad constant expression, We hardcode the max. number of memory banks to four for the foreseeable future, and add an error with instructions on what to do once it's exceeded: fdt_support.c:397:22: error: bad constant expression For the rest below, sparse found a couple of wrong endian conversions in of_bus_default_translate() and fdt_get_base_address(), but otherwise the rest is mostly annotation fixes: fdt_support.c:64:24: warning: cast to restricted __be32 fdt_support.c:192:21: warning: incorrect type in assignment (different base types) fdt_support.c:192:21: expected unsigned int [unsigned] [usertype] tmp fdt_support.c:192:21: got restricted __be32 [usertype] fdt_support.c:201:21: warning: incorrect type in assignment (different base types) fdt_support.c:201:21: expected unsigned int [unsigned] [addressable] [usertype] tmp fdt_support.c:201:21: got restricted __be32 [usertype] fdt_support.c:304:13: warning: incorrect type in assignment (different base types) fdt_support.c:304:13: expected unsigned int [unsigned] [usertype] val fdt_support.c:304:13: got restricted __be32 [usertype] fdt_support.c:333:13: warning: incorrect type in assignment (different base types) fdt_support.c:333:13: expected unsigned int [unsigned] [usertype] val fdt_support.c:333:13: got restricted __be32 [usertype] fdt_support.c:359:13: warning: incorrect type in assignment (different base types) fdt_support.c:359:13: expected unsigned int [unsigned] [usertype] val fdt_support.c:359:13: got restricted __be32 [usertype] fdt_support.c:373:21: warning: cast to restricted __be32 fdt_support.c:963:48: warning: incorrect type in argument 1 (different base types) fdt_support.c:963:48: expected restricted __be32 const [usertype] *p fdt_support.c:963:48: got unsigned int [usertype] * fdt_support.c:971:48: warning: incorrect type in argument 1 (different base types) fdt_support.c:971:48: expected restricted __be32 const [usertype] *p fdt_support.c:971:48: got unsigned int [usertype] * fdt_support.c:984:29: warning: incorrect type in argument 1 (different base types) fdt_support.c:984:29: expected restricted __be32 const [usertype] *cell fdt_support.c:984:29: got unsigned int [usertype] *addr fdt_support.c:996:32: warning: incorrect type in argument 1 (different base types) fdt_support.c:996:32: expected restricted __be32 const [usertype] *cell fdt_support.c:996:32: got unsigned int [usertype] *addr fdt_support.c:1041:41: warning: incorrect type in argument 1 (different base types) fdt_support.c:1041:41: expected restricted __be32 const [usertype] *cell fdt_support.c:1041:41: got unsigned int [usertype] *addr fdt_support.c:1053:41: warning: incorrect type in argument 2 (different base types) fdt_support.c:1053:41: expected restricted __be32 const [usertype] *range fdt_support.c:1053:41: got unsigned int const [usertype] *[assigned] ranges fdt_support.c:1064:53: warning: incorrect type in argument 2 (different base types) fdt_support.c:1064:53: expected restricted __be32 const [usertype] *addr fdt_support.c:1064:53: got unsigned int [usertype] *addr fdt_support.c:1110:50: warning: incorrect type in argument 2 (different base types) fdt_support.c:1110:50: expected restricted __be32 const [usertype] *addr fdt_support.c:1110:50: got unsigned int * fdt_support.c:1121:49: warning: incorrect type in argument 1 (different base types) fdt_support.c:1121:49: expected restricted __be32 const [usertype] *cell fdt_support.c:1121:49: got unsigned int * fdt_support.c:1147:60: warning: incorrect type in argument 2 (different base types) fdt_support.c:1147:60: expected restricted __be32 const [usertype] *addr fdt_support.c:1147:60: got unsigned int * fdt_support.c:1081:5: warning: symbol '__of_translate_address' was not declared. Should it be static? fdt_support.c:1154:5: error: symbol 'fdt_translate_address' redeclared with different type (originally declared at include/fdt_support.h:95) - incompatible argument 3 (different base types) fdt_support.c: In function 'fdt_node_offset_by_compat_reg': fdt_support.c:1173:17: warning: initialization discards 'const' qualifier from pointer target type [enabled by default] See also linux kernel commit 0131d897 "of/address: use proper endianess in get_flags". Signed-off-by: Kim Phillips Cc: Jerry Van Baren --- v1 sent Tue, 16 Oct 2012 14:28:30 -0000 v2: updated to use fdt32 instead of be32 nomenclature, now that fdt specific types exist arch/powerpc/cpu/mpc85xx/fdt.c | 2 +- common/fdt_support.c | 86 +++++++++++++++++++++++------------------- include/fdt_support.h | 2 +- 3 files changed, 49 insertions(+), 41 deletions(-) diff --git a/arch/powerpc/cpu/mpc85xx/fdt.c b/arch/powerpc/cpu/mpc85xx/fdt.c index ab09330..2b32fcd 100644 --- a/arch/powerpc/cpu/mpc85xx/fdt.c +++ b/arch/powerpc/cpu/mpc85xx/fdt.c @@ -787,7 +787,7 @@ int ft_verify_fdt(void *fdt) #ifdef CONFIG_SYS_LBC_ADDR off = fdt_node_offset_by_compatible(fdt, -1, "fsl,elbc"); if (off > 0) { - const u32 *reg = fdt_getprop(fdt, off, "reg", NULL); + const fdt32_t *reg = fdt_getprop(fdt, off, "reg", NULL); if (reg) { uint64_t uaddr = CCSR_VIRT_TO_PHYS(CONFIG_SYS_LBC_ADDR); diff --git a/common/fdt_support.c b/common/fdt_support.c index 7a3fee4..812acb4 100644 --- a/common/fdt_support.c +++ b/common/fdt_support.c @@ -51,7 +51,7 @@ DECLARE_GLOBAL_DATA_PTR; u32 fdt_getprop_u32_default(const void *fdt, const char *path, const char *prop, const u32 dflt) { - const u32 *val; + const fdt32_t *val; int off; off = fdt_path_offset(fdt, path); @@ -85,7 +85,7 @@ int fdt_find_and_setprop(void *fdt, const char *node, const char *prop, if (nodeoff < 0) return nodeoff; - if ((!create) && (fdt_get_property(fdt, nodeoff, prop, 0) == NULL)) + if ((!create) && (fdt_get_property(fdt, nodeoff, prop, NULL) == NULL)) return 0; /* create flag not set; so exit quietly */ return fdt_setprop(fdt, nodeoff, prop, val, len); @@ -149,7 +149,7 @@ int fdt_initrd(void *fdt, ulong initrd_start, ulong initrd_end, int force) { int nodeoffset; int err, j, total; - u32 tmp; + fdt32_t tmp; const char *path; uint64_t addr, size; @@ -188,7 +188,7 @@ int fdt_initrd(void *fdt, ulong initrd_start, ulong initrd_end, int force) path = fdt_getprop(fdt, nodeoffset, "linux,initrd-start", NULL); if ((path == NULL) || force) { - tmp = __cpu_to_be32(initrd_start); + tmp = cpu_to_fdt32(initrd_start); err = fdt_setprop(fdt, nodeoffset, "linux,initrd-start", &tmp, sizeof(tmp)); if (err < 0) { @@ -197,7 +197,7 @@ int fdt_initrd(void *fdt, ulong initrd_start, ulong initrd_end, int force) fdt_strerror(err)); return err; } - tmp = __cpu_to_be32(initrd_end); + tmp = cpu_to_fdt32(initrd_end); err = fdt_setprop(fdt, nodeoffset, "linux,initrd-end", &tmp, sizeof(tmp)); if (err < 0) { @@ -300,8 +300,8 @@ void do_fixup_by_path(void *fdt, const char *path, const char *prop, void do_fixup_by_path_u32(void *fdt, const char *path, const char *prop, u32 val, int create) { - val = cpu_to_fdt32(val); - do_fixup_by_path(fdt, path, prop, &val, sizeof(val), create); + fdt32_t tmp = cpu_to_fdt32(val); + do_fixup_by_path(fdt, path, prop, &tmp, sizeof(tmp), create); } void do_fixup_by_prop(void *fdt, @@ -319,7 +319,7 @@ void do_fixup_by_prop(void *fdt, #endif off = fdt_node_offset_by_prop_value(fdt, -1, pname, pval, plen); while (off != -FDT_ERR_NOTFOUND) { - if (create || (fdt_get_property(fdt, off, prop, 0) != NULL)) + if (create || (fdt_get_property(fdt, off, prop, NULL) != NULL)) fdt_setprop(fdt, off, prop, val, len); off = fdt_node_offset_by_prop_value(fdt, off, pname, pval, plen); } @@ -329,8 +329,8 @@ void do_fixup_by_prop_u32(void *fdt, const char *pname, const void *pval, int plen, const char *prop, u32 val, int create) { - val = cpu_to_fdt32(val); - do_fixup_by_prop(fdt, pname, pval, plen, prop, &val, 4, create); + fdt32_t tmp = cpu_to_fdt32(val); + do_fixup_by_prop(fdt, pname, pval, plen, prop, &tmp, 4, create); } void do_fixup_by_compat(void *fdt, const char *compat, @@ -346,7 +346,7 @@ void do_fixup_by_compat(void *fdt, const char *compat, #endif off = fdt_node_offset_by_compatible(fdt, -1, compat); while (off != -FDT_ERR_NOTFOUND) { - if (create || (fdt_get_property(fdt, off, prop, 0) != NULL)) + if (create || (fdt_get_property(fdt, off, prop, NULL) != NULL)) fdt_setprop(fdt, off, prop, val, len); off = fdt_node_offset_by_compatible(fdt, off, compat); } @@ -355,8 +355,8 @@ void do_fixup_by_compat(void *fdt, const char *compat, void do_fixup_by_compat_u32(void *fdt, const char *compat, const char *prop, u32 val, int create) { - val = cpu_to_fdt32(val); - do_fixup_by_compat(fdt, compat, prop, &val, 4, create); + fdt32_t tmp = cpu_to_fdt32(val); + do_fixup_by_compat(fdt, compat, prop, &tmp, 4, create); } /* @@ -366,7 +366,7 @@ void do_fixup_by_compat_u32(void *fdt, const char *compat, */ static int get_cells_len(void *blob, char *nr_cells_name) { - const u32 *cell; + const fdt32_t *cell; cell = fdt_getprop(blob, 0, nr_cells_name, NULL); if (cell && fdt32_to_cpu(*cell) == 2) @@ -387,13 +387,21 @@ static void write_cell(u8 *addr, u64 val, int size) } } +#define MEMORY_BANKS_MAX 4 int fdt_fixup_memory_banks(void *blob, u64 start[], u64 size[], int banks) { int err, nodeoffset; int addr_cell_len, size_cell_len, len; - u8 tmp[banks * 16]; /* Up to 64-bit address + 64-bit size */ + u8 tmp[MEMORY_BANKS_MAX * 16]; /* Up to 64-bit address + 64-bit size */ int bank; + if (banks > MEMORY_BANKS_MAX) { + printf("%s: num banks %d exceeds hardcoded limit %d." + " Recompile with higher MEMORY_BANKS_MAX?\n", + __FUNCTION__, banks, MEMORY_BANKS_MAX); + return -1; + } + err = fdt_check_header(blob); if (err < 0) { printf("%s: %s\n", __FUNCTION__, fdt_strerror(err)); @@ -902,11 +910,11 @@ void fdt_del_node_and_alias(void *blob, const char *alias) } /* Helper to read a big number; size is in cells (not bytes) */ -static inline u64 of_read_number(const __be32 *cell, int size) +static inline u64 of_read_number(const fdt32_t *cell, int size) { u64 r = 0; while (size--) - r = (r << 32) | be32_to_cpu(*(cell++)); + r = (r << 32) | fdt32_to_cpu(*(cell++)); return r; } @@ -920,7 +928,7 @@ static inline u64 of_read_number(const __be32 *cell, int size) /* Debug utility */ #ifdef DEBUG -static void of_dump_addr(const char *s, const u32 *addr, int na) +static void of_dump_addr(const char *s, const fdt32_t *addr, int na) { printf("%s", s); while(na--) @@ -928,7 +936,7 @@ static void of_dump_addr(const char *s, const u32 *addr, int na) printf("\n"); } #else -static void of_dump_addr(const char *s, const u32 *addr, int na) { } +static void of_dump_addr(const char *s, const fdt32_t *addr, int na) { } #endif /* Callbacks for bus specific translators */ @@ -937,21 +945,21 @@ struct of_bus { const char *addresses; void (*count_cells)(void *blob, int parentoffset, int *addrc, int *sizec); - u64 (*map)(u32 *addr, const u32 *range, + u64 (*map)(fdt32_t *addr, const fdt32_t *range, int na, int ns, int pna); - int (*translate)(u32 *addr, u64 offset, int na); + int (*translate)(fdt32_t *addr, u64 offset, int na); }; /* Default translator (generic bus) */ static void of_bus_default_count_cells(void *blob, int parentoffset, int *addrc, int *sizec) { - const u32 *prop; + const fdt32_t *prop; if (addrc) { prop = fdt_getprop(blob, parentoffset, "#address-cells", NULL); if (prop) - *addrc = be32_to_cpup((u32 *)prop); + *addrc = be32_to_cpup(prop); else *addrc = 2; } @@ -959,13 +967,13 @@ static void of_bus_default_count_cells(void *blob, int parentoffset, if (sizec) { prop = fdt_getprop(blob, parentoffset, "#size-cells", NULL); if (prop) - *sizec = be32_to_cpup((u32 *)prop); + *sizec = be32_to_cpup(prop); else *sizec = 1; } } -static u64 of_bus_default_map(u32 *addr, const u32 *range, +static u64 of_bus_default_map(fdt32_t *addr, const fdt32_t *range, int na, int ns, int pna) { u64 cp, s, da; @@ -982,14 +990,14 @@ static u64 of_bus_default_map(u32 *addr, const u32 *range, return da - cp; } -static int of_bus_default_translate(u32 *addr, u64 offset, int na) +static int of_bus_default_translate(fdt32_t *addr, u64 offset, int na) { u64 a = of_read_number(addr, na); memset(addr, 0, na * 4); a += offset; if (na > 1) - addr[na - 2] = a >> 32; - addr[na - 1] = a & 0xffffffffu; + addr[na - 2] = cpu_to_fdt32(a >> 32); + addr[na - 1] = cpu_to_fdt32(a & 0xffffffffu); return 0; } @@ -1007,10 +1015,10 @@ static struct of_bus of_busses[] = { }; static int of_translate_one(void * blob, int parent, struct of_bus *bus, - struct of_bus *pbus, u32 *addr, + struct of_bus *pbus, fdt32_t *addr, int na, int ns, int pna, const char *rprop) { - const u32 *ranges; + const fdt32_t *ranges; int rlen; int rone; u64 offset = OF_BAD_ADDR; @@ -1027,7 +1035,7 @@ static int of_translate_one(void * blob, int parent, struct of_bus *bus, * to translate addresses that aren't supposed to be translated in * the first place. --BenH. */ - ranges = (u32 *)fdt_getprop(blob, parent, rprop, &rlen); + ranges = fdt_getprop(blob, parent, rprop, &rlen); if (ranges == NULL || rlen == 0) { offset = of_read_number(addr, na); memset(addr, 0, pna * 4); @@ -1069,12 +1077,12 @@ static int of_translate_one(void * blob, int parent, struct of_bus *bus, * that can be mapped to a cpu physical address). This is not really specified * that way, but this is traditionally the way IBM at least do things */ -u64 __of_translate_address(void *blob, int node_offset, const u32 *in_addr, - const char *rprop) +static u64 __of_translate_address(void *blob, int node_offset, const fdt32_t *in_addr, + const char *rprop) { int parent; struct of_bus *bus, *pbus; - u32 addr[OF_MAX_ADDR_CELLS]; + fdt32_t addr[OF_MAX_ADDR_CELLS]; int na, ns, pna, pns; u64 result = OF_BAD_ADDR; @@ -1142,7 +1150,7 @@ u64 __of_translate_address(void *blob, int node_offset, const u32 *in_addr, return result; } -u64 fdt_translate_address(void *blob, int node_offset, const u32 *in_addr) +u64 fdt_translate_address(void *blob, int node_offset, const fdt32_t *in_addr) { return __of_translate_address(blob, node_offset, in_addr, "ranges"); } @@ -1161,7 +1169,7 @@ int fdt_node_offset_by_compat_reg(void *blob, const char *compat, { int len, off = fdt_node_offset_by_compatible(blob, -1, compat); while (off != -FDT_ERR_NOTFOUND) { - u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", &len); + const fdt32_t *reg = fdt_getprop(blob, off, "reg", &len); if (reg) { if (compat_off == fdt_translate_address(blob, off, reg)) return off; @@ -1355,7 +1363,7 @@ err_size: int fdt_verify_alias_address(void *fdt, int anode, const char *alias, u64 addr) { const char *path; - const u32 *reg; + const fdt32_t *reg; int node, len; u64 dt_addr; @@ -1397,11 +1405,11 @@ u64 fdt_get_base_address(void *fdt, int node) { int size; u32 naddr; - const u32 *prop; + const fdt32_t *prop; prop = fdt_getprop(fdt, node, "#address-cells", &size); if (prop && size == 4) - naddr = *prop; + naddr = be32_to_cpup(prop); else naddr = 2; diff --git a/include/fdt_support.h b/include/fdt_support.h index a08c90b..568bcbf 100644 --- a/include/fdt_support.h +++ b/include/fdt_support.h @@ -93,7 +93,7 @@ int fdt_fixup_nor_flash_size(void *blob); void fdt_fixup_mtdparts(void *fdt, void *node_info, int node_info_size); void fdt_del_node_and_alias(void *blob, const char *alias); -u64 fdt_translate_address(void *blob, int node_offset, const u32 *in_addr); +u64 fdt_translate_address(void *blob, int node_offset, const __be32 *in_addr); int fdt_node_offset_by_compat_reg(void *blob, const char *compat, phys_addr_t compat_off); int fdt_alloc_phandle(void *blob);