* [edk2-devel] [edk2 Patch 0/1] Fix compiler errors due to implicit conversions @ 2024-02-06 16:23 Jayaprakash, N 2024-02-06 16:23 ` [edk2-devel] [edk2 Patch 1/1] EmbeddedPkg: " Jayaprakash, N 0 siblings, 1 reply; 4+ messages in thread From: Jayaprakash, N @ 2024-02-06 16:23 UTC (permalink / raw) To: devel; +Cc: Jayaprakash N This commit fixes compilation issues reported through BZ4669. There were several compilation errors due to implicit type conversions in EmbeddedPkg. Fixed all the issues with the correct usage of explicit type conversions based on the context. Jayaprakash N (1): EmbeddedPkg: Fix compiler errors due to implicit conversions EmbeddedPkg/GdbStub/X64/Processor.c | 36 +++++++++---------- EmbeddedPkg/Include/libfdt_env.h | 8 ++--- EmbeddedPkg/Library/FdtLib/fdt.c | 9 ++--- EmbeddedPkg/Library/FdtLib/fdt_overlay.c | 20 +++++------ EmbeddedPkg/Library/FdtLib/fdt_ro.c | 32 ++++++++--------- EmbeddedPkg/Library/FdtLib/fdt_rw.c | 24 ++++++------- EmbeddedPkg/Library/FdtLib/fdt_strerror.c | 2 +- EmbeddedPkg/Library/FdtLib/fdt_strtoul.c | 2 +- EmbeddedPkg/Library/FdtLib/fdt_sw.c | 10 +++--- EmbeddedPkg/Library/FdtLib/fdt_wip.c | 4 +-- .../MemoryAllocationLib.c | 2 +- EmbeddedPkg/Universal/MmcDxe/MmcBlockIo.c | 8 ++--- .../Universal/MmcDxe/MmcIdentification.c | 22 ++++++------ 13 files changed, 90 insertions(+), 89 deletions(-) -- 2.40.0.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#115180): https://edk2.groups.io/g/devel/message/115180 Mute This Topic: https://groups.io/mt/104200928/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=- ^ permalink raw reply [flat|nested] 4+ messages in thread
* [edk2-devel] [edk2 Patch 1/1] EmbeddedPkg: Fix compiler errors due to implicit conversions 2024-02-06 16:23 [edk2-devel] [edk2 Patch 0/1] Fix compiler errors due to implicit conversions Jayaprakash, N @ 2024-02-06 16:23 ` Jayaprakash, N 2024-02-07 19:59 ` Laszlo Ersek 0 siblings, 1 reply; 4+ messages in thread From: Jayaprakash, N @ 2024-02-06 16:23 UTC (permalink / raw) To: devel Cc: Jayaprakash N, Rebecca Cran, Michael D Kinney, Laszlo Ersek, Leif Lindholm, Ard Biesheuvel, Abner Chang REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4669 This commit fixes compilation issues reported through BZ4669. There were several compilation errors due to implicit type conversions in EmbeddedPkg. Fixed all the issues with the correct usage of explicit type conversions based on the context. Cc: Rebecca Cran <rebecca@bsdio.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Laszlo Ersek <lersek@redhat.com> Cc: Leif Lindholm <quic_llindhol@quicinc.com> Cc: Ard Biesheuvel <ardb+tianocore@kernel.org> Cc: Abner Chang <abner.chang@amd.com> Cc: Jayaprakash N <n.jayaprakash@intel.com> Signed-off-by: Jayaprakash N <n.jayaprakash@intel.com> --- EmbeddedPkg/GdbStub/X64/Processor.c | 36 +++++++++---------- EmbeddedPkg/Include/libfdt_env.h | 8 ++--- EmbeddedPkg/Library/FdtLib/fdt.c | 9 ++--- EmbeddedPkg/Library/FdtLib/fdt_overlay.c | 20 +++++------ EmbeddedPkg/Library/FdtLib/fdt_ro.c | 32 ++++++++--------- EmbeddedPkg/Library/FdtLib/fdt_rw.c | 24 ++++++------- EmbeddedPkg/Library/FdtLib/fdt_strerror.c | 2 +- EmbeddedPkg/Library/FdtLib/fdt_strtoul.c | 2 +- EmbeddedPkg/Library/FdtLib/fdt_sw.c | 10 +++--- EmbeddedPkg/Library/FdtLib/fdt_wip.c | 4 +-- .../MemoryAllocationLib.c | 2 +- EmbeddedPkg/Universal/MmcDxe/MmcBlockIo.c | 8 ++--- .../Universal/MmcDxe/MmcIdentification.c | 22 ++++++------ 13 files changed, 90 insertions(+), 89 deletions(-) diff --git a/EmbeddedPkg/GdbStub/X64/Processor.c b/EmbeddedPkg/GdbStub/X64/Processor.c index 4ff79abe42..b03d15938c 100644 --- a/EmbeddedPkg/GdbStub/X64/Processor.c +++ b/EmbeddedPkg/GdbStub/X64/Processor.c @@ -599,31 +599,31 @@ EnableDebugRegister ( Dr7.UintN = SystemContext.SystemContextIa32->Dr7; if (Register == 0) { - SystemContext.SystemContextIa32->Dr0 = Address; + SystemContext.SystemContextIa32->Dr0 = (UINT32)Address; Dr7.Bits.G0 = 1; - Dr7.Bits.RW0 = Type; - Dr7.Bits.LEN0 = Length; + Dr7.Bits.RW0 = (UINT32)Type; + Dr7.Bits.LEN0 = (UINT32)Length; } else if (Register == 1) { - SystemContext.SystemContextIa32->Dr1 = Address; + SystemContext.SystemContextIa32->Dr1 = (UINT32)Address; Dr7.Bits.G1 = 1; - Dr7.Bits.RW1 = Type; - Dr7.Bits.LEN1 = Length; + Dr7.Bits.RW1 = (UINT32)Type; + Dr7.Bits.LEN1 = (UINT32)Length; } else if (Register == 2) { - SystemContext.SystemContextIa32->Dr2 = Address; + SystemContext.SystemContextIa32->Dr2 = (UINT32)Address; Dr7.Bits.G2 = 1; - Dr7.Bits.RW2 = Type; - Dr7.Bits.LEN2 = Length; + Dr7.Bits.RW2 = (UINT32)Type; + Dr7.Bits.LEN2 = (UINT32)Length; } else if (Register == 3) { - SystemContext.SystemContextIa32->Dr3 = Address; + SystemContext.SystemContextIa32->Dr3 = (UINT32)Address; Dr7.Bits.G3 = 1; - Dr7.Bits.RW3 = Type; - Dr7.Bits.LEN3 = Length; + Dr7.Bits.RW3 = (UINT32)Type; + Dr7.Bits.LEN3 = (UINT32)Length; } else { return EFI_INVALID_PARAMETER; } // Update Dr7 with appropriate Gn, RWn and LENn bits - SystemContext.SystemContextIa32->Dr7 = Dr7.UintN; + SystemContext.SystemContextIa32->Dr7 = (UINT32)(Dr7.UintN); return EFI_SUCCESS; } @@ -722,22 +722,22 @@ DisableDebugRegister ( Dr7.UintN = SystemContext.SystemContextIa32->Dr7; if (Register == 0) { - SystemContext.SystemContextIa32->Dr0 = Address; + SystemContext.SystemContextIa32->Dr0 = (UINT32)Address; Dr7.Bits.G0 = 0; Dr7.Bits.RW0 = 0; Dr7.Bits.LEN0 = 0; } else if (Register == 1) { - SystemContext.SystemContextIa32->Dr1 = Address; + SystemContext.SystemContextIa32->Dr1 = (UINT32)Address; Dr7.Bits.G1 = 0; Dr7.Bits.RW1 = 0; Dr7.Bits.LEN1 = 0; } else if (Register == 2) { - SystemContext.SystemContextIa32->Dr2 = Address; + SystemContext.SystemContextIa32->Dr2 = (UINT32)Address; Dr7.Bits.G2 = 0; Dr7.Bits.RW2 = 0; Dr7.Bits.LEN2 = 0; } else if (Register == 3) { - SystemContext.SystemContextIa32->Dr3 = Address; + SystemContext.SystemContextIa32->Dr3 = (UINT32)Address; Dr7.Bits.G3 = 0; Dr7.Bits.RW3 = 0; Dr7.Bits.LEN3 = 0; @@ -746,7 +746,7 @@ DisableDebugRegister ( } // Update DR7 register so appropriate Gn, RWn and LENn bits can be turned off. - SystemContext.SystemContextIa32->Dr7 = Dr7.UintN; + SystemContext.SystemContextIa32->Dr7 = (UINT32)(Dr7.UintN); return EFI_SUCCESS; } diff --git a/EmbeddedPkg/Include/libfdt_env.h b/EmbeddedPkg/Include/libfdt_env.h index dfd3bac01f..1b08727a12 100644 --- a/EmbeddedPkg/Include/libfdt_env.h +++ b/EmbeddedPkg/Include/libfdt_env.h @@ -80,7 +80,7 @@ memset ( size_t n ) { - return SetMem (s, n, c); + return SetMem (s, n, (UINT8)c); } static inline int @@ -90,7 +90,7 @@ memcmp ( int len ) { - return CompareMem (dest, src, len); + return (int) CompareMem (dest, src, len); } static inline void * @@ -100,7 +100,7 @@ memchr ( size_t n ) { - return ScanMem8 (s, n, c); + return ScanMem8 (s, n, (UINT8)c); } static inline size_t @@ -119,7 +119,7 @@ strchr ( { char pattern[2]; - pattern[0] = c; + pattern[0] = (char)c; pattern[1] = 0; return AsciiStrStr (s, pattern); } diff --git a/EmbeddedPkg/Library/FdtLib/fdt.c b/EmbeddedPkg/Library/FdtLib/fdt.c index 56a9787cd0..e7dc86b46c 100644 --- a/EmbeddedPkg/Library/FdtLib/fdt.c +++ b/EmbeddedPkg/Library/FdtLib/fdt.c @@ -90,7 +90,8 @@ fdt_offset_ptr ( { unsigned absoffset = offset + fdt_off_dt_struct (fdt); - if ( (absoffset < offset) + if ( (offset < 0) + || (absoffset < (unsigned int)offset) || ((absoffset + len) < absoffset) || ((absoffset + len) > fdt_totalsize (fdt))) { @@ -98,7 +99,7 @@ fdt_offset_ptr ( } if (fdt_version (fdt) >= 0x11) { - if ( ((offset + len) < offset) + if ( ((offset + len) < (unsigned int)offset) || ((offset + len) > fdt_size_dt_struct (fdt))) { return NULL; @@ -299,7 +300,7 @@ _fdt_find_string ( const char *s ) { - int len = strlen (s) + 1; + int len = (int) strlen (s) + 1; const char *last = strtab + tabsize - len; const char *p; @@ -321,7 +322,7 @@ fdt_move ( { FDT_CHECK_HEADER (fdt); - if (fdt_totalsize (fdt) > bufsize) { + if ((bufsize < 0) || (fdt_totalsize (fdt) > (unsigned int)bufsize)) { return -FDT_ERR_NOSPACE; } diff --git a/EmbeddedPkg/Library/FdtLib/fdt_overlay.c b/EmbeddedPkg/Library/FdtLib/fdt_overlay.c index 0e6b8715e4..1828e7afd9 100644 --- a/EmbeddedPkg/Library/FdtLib/fdt_overlay.c +++ b/EmbeddedPkg/Library/FdtLib/fdt_overlay.c @@ -362,7 +362,7 @@ overlay_update_local_node_references ( fdto, tree_node, name, - strlen (name), + (int)strlen (name), poffset, &adj_val, sizeof (adj_val) @@ -610,7 +610,7 @@ overlay_fixup_phandle ( return -FDT_ERR_BADOVERLAY; } - fixup_len = fixup_end - fixup_str; + fixup_len = (uint32_t)(fixup_end - fixup_str); len -= fixup_len + 1; value += fixup_len + 1; @@ -621,7 +621,7 @@ overlay_fixup_phandle ( return -FDT_ERR_BADOVERLAY; } - path_len = sep - path; + path_len = (uint32_t)(sep - path); if (path_len == (fixup_len - 1)) { return -FDT_ERR_BADOVERLAY; } @@ -633,7 +633,7 @@ overlay_fixup_phandle ( return -FDT_ERR_BADOVERLAY; } - name_len = sep - name; + name_len = (uint32_t)(sep - name); if (!name_len) { return -FDT_ERR_BADOVERLAY; } @@ -971,7 +971,7 @@ overlay_symbol_update ( } frag_name = path + 1; - frag_name_len = s - path - 1; + frag_name_len = (int)(s - path - 1); /* verify format; safe since "s" lies in \0 terminated prop */ len = sizeof ("/__overlay__/") - 1; @@ -980,7 +980,7 @@ overlay_symbol_update ( } rel_path = s + len; - rel_path_len = e - rel_path; + rel_path_len = (int)(e - rel_path); /* find the fragment index in which the symbol lies */ ret = fdt_subnode_offset_namelen ( @@ -1019,7 +1019,7 @@ overlay_symbol_update ( len = ret; } else { - len = strlen (target_path); + len = (int)strlen (target_path); } ret = fdt_setprop_placeholder ( @@ -1106,7 +1106,7 @@ fdt_overlay_apply ( /* * The overlay has been damaged, erase its magic. */ - fdt_set_magic (fdto, ~0); + fdt_set_magic (fdto, (uint32_t)~0); return 0; @@ -1115,13 +1115,13 @@ err: /* * The overlay might have been damaged, erase its magic. */ - fdt_set_magic (fdto, ~0); + fdt_set_magic (fdto, (uint32_t)~0); /* * The base device tree might have been damaged, erase its * magic. */ - fdt_set_magic (fdt, ~0); + fdt_set_magic (fdt, (uint32_t)~0); return ret; } diff --git a/EmbeddedPkg/Library/FdtLib/fdt_ro.c b/EmbeddedPkg/Library/FdtLib/fdt_ro.c index 30aac37958..1f2aee3405 100644 --- a/EmbeddedPkg/Library/FdtLib/fdt_ro.c +++ b/EmbeddedPkg/Library/FdtLib/fdt_ro.c @@ -234,7 +234,7 @@ fdt_subnode_offset ( const char *name ) { - return fdt_subnode_offset_namelen (fdt, parentoffset, name, strlen (name)); + return fdt_subnode_offset_namelen (fdt, parentoffset, name, (int)strlen (name)); } int @@ -258,7 +258,7 @@ fdt_path_offset_namelen ( q = end; } - p = fdt_get_alias_namelen (fdt, p, q - p); + p = fdt_get_alias_namelen (fdt, p, (int)(q - p)); if (!p) { return -FDT_ERR_BADPATH; } @@ -283,7 +283,7 @@ fdt_path_offset_namelen ( q = end; } - offset = fdt_subnode_offset_namelen (fdt, offset, p, q-p); + offset = fdt_subnode_offset_namelen (fdt, offset, p, (int)(q-p)); if (offset < 0) { return offset; } @@ -300,7 +300,7 @@ fdt_path_offset ( const char *path ) { - return fdt_path_offset_namelen (fdt, path, strlen (path)); + return fdt_path_offset_namelen (fdt, path, (int)strlen (path)); } const char * @@ -320,7 +320,7 @@ fdt_get_name ( } if (len) { - *len = strlen (nh->name); + *len = (int)strlen (nh->name); } return nh->name; @@ -402,8 +402,8 @@ fdt_get_property_namelen ( (offset = fdt_next_property_offset (fdt, offset))) { const struct fdt_property *prop; - - if (!(prop = fdt_get_property_by_offset (fdt, offset, lenp))) { + prop = fdt_get_property_by_offset (fdt, offset, lenp); + if (!prop) { offset = -FDT_ERR_INTERNAL; break; } @@ -438,7 +438,7 @@ fdt_get_property ( fdt, nodeoffset, name, - strlen (name), + (int)strlen (name), lenp ); } @@ -492,7 +492,7 @@ fdt_getprop ( int *lenp ) { - return fdt_getprop_namelen (fdt, nodeoffset, name, strlen (name), lenp); + return fdt_getprop_namelen (fdt, nodeoffset, name, (int)strlen (name), lenp); } uint32_t @@ -540,7 +540,7 @@ fdt_get_alias ( const char *name ) { - return fdt_get_alias_namelen (fdt, name, strlen (name)); + return fdt_get_alias_namelen (fdt, name, (int)strlen (name)); } int @@ -769,7 +769,7 @@ fdt_stringlist_contains ( const char *str ) { - int len = strlen (str); + int len = (int)strlen (str); const char *p; while (listlen >= len) { @@ -782,7 +782,7 @@ fdt_stringlist_contains ( return 0; /* malformed strlist.. */ } - listlen -= (p-strlist) + 1; + listlen -= (int)(p-strlist) + 1; strlist = p + 1; } @@ -807,7 +807,7 @@ fdt_stringlist_count ( end = list + length; while (list < end) { - length = strnlen (list, end - list) + 1; + length = (int)strnlen (list, end - list) + 1; /* Abort if the last string isn't properly NUL-terminated. */ if (list + length > end) { @@ -837,11 +837,11 @@ fdt_stringlist_search ( return length; } - len = strlen (string) + 1; + len = (int)strlen (string) + 1; end = list + length; while (list < end) { - length = strnlen (list, end - list) + 1; + length = (int)strnlen (list, end - list) + 1; /* Abort if the last string isn't properly NUL-terminated. */ if (list + length > end) { @@ -883,7 +883,7 @@ fdt_stringlist_get ( end = list + length; while (list < end) { - length = strnlen (list, end - list) + 1; + length = (int)strnlen (list, end - list) + 1; /* Abort if the last string isn't properly NUL-terminated. */ if (list + length > end) { diff --git a/EmbeddedPkg/Library/FdtLib/fdt_rw.c b/EmbeddedPkg/Library/FdtLib/fdt_rw.c index cb5088a3af..5d172127e4 100644 --- a/EmbeddedPkg/Library/FdtLib/fdt_rw.c +++ b/EmbeddedPkg/Library/FdtLib/fdt_rw.c @@ -171,8 +171,8 @@ _fdt_splice_struct ( { int delta = newlen - oldlen; int err; - - if ((err = _fdt_splice (fdt, p, oldlen, newlen))) { + err = _fdt_splice (fdt, p, oldlen, newlen); + if (err) { return err; } @@ -190,8 +190,8 @@ _fdt_splice_string ( void *p = (char *)fdt + fdt_off_dt_strings (fdt) + fdt_size_dt_strings (fdt); int err; - - if ((err = _fdt_splice (fdt, p, 0, newlen))) { + err = _fdt_splice (fdt, p, 0, newlen); + if (err) { return err; } @@ -208,13 +208,13 @@ _fdt_find_add_string ( char *strtab = (char *)fdt + fdt_off_dt_strings (fdt); const char *p; char *new; - int len = strlen (s) + 1; + int len = (int)strlen (s) + 1; int err; p = _fdt_find_string (strtab, fdt_size_dt_strings (fdt), s); if (p) { /* found it */ - return (p - strtab); + return (int)(p - strtab); } new = strtab + fdt_size_dt_strings (fdt); @@ -224,7 +224,7 @@ _fdt_find_add_string ( } memcpy (new, s, len); - return (new - strtab); + return (int)(new - strtab); } int @@ -283,13 +283,13 @@ _fdt_resize_property ( if (!*prop) { return oldlen; } - - if ((err = _fdt_splice_struct ( + err = _fdt_splice_struct ( fdt, (*prop)->data, FDT_TAGALIGN (oldlen), FDT_TAGALIGN (len) - ))) + ); + if (err) { return err; } @@ -353,7 +353,7 @@ fdt_set_name ( return oldlen; } - newlen = strlen (name); + newlen = (int)strlen (name); err = _fdt_splice_struct ( fdt, @@ -537,7 +537,7 @@ fdt_add_subnode ( const char *name ) { - return fdt_add_subnode_namelen (fdt, parentoffset, name, strlen (name)); + return fdt_add_subnode_namelen (fdt, parentoffset, name, (int)strlen (name)); } int diff --git a/EmbeddedPkg/Library/FdtLib/fdt_strerror.c b/EmbeddedPkg/Library/FdtLib/fdt_strerror.c index cb07f6166e..36e2613b43 100644 --- a/EmbeddedPkg/Library/FdtLib/fdt_strerror.c +++ b/EmbeddedPkg/Library/FdtLib/fdt_strerror.c @@ -94,7 +94,7 @@ fdt_strerror ( return "<valid offset/length>"; } else if (errval == 0) { return "<no error>"; - } else if (errval > -FDT_ERRTABSIZE) { + } else if (errval > (-1 * FDT_ERRTABSIZE)) { const char *s = fdt_errtable[-errval].str; if (s) { diff --git a/EmbeddedPkg/Library/FdtLib/fdt_strtoul.c b/EmbeddedPkg/Library/FdtLib/fdt_strtoul.c index e615d6f4c0..c340771918 100644 --- a/EmbeddedPkg/Library/FdtLib/fdt_strtoul.c +++ b/EmbeddedPkg/Library/FdtLib/fdt_strtoul.c @@ -33,5 +33,5 @@ strtoul ( return MAX_UINTN; } - return ReturnValue; + return (unsigned long)ReturnValue; } diff --git a/EmbeddedPkg/Library/FdtLib/fdt_sw.c b/EmbeddedPkg/Library/FdtLib/fdt_sw.c index 6bcdd1fc7b..1fb47776cb 100644 --- a/EmbeddedPkg/Library/FdtLib/fdt_sw.c +++ b/EmbeddedPkg/Library/FdtLib/fdt_sw.c @@ -91,7 +91,7 @@ _fdt_grab_space ( return NULL; } - fdt_set_size_dt_struct (fdt, offset + len); + fdt_set_size_dt_struct (fdt, offset + (int)len); return _fdt_offset_ptr_w (fdt, offset); } @@ -210,7 +210,7 @@ fdt_begin_node ( ) { struct fdt_node_header *nh; - int namelen = strlen (name) + 1; + int namelen = (int)strlen (name) + 1; FDT_SW_CHECK_HEADER (fdt); @@ -251,18 +251,18 @@ _fdt_find_add_string ( char *strtab = (char *)fdt + fdt_totalsize (fdt); const char *p; int strtabsize = fdt_size_dt_strings (fdt); - int len = strlen (s) + 1; + int len = (int)strlen (s) + 1; int struct_top, offset; p = _fdt_find_string (strtab - strtabsize, strtabsize, s); if (p) { - return p - strtab; + return (int)(p - strtab); } /* Add it */ offset = -strtabsize - len; struct_top = fdt_off_dt_struct (fdt) + fdt_size_dt_struct (fdt); - if (fdt_totalsize (fdt) + offset < struct_top) { + if (fdt_totalsize (fdt) + offset < (uint32_t)struct_top) { return 0; /* no more room :( */ } diff --git a/EmbeddedPkg/Library/FdtLib/fdt_wip.c b/EmbeddedPkg/Library/FdtLib/fdt_wip.c index 8447706919..2f822fce61 100644 --- a/EmbeddedPkg/Library/FdtLib/fdt_wip.c +++ b/EmbeddedPkg/Library/FdtLib/fdt_wip.c @@ -80,7 +80,7 @@ fdt_setprop_inplace_namelen_partial ( return proplen; } - if (proplen < (len + idx)) { + if ((proplen < 0) || ((uint32_t)proplen < (len + idx))) { return -FDT_ERR_NOSPACE; } @@ -113,7 +113,7 @@ fdt_setprop_inplace ( fdt, nodeoffset, name, - strlen (name), + (int)strlen (name), 0, val, len diff --git a/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c b/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c index fa81cc9d59..11566cf57f 100644 --- a/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c +++ b/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c @@ -308,7 +308,7 @@ ReallocatePool ( if (OldBuffer != NULL) { HandOffHob = GetHobList (); ASSERT (((EFI_PHYSICAL_ADDRESS)(UINTN)OldBuffer >= HandOffHob->EfiMemoryBottom)); - ASSERT (((EFI_PHYSICAL_ADDRESS)(UINTN)(OldBuffer + OldSize) <= HandOffHob->EfiFreeMemoryBottom)); + ASSERT (((EFI_PHYSICAL_ADDRESS)(UINTN)((UINTN)OldBuffer + OldSize) <= HandOffHob->EfiFreeMemoryBottom)); } DEBUG_CODE_END (); diff --git a/EmbeddedPkg/Universal/MmcDxe/MmcBlockIo.c b/EmbeddedPkg/Universal/MmcDxe/MmcBlockIo.c index d695e25571..c234f41f02 100644 --- a/EmbeddedPkg/Universal/MmcDxe/MmcBlockIo.c +++ b/EmbeddedPkg/Universal/MmcDxe/MmcBlockIo.c @@ -42,7 +42,7 @@ MmcGetCardStatus ( if (MmcHostInstance->State != MmcHwInitializationState) { // Get the Status of the card. CmdArg = MmcHostInstance->CardInfo.RCA << 16; - Status = MmcHost->SendCommand (MmcHost, MMC_CMD13, CmdArg); + Status = MmcHost->SendCommand (MmcHost, MMC_CMD13, (UINT32)CmdArg); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "MmcGetCardStatus(MMC_CMD13): Error and Status = %r\n", Status)); return Status; @@ -165,7 +165,7 @@ MmcTransferBlock ( } } - Status = MmcHost->SendCommand (MmcHost, Cmd, CmdArg); + Status = MmcHost->SendCommand (MmcHost, (MMC_CMD)Cmd, (UINT32)CmdArg); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a(MMC_CMD%d): Error %r\n", __func__, Cmd, Status)); return Status; @@ -203,7 +203,7 @@ MmcTransferBlock ( && (MMC_R0_CURRENTSTATE (Response) != MMC_R0_STATE_TRAN) && Timeout--) { - Status = MmcHost->SendCommand (MmcHost, MMC_CMD13, CmdArg); + Status = MmcHost->SendCommand (MmcHost, MMC_CMD13, (UINT32)CmdArg); if (!EFI_ERROR (Status)) { MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_R1, Response); if (Response[0] & MMC_R0_READY_FOR_DATA) { @@ -319,7 +319,7 @@ MmcIoBlocks ( && (MMC_R0_CURRENTSTATE (Response) != MMC_R0_STATE_TRAN) && Timeout--) { - Status = MmcHost->SendCommand (MmcHost, MMC_CMD13, CmdArg); + Status = MmcHost->SendCommand (MmcHost, MMC_CMD13, (UINT32)CmdArg); if (!EFI_ERROR (Status)) { MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_R1, Response); } diff --git a/EmbeddedPkg/Universal/MmcDxe/MmcIdentification.c b/EmbeddedPkg/Universal/MmcDxe/MmcIdentification.c index 57388d9f46..d0bf59c79d 100755 --- a/EmbeddedPkg/Universal/MmcDxe/MmcIdentification.c +++ b/EmbeddedPkg/Universal/MmcDxe/MmcIdentification.c @@ -166,7 +166,7 @@ EmmcIdentificationMode ( } // Assign a relative address value to the card - MmcHostInstance->CardInfo.RCA = ++mEmmcRcaCount; // TODO: might need a more sophisticated way of doing this + MmcHostInstance->CardInfo.RCA = (UINT16)++mEmmcRcaCount; // TODO: might need a more sophisticated way of doing this RCA = MmcHostInstance->CardInfo.RCA << RCA_SHIFT_OFFSET; Status = Host->SendCommand (Host, MMC_CMD3, RCA); if (EFI_ERROR (Status)) { @@ -386,21 +386,21 @@ InitializeSdMmcDevice ( if (MmcHostInstance->CardInfo.CardType == SD_CARD_2_HIGH) { CardSize = HC_MMC_CSD_GET_DEVICESIZE (Response); NumBlocks = ((CardSize + 1) * 1024); - BlockSize = 1 << MMC_CSD_GET_READBLLEN (Response); + BlockSize = (UINTN)(1 << MMC_CSD_GET_READBLLEN (Response)); } else { CardSize = MMC_CSD_GET_DEVICESIZE (Response); - NumBlocks = (CardSize + 1) * (1 << (MMC_CSD_GET_DEVICESIZEMULT (Response) + 2)); - BlockSize = 1 << MMC_CSD_GET_READBLLEN (Response); + NumBlocks = (CardSize + 1) * (UINTN)(1 << (MMC_CSD_GET_DEVICESIZEMULT (Response) + 2)); + BlockSize = (UINTN)(1 << MMC_CSD_GET_READBLLEN (Response)); } // For >=2G card, BlockSize may be 1K, but the transfer size is 512 bytes. if (BlockSize > 512) { - NumBlocks = MultU64x32 (NumBlocks, BlockSize / 512); + NumBlocks = MultU64x32 (NumBlocks, (UINT32)(BlockSize / 512)); BlockSize = 512; } MmcHostInstance->BlockIo.Media->LastBlock = (NumBlocks - 1); - MmcHostInstance->BlockIo.Media->BlockSize = BlockSize; + MmcHostInstance->BlockIo.Media->BlockSize = (UINT32)BlockSize; MmcHostInstance->BlockIo.Media->ReadOnly = MmcHost->IsReadOnly (MmcHost); MmcHostInstance->BlockIo.Media->MediaPresent = TRUE; MmcHostInstance->BlockIo.Media->MediaId++; @@ -629,7 +629,7 @@ MmcIdentificationMode ( // Check which kind of card we are using. Ver2.00 or later SD Memory Card (PL180 is SD v1.1) CmdArg = (0x0UL << 12 | BIT8 | 0xCEUL << 0); - Status = MmcHost->SendCommand (MmcHost, MMC_CMD8, CmdArg); + Status = MmcHost->SendCommand (MmcHost, MMC_CMD8, (UINT32)CmdArg); if (Status == EFI_SUCCESS) { DEBUG ((DEBUG_ERROR, "Card is SD2.0 => Supports high capacity\n")); IsHCS = TRUE; @@ -668,7 +668,7 @@ MmcIdentificationMode ( CmdArg |= BIT30; } - Status = MmcHost->SendCommand (MmcHost, MMC_ACMD41, CmdArg); + Status = MmcHost->SendCommand (MmcHost, MMC_ACMD41, (UINT32)CmdArg); if (!EFI_ERROR (Status)) { Status = MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_OCR, Response); if (EFI_ERROR (Status)) { @@ -751,7 +751,7 @@ MmcIdentificationMode ( // The status returned for this CMD3 will be 2 - identification // CmdArg = 1; - Status = MmcHost->SendCommand (MmcHost, MMC_CMD3, CmdArg); + Status = MmcHost->SendCommand (MmcHost, MMC_CMD3, (UINT32)CmdArg); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "MmcIdentificationMode(MMC_CMD3): Error\n")); return Status; @@ -769,7 +769,7 @@ MmcIdentificationMode ( if (MmcHostInstance->CardInfo.CardType != MMC_CARD) { MmcHostInstance->CardInfo.RCA = Response[0] >> 16; } else { - MmcHostInstance->CardInfo.RCA = CmdArg; + MmcHostInstance->CardInfo.RCA = (UINT16)CmdArg; } Status = MmcNotifyState (MmcHostInstance, MmcStandByState); @@ -829,7 +829,7 @@ InitializeMmcDevice ( // Block Count (not used). Could return an error for SD card if (MmcHostInstance->CardInfo.CardType == MMC_CARD) { - Status = MmcHost->SendCommand (MmcHost, MMC_CMD23, BlockCount); + Status = MmcHost->SendCommand (MmcHost, MMC_CMD23, (UINT32)BlockCount); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "InitializeMmcDevice(MMC_CMD23): Error, Status=%r\n", Status)); return Status; -- 2.40.0.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#115181): https://edk2.groups.io/g/devel/message/115181 Mute This Topic: https://groups.io/mt/104200931/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=- ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [edk2-devel] [edk2 Patch 1/1] EmbeddedPkg: Fix compiler errors due to implicit conversions 2024-02-06 16:23 ` [edk2-devel] [edk2 Patch 1/1] EmbeddedPkg: " Jayaprakash, N @ 2024-02-07 19:59 ` Laszlo Ersek 2024-02-08 17:58 ` Leif Lindholm 0 siblings, 1 reply; 4+ messages in thread From: Laszlo Ersek @ 2024-02-07 19:59 UTC (permalink / raw) To: Jayaprakash N, devel Cc: Rebecca Cran, Michael D Kinney, Leif Lindholm, Ard Biesheuvel, Abner Chang On 2/6/24 17:23, Jayaprakash N wrote: > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4669 > > This commit fixes compilation issues reported through BZ4669. > There were several compilation errors due to implicit type > conversions in EmbeddedPkg. Fixed all the issues with the > correct usage of explicit type conversions based on the > context. > > Cc: Rebecca Cran <rebecca@bsdio.com> > Cc: Michael D Kinney <michael.d.kinney@intel.com> > Cc: Laszlo Ersek <lersek@redhat.com> > Cc: Leif Lindholm <quic_llindhol@quicinc.com> > Cc: Ard Biesheuvel <ardb+tianocore@kernel.org> > Cc: Abner Chang <abner.chang@amd.com> > Cc: Jayaprakash N <n.jayaprakash@intel.com> > Signed-off-by: Jayaprakash N <n.jayaprakash@intel.com> > --- > EmbeddedPkg/GdbStub/X64/Processor.c | 36 +++++++++---------- > EmbeddedPkg/Include/libfdt_env.h | 8 ++--- > EmbeddedPkg/Library/FdtLib/fdt.c | 9 ++--- > EmbeddedPkg/Library/FdtLib/fdt_overlay.c | 20 +++++------ > EmbeddedPkg/Library/FdtLib/fdt_ro.c | 32 ++++++++--------- > EmbeddedPkg/Library/FdtLib/fdt_rw.c | 24 ++++++------- > EmbeddedPkg/Library/FdtLib/fdt_strerror.c | 2 +- > EmbeddedPkg/Library/FdtLib/fdt_strtoul.c | 2 +- > EmbeddedPkg/Library/FdtLib/fdt_sw.c | 10 +++--- > EmbeddedPkg/Library/FdtLib/fdt_wip.c | 4 +-- > .../MemoryAllocationLib.c | 2 +- > EmbeddedPkg/Universal/MmcDxe/MmcBlockIo.c | 8 ++--- > .../Universal/MmcDxe/MmcIdentification.c | 22 ++++++------ > 13 files changed, 90 insertions(+), 89 deletions(-) This patch does way too many things at once. Please, minimally, split it into multiple patches, at module boundaries. Second, I'm unsure if edk2 considers FdtLib a completely detached fork of libfdt, at this point. If so, then fixing the warnings in the edk2 tree is valid (but should still be likely structured with finer granularity). If not (i.e., if we still intend to update FdtLib to more recent libfdt versions in the future), then these fixes don't belong in edk2 (we'd have to redo them after every update); they should be upstreamed to libfdt. Laszlo > > diff --git a/EmbeddedPkg/GdbStub/X64/Processor.c b/EmbeddedPkg/GdbStub/X64/Processor.c > index 4ff79abe42..b03d15938c 100644 > --- a/EmbeddedPkg/GdbStub/X64/Processor.c > +++ b/EmbeddedPkg/GdbStub/X64/Processor.c > @@ -599,31 +599,31 @@ EnableDebugRegister ( > Dr7.UintN = SystemContext.SystemContextIa32->Dr7; > > if (Register == 0) { > - SystemContext.SystemContextIa32->Dr0 = Address; > + SystemContext.SystemContextIa32->Dr0 = (UINT32)Address; > Dr7.Bits.G0 = 1; > - Dr7.Bits.RW0 = Type; > - Dr7.Bits.LEN0 = Length; > + Dr7.Bits.RW0 = (UINT32)Type; > + Dr7.Bits.LEN0 = (UINT32)Length; > } else if (Register == 1) { > - SystemContext.SystemContextIa32->Dr1 = Address; > + SystemContext.SystemContextIa32->Dr1 = (UINT32)Address; > Dr7.Bits.G1 = 1; > - Dr7.Bits.RW1 = Type; > - Dr7.Bits.LEN1 = Length; > + Dr7.Bits.RW1 = (UINT32)Type; > + Dr7.Bits.LEN1 = (UINT32)Length; > } else if (Register == 2) { > - SystemContext.SystemContextIa32->Dr2 = Address; > + SystemContext.SystemContextIa32->Dr2 = (UINT32)Address; > Dr7.Bits.G2 = 1; > - Dr7.Bits.RW2 = Type; > - Dr7.Bits.LEN2 = Length; > + Dr7.Bits.RW2 = (UINT32)Type; > + Dr7.Bits.LEN2 = (UINT32)Length; > } else if (Register == 3) { > - SystemContext.SystemContextIa32->Dr3 = Address; > + SystemContext.SystemContextIa32->Dr3 = (UINT32)Address; > Dr7.Bits.G3 = 1; > - Dr7.Bits.RW3 = Type; > - Dr7.Bits.LEN3 = Length; > + Dr7.Bits.RW3 = (UINT32)Type; > + Dr7.Bits.LEN3 = (UINT32)Length; > } else { > return EFI_INVALID_PARAMETER; > } > > // Update Dr7 with appropriate Gn, RWn and LENn bits > - SystemContext.SystemContextIa32->Dr7 = Dr7.UintN; > + SystemContext.SystemContextIa32->Dr7 = (UINT32)(Dr7.UintN); > > return EFI_SUCCESS; > } > @@ -722,22 +722,22 @@ DisableDebugRegister ( > Dr7.UintN = SystemContext.SystemContextIa32->Dr7; > > if (Register == 0) { > - SystemContext.SystemContextIa32->Dr0 = Address; > + SystemContext.SystemContextIa32->Dr0 = (UINT32)Address; > Dr7.Bits.G0 = 0; > Dr7.Bits.RW0 = 0; > Dr7.Bits.LEN0 = 0; > } else if (Register == 1) { > - SystemContext.SystemContextIa32->Dr1 = Address; > + SystemContext.SystemContextIa32->Dr1 = (UINT32)Address; > Dr7.Bits.G1 = 0; > Dr7.Bits.RW1 = 0; > Dr7.Bits.LEN1 = 0; > } else if (Register == 2) { > - SystemContext.SystemContextIa32->Dr2 = Address; > + SystemContext.SystemContextIa32->Dr2 = (UINT32)Address; > Dr7.Bits.G2 = 0; > Dr7.Bits.RW2 = 0; > Dr7.Bits.LEN2 = 0; > } else if (Register == 3) { > - SystemContext.SystemContextIa32->Dr3 = Address; > + SystemContext.SystemContextIa32->Dr3 = (UINT32)Address; > Dr7.Bits.G3 = 0; > Dr7.Bits.RW3 = 0; > Dr7.Bits.LEN3 = 0; > @@ -746,7 +746,7 @@ DisableDebugRegister ( > } > > // Update DR7 register so appropriate Gn, RWn and LENn bits can be turned off. > - SystemContext.SystemContextIa32->Dr7 = Dr7.UintN; > + SystemContext.SystemContextIa32->Dr7 = (UINT32)(Dr7.UintN); > > return EFI_SUCCESS; > } > diff --git a/EmbeddedPkg/Include/libfdt_env.h b/EmbeddedPkg/Include/libfdt_env.h > index dfd3bac01f..1b08727a12 100644 > --- a/EmbeddedPkg/Include/libfdt_env.h > +++ b/EmbeddedPkg/Include/libfdt_env.h > @@ -80,7 +80,7 @@ memset ( > size_t n > ) > { > - return SetMem (s, n, c); > + return SetMem (s, n, (UINT8)c); > } > > static inline int > @@ -90,7 +90,7 @@ memcmp ( > int len > ) > { > - return CompareMem (dest, src, len); > + return (int) CompareMem (dest, src, len); > } > > static inline void * > @@ -100,7 +100,7 @@ memchr ( > size_t n > ) > { > - return ScanMem8 (s, n, c); > + return ScanMem8 (s, n, (UINT8)c); > } > > static inline size_t > @@ -119,7 +119,7 @@ strchr ( > { > char pattern[2]; > > - pattern[0] = c; > + pattern[0] = (char)c; > pattern[1] = 0; > return AsciiStrStr (s, pattern); > } > diff --git a/EmbeddedPkg/Library/FdtLib/fdt.c b/EmbeddedPkg/Library/FdtLib/fdt.c > index 56a9787cd0..e7dc86b46c 100644 > --- a/EmbeddedPkg/Library/FdtLib/fdt.c > +++ b/EmbeddedPkg/Library/FdtLib/fdt.c > @@ -90,7 +90,8 @@ fdt_offset_ptr ( > { > unsigned absoffset = offset + fdt_off_dt_struct (fdt); > > - if ( (absoffset < offset) > + if ( (offset < 0) > + || (absoffset < (unsigned int)offset) > || ((absoffset + len) < absoffset) > || ((absoffset + len) > fdt_totalsize (fdt))) > { > @@ -98,7 +99,7 @@ fdt_offset_ptr ( > } > > if (fdt_version (fdt) >= 0x11) { > - if ( ((offset + len) < offset) > + if ( ((offset + len) < (unsigned int)offset) > || ((offset + len) > fdt_size_dt_struct (fdt))) > { > return NULL; > @@ -299,7 +300,7 @@ _fdt_find_string ( > const char *s > ) > { > - int len = strlen (s) + 1; > + int len = (int) strlen (s) + 1; > const char *last = strtab + tabsize - len; > const char *p; > > @@ -321,7 +322,7 @@ fdt_move ( > { > FDT_CHECK_HEADER (fdt); > > - if (fdt_totalsize (fdt) > bufsize) { > + if ((bufsize < 0) || (fdt_totalsize (fdt) > (unsigned int)bufsize)) { > return -FDT_ERR_NOSPACE; > } > > diff --git a/EmbeddedPkg/Library/FdtLib/fdt_overlay.c b/EmbeddedPkg/Library/FdtLib/fdt_overlay.c > index 0e6b8715e4..1828e7afd9 100644 > --- a/EmbeddedPkg/Library/FdtLib/fdt_overlay.c > +++ b/EmbeddedPkg/Library/FdtLib/fdt_overlay.c > @@ -362,7 +362,7 @@ overlay_update_local_node_references ( > fdto, > tree_node, > name, > - strlen (name), > + (int)strlen (name), > poffset, > &adj_val, > sizeof (adj_val) > @@ -610,7 +610,7 @@ overlay_fixup_phandle ( > return -FDT_ERR_BADOVERLAY; > } > > - fixup_len = fixup_end - fixup_str; > + fixup_len = (uint32_t)(fixup_end - fixup_str); > > len -= fixup_len + 1; > value += fixup_len + 1; > @@ -621,7 +621,7 @@ overlay_fixup_phandle ( > return -FDT_ERR_BADOVERLAY; > } > > - path_len = sep - path; > + path_len = (uint32_t)(sep - path); > if (path_len == (fixup_len - 1)) { > return -FDT_ERR_BADOVERLAY; > } > @@ -633,7 +633,7 @@ overlay_fixup_phandle ( > return -FDT_ERR_BADOVERLAY; > } > > - name_len = sep - name; > + name_len = (uint32_t)(sep - name); > if (!name_len) { > return -FDT_ERR_BADOVERLAY; > } > @@ -971,7 +971,7 @@ overlay_symbol_update ( > } > > frag_name = path + 1; > - frag_name_len = s - path - 1; > + frag_name_len = (int)(s - path - 1); > > /* verify format; safe since "s" lies in \0 terminated prop */ > len = sizeof ("/__overlay__/") - 1; > @@ -980,7 +980,7 @@ overlay_symbol_update ( > } > > rel_path = s + len; > - rel_path_len = e - rel_path; > + rel_path_len = (int)(e - rel_path); > > /* find the fragment index in which the symbol lies */ > ret = fdt_subnode_offset_namelen ( > @@ -1019,7 +1019,7 @@ overlay_symbol_update ( > > len = ret; > } else { > - len = strlen (target_path); > + len = (int)strlen (target_path); > } > > ret = fdt_setprop_placeholder ( > @@ -1106,7 +1106,7 @@ fdt_overlay_apply ( > /* > * The overlay has been damaged, erase its magic. > */ > - fdt_set_magic (fdto, ~0); > + fdt_set_magic (fdto, (uint32_t)~0); > > return 0; > > @@ -1115,13 +1115,13 @@ err: > /* > * The overlay might have been damaged, erase its magic. > */ > - fdt_set_magic (fdto, ~0); > + fdt_set_magic (fdto, (uint32_t)~0); > > /* > * The base device tree might have been damaged, erase its > * magic. > */ > - fdt_set_magic (fdt, ~0); > + fdt_set_magic (fdt, (uint32_t)~0); > > return ret; > } > diff --git a/EmbeddedPkg/Library/FdtLib/fdt_ro.c b/EmbeddedPkg/Library/FdtLib/fdt_ro.c > index 30aac37958..1f2aee3405 100644 > --- a/EmbeddedPkg/Library/FdtLib/fdt_ro.c > +++ b/EmbeddedPkg/Library/FdtLib/fdt_ro.c > @@ -234,7 +234,7 @@ fdt_subnode_offset ( > const char *name > ) > { > - return fdt_subnode_offset_namelen (fdt, parentoffset, name, strlen (name)); > + return fdt_subnode_offset_namelen (fdt, parentoffset, name, (int)strlen (name)); > } > > int > @@ -258,7 +258,7 @@ fdt_path_offset_namelen ( > q = end; > } > > - p = fdt_get_alias_namelen (fdt, p, q - p); > + p = fdt_get_alias_namelen (fdt, p, (int)(q - p)); > if (!p) { > return -FDT_ERR_BADPATH; > } > @@ -283,7 +283,7 @@ fdt_path_offset_namelen ( > q = end; > } > > - offset = fdt_subnode_offset_namelen (fdt, offset, p, q-p); > + offset = fdt_subnode_offset_namelen (fdt, offset, p, (int)(q-p)); > if (offset < 0) { > return offset; > } > @@ -300,7 +300,7 @@ fdt_path_offset ( > const char *path > ) > { > - return fdt_path_offset_namelen (fdt, path, strlen (path)); > + return fdt_path_offset_namelen (fdt, path, (int)strlen (path)); > } > > const char * > @@ -320,7 +320,7 @@ fdt_get_name ( > } > > if (len) { > - *len = strlen (nh->name); > + *len = (int)strlen (nh->name); > } > > return nh->name; > @@ -402,8 +402,8 @@ fdt_get_property_namelen ( > (offset = fdt_next_property_offset (fdt, offset))) > { > const struct fdt_property *prop; > - > - if (!(prop = fdt_get_property_by_offset (fdt, offset, lenp))) { > + prop = fdt_get_property_by_offset (fdt, offset, lenp); > + if (!prop) { > offset = -FDT_ERR_INTERNAL; > break; > } > @@ -438,7 +438,7 @@ fdt_get_property ( > fdt, > nodeoffset, > name, > - strlen (name), > + (int)strlen (name), > lenp > ); > } > @@ -492,7 +492,7 @@ fdt_getprop ( > int *lenp > ) > { > - return fdt_getprop_namelen (fdt, nodeoffset, name, strlen (name), lenp); > + return fdt_getprop_namelen (fdt, nodeoffset, name, (int)strlen (name), lenp); > } > > uint32_t > @@ -540,7 +540,7 @@ fdt_get_alias ( > const char *name > ) > { > - return fdt_get_alias_namelen (fdt, name, strlen (name)); > + return fdt_get_alias_namelen (fdt, name, (int)strlen (name)); > } > > int > @@ -769,7 +769,7 @@ fdt_stringlist_contains ( > const char *str > ) > { > - int len = strlen (str); > + int len = (int)strlen (str); > const char *p; > > while (listlen >= len) { > @@ -782,7 +782,7 @@ fdt_stringlist_contains ( > return 0; /* malformed strlist.. */ > } > > - listlen -= (p-strlist) + 1; > + listlen -= (int)(p-strlist) + 1; > strlist = p + 1; > } > > @@ -807,7 +807,7 @@ fdt_stringlist_count ( > end = list + length; > > while (list < end) { > - length = strnlen (list, end - list) + 1; > + length = (int)strnlen (list, end - list) + 1; > > /* Abort if the last string isn't properly NUL-terminated. */ > if (list + length > end) { > @@ -837,11 +837,11 @@ fdt_stringlist_search ( > return length; > } > > - len = strlen (string) + 1; > + len = (int)strlen (string) + 1; > end = list + length; > > while (list < end) { > - length = strnlen (list, end - list) + 1; > + length = (int)strnlen (list, end - list) + 1; > > /* Abort if the last string isn't properly NUL-terminated. */ > if (list + length > end) { > @@ -883,7 +883,7 @@ fdt_stringlist_get ( > end = list + length; > > while (list < end) { > - length = strnlen (list, end - list) + 1; > + length = (int)strnlen (list, end - list) + 1; > > /* Abort if the last string isn't properly NUL-terminated. */ > if (list + length > end) { > diff --git a/EmbeddedPkg/Library/FdtLib/fdt_rw.c b/EmbeddedPkg/Library/FdtLib/fdt_rw.c > index cb5088a3af..5d172127e4 100644 > --- a/EmbeddedPkg/Library/FdtLib/fdt_rw.c > +++ b/EmbeddedPkg/Library/FdtLib/fdt_rw.c > @@ -171,8 +171,8 @@ _fdt_splice_struct ( > { > int delta = newlen - oldlen; > int err; > - > - if ((err = _fdt_splice (fdt, p, oldlen, newlen))) { > + err = _fdt_splice (fdt, p, oldlen, newlen); > + if (err) { > return err; > } > > @@ -190,8 +190,8 @@ _fdt_splice_string ( > void *p = (char *)fdt > + fdt_off_dt_strings (fdt) + fdt_size_dt_strings (fdt); > int err; > - > - if ((err = _fdt_splice (fdt, p, 0, newlen))) { > + err = _fdt_splice (fdt, p, 0, newlen); > + if (err) { > return err; > } > > @@ -208,13 +208,13 @@ _fdt_find_add_string ( > char *strtab = (char *)fdt + fdt_off_dt_strings (fdt); > const char *p; > char *new; > - int len = strlen (s) + 1; > + int len = (int)strlen (s) + 1; > int err; > > p = _fdt_find_string (strtab, fdt_size_dt_strings (fdt), s); > if (p) { > /* found it */ > - return (p - strtab); > + return (int)(p - strtab); > } > > new = strtab + fdt_size_dt_strings (fdt); > @@ -224,7 +224,7 @@ _fdt_find_add_string ( > } > > memcpy (new, s, len); > - return (new - strtab); > + return (int)(new - strtab); > } > > int > @@ -283,13 +283,13 @@ _fdt_resize_property ( > if (!*prop) { > return oldlen; > } > - > - if ((err = _fdt_splice_struct ( > + err = _fdt_splice_struct ( > fdt, > (*prop)->data, > FDT_TAGALIGN (oldlen), > FDT_TAGALIGN (len) > - ))) > + ); > + if (err) > { > return err; > } > @@ -353,7 +353,7 @@ fdt_set_name ( > return oldlen; > } > > - newlen = strlen (name); > + newlen = (int)strlen (name); > > err = _fdt_splice_struct ( > fdt, > @@ -537,7 +537,7 @@ fdt_add_subnode ( > const char *name > ) > { > - return fdt_add_subnode_namelen (fdt, parentoffset, name, strlen (name)); > + return fdt_add_subnode_namelen (fdt, parentoffset, name, (int)strlen (name)); > } > > int > diff --git a/EmbeddedPkg/Library/FdtLib/fdt_strerror.c b/EmbeddedPkg/Library/FdtLib/fdt_strerror.c > index cb07f6166e..36e2613b43 100644 > --- a/EmbeddedPkg/Library/FdtLib/fdt_strerror.c > +++ b/EmbeddedPkg/Library/FdtLib/fdt_strerror.c > @@ -94,7 +94,7 @@ fdt_strerror ( > return "<valid offset/length>"; > } else if (errval == 0) { > return "<no error>"; > - } else if (errval > -FDT_ERRTABSIZE) { > + } else if (errval > (-1 * FDT_ERRTABSIZE)) { > const char *s = fdt_errtable[-errval].str; > > if (s) { > diff --git a/EmbeddedPkg/Library/FdtLib/fdt_strtoul.c b/EmbeddedPkg/Library/FdtLib/fdt_strtoul.c > index e615d6f4c0..c340771918 100644 > --- a/EmbeddedPkg/Library/FdtLib/fdt_strtoul.c > +++ b/EmbeddedPkg/Library/FdtLib/fdt_strtoul.c > @@ -33,5 +33,5 @@ strtoul ( > return MAX_UINTN; > } > > - return ReturnValue; > + return (unsigned long)ReturnValue; > } > diff --git a/EmbeddedPkg/Library/FdtLib/fdt_sw.c b/EmbeddedPkg/Library/FdtLib/fdt_sw.c > index 6bcdd1fc7b..1fb47776cb 100644 > --- a/EmbeddedPkg/Library/FdtLib/fdt_sw.c > +++ b/EmbeddedPkg/Library/FdtLib/fdt_sw.c > @@ -91,7 +91,7 @@ _fdt_grab_space ( > return NULL; > } > > - fdt_set_size_dt_struct (fdt, offset + len); > + fdt_set_size_dt_struct (fdt, offset + (int)len); > return _fdt_offset_ptr_w (fdt, offset); > } > > @@ -210,7 +210,7 @@ fdt_begin_node ( > ) > { > struct fdt_node_header *nh; > - int namelen = strlen (name) + 1; > + int namelen = (int)strlen (name) + 1; > > FDT_SW_CHECK_HEADER (fdt); > > @@ -251,18 +251,18 @@ _fdt_find_add_string ( > char *strtab = (char *)fdt + fdt_totalsize (fdt); > const char *p; > int strtabsize = fdt_size_dt_strings (fdt); > - int len = strlen (s) + 1; > + int len = (int)strlen (s) + 1; > int struct_top, offset; > > p = _fdt_find_string (strtab - strtabsize, strtabsize, s); > if (p) { > - return p - strtab; > + return (int)(p - strtab); > } > > /* Add it */ > offset = -strtabsize - len; > struct_top = fdt_off_dt_struct (fdt) + fdt_size_dt_struct (fdt); > - if (fdt_totalsize (fdt) + offset < struct_top) { > + if (fdt_totalsize (fdt) + offset < (uint32_t)struct_top) { > return 0; /* no more room :( */ > } > > diff --git a/EmbeddedPkg/Library/FdtLib/fdt_wip.c b/EmbeddedPkg/Library/FdtLib/fdt_wip.c > index 8447706919..2f822fce61 100644 > --- a/EmbeddedPkg/Library/FdtLib/fdt_wip.c > +++ b/EmbeddedPkg/Library/FdtLib/fdt_wip.c > @@ -80,7 +80,7 @@ fdt_setprop_inplace_namelen_partial ( > return proplen; > } > > - if (proplen < (len + idx)) { > + if ((proplen < 0) || ((uint32_t)proplen < (len + idx))) { > return -FDT_ERR_NOSPACE; > } > > @@ -113,7 +113,7 @@ fdt_setprop_inplace ( > fdt, > nodeoffset, > name, > - strlen (name), > + (int)strlen (name), > 0, > val, > len > diff --git a/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c b/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c > index fa81cc9d59..11566cf57f 100644 > --- a/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c > +++ b/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c > @@ -308,7 +308,7 @@ ReallocatePool ( > if (OldBuffer != NULL) { > HandOffHob = GetHobList (); > ASSERT (((EFI_PHYSICAL_ADDRESS)(UINTN)OldBuffer >= HandOffHob->EfiMemoryBottom)); > - ASSERT (((EFI_PHYSICAL_ADDRESS)(UINTN)(OldBuffer + OldSize) <= HandOffHob->EfiFreeMemoryBottom)); > + ASSERT (((EFI_PHYSICAL_ADDRESS)(UINTN)((UINTN)OldBuffer + OldSize) <= HandOffHob->EfiFreeMemoryBottom)); > } > > DEBUG_CODE_END (); > diff --git a/EmbeddedPkg/Universal/MmcDxe/MmcBlockIo.c b/EmbeddedPkg/Universal/MmcDxe/MmcBlockIo.c > index d695e25571..c234f41f02 100644 > --- a/EmbeddedPkg/Universal/MmcDxe/MmcBlockIo.c > +++ b/EmbeddedPkg/Universal/MmcDxe/MmcBlockIo.c > @@ -42,7 +42,7 @@ MmcGetCardStatus ( > if (MmcHostInstance->State != MmcHwInitializationState) { > // Get the Status of the card. > CmdArg = MmcHostInstance->CardInfo.RCA << 16; > - Status = MmcHost->SendCommand (MmcHost, MMC_CMD13, CmdArg); > + Status = MmcHost->SendCommand (MmcHost, MMC_CMD13, (UINT32)CmdArg); > if (EFI_ERROR (Status)) { > DEBUG ((DEBUG_ERROR, "MmcGetCardStatus(MMC_CMD13): Error and Status = %r\n", Status)); > return Status; > @@ -165,7 +165,7 @@ MmcTransferBlock ( > } > } > > - Status = MmcHost->SendCommand (MmcHost, Cmd, CmdArg); > + Status = MmcHost->SendCommand (MmcHost, (MMC_CMD)Cmd, (UINT32)CmdArg); > if (EFI_ERROR (Status)) { > DEBUG ((DEBUG_ERROR, "%a(MMC_CMD%d): Error %r\n", __func__, Cmd, Status)); > return Status; > @@ -203,7 +203,7 @@ MmcTransferBlock ( > && (MMC_R0_CURRENTSTATE (Response) != MMC_R0_STATE_TRAN) > && Timeout--) > { > - Status = MmcHost->SendCommand (MmcHost, MMC_CMD13, CmdArg); > + Status = MmcHost->SendCommand (MmcHost, MMC_CMD13, (UINT32)CmdArg); > if (!EFI_ERROR (Status)) { > MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_R1, Response); > if (Response[0] & MMC_R0_READY_FOR_DATA) { > @@ -319,7 +319,7 @@ MmcIoBlocks ( > && (MMC_R0_CURRENTSTATE (Response) != MMC_R0_STATE_TRAN) > && Timeout--) > { > - Status = MmcHost->SendCommand (MmcHost, MMC_CMD13, CmdArg); > + Status = MmcHost->SendCommand (MmcHost, MMC_CMD13, (UINT32)CmdArg); > if (!EFI_ERROR (Status)) { > MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_R1, Response); > } > diff --git a/EmbeddedPkg/Universal/MmcDxe/MmcIdentification.c b/EmbeddedPkg/Universal/MmcDxe/MmcIdentification.c > index 57388d9f46..d0bf59c79d 100755 > --- a/EmbeddedPkg/Universal/MmcDxe/MmcIdentification.c > +++ b/EmbeddedPkg/Universal/MmcDxe/MmcIdentification.c > @@ -166,7 +166,7 @@ EmmcIdentificationMode ( > } > > // Assign a relative address value to the card > - MmcHostInstance->CardInfo.RCA = ++mEmmcRcaCount; // TODO: might need a more sophisticated way of doing this > + MmcHostInstance->CardInfo.RCA = (UINT16)++mEmmcRcaCount; // TODO: might need a more sophisticated way of doing this > RCA = MmcHostInstance->CardInfo.RCA << RCA_SHIFT_OFFSET; > Status = Host->SendCommand (Host, MMC_CMD3, RCA); > if (EFI_ERROR (Status)) { > @@ -386,21 +386,21 @@ InitializeSdMmcDevice ( > if (MmcHostInstance->CardInfo.CardType == SD_CARD_2_HIGH) { > CardSize = HC_MMC_CSD_GET_DEVICESIZE (Response); > NumBlocks = ((CardSize + 1) * 1024); > - BlockSize = 1 << MMC_CSD_GET_READBLLEN (Response); > + BlockSize = (UINTN)(1 << MMC_CSD_GET_READBLLEN (Response)); > } else { > CardSize = MMC_CSD_GET_DEVICESIZE (Response); > - NumBlocks = (CardSize + 1) * (1 << (MMC_CSD_GET_DEVICESIZEMULT (Response) + 2)); > - BlockSize = 1 << MMC_CSD_GET_READBLLEN (Response); > + NumBlocks = (CardSize + 1) * (UINTN)(1 << (MMC_CSD_GET_DEVICESIZEMULT (Response) + 2)); > + BlockSize = (UINTN)(1 << MMC_CSD_GET_READBLLEN (Response)); > } > > // For >=2G card, BlockSize may be 1K, but the transfer size is 512 bytes. > if (BlockSize > 512) { > - NumBlocks = MultU64x32 (NumBlocks, BlockSize / 512); > + NumBlocks = MultU64x32 (NumBlocks, (UINT32)(BlockSize / 512)); > BlockSize = 512; > } > > MmcHostInstance->BlockIo.Media->LastBlock = (NumBlocks - 1); > - MmcHostInstance->BlockIo.Media->BlockSize = BlockSize; > + MmcHostInstance->BlockIo.Media->BlockSize = (UINT32)BlockSize; > MmcHostInstance->BlockIo.Media->ReadOnly = MmcHost->IsReadOnly (MmcHost); > MmcHostInstance->BlockIo.Media->MediaPresent = TRUE; > MmcHostInstance->BlockIo.Media->MediaId++; > @@ -629,7 +629,7 @@ MmcIdentificationMode ( > > // Check which kind of card we are using. Ver2.00 or later SD Memory Card (PL180 is SD v1.1) > CmdArg = (0x0UL << 12 | BIT8 | 0xCEUL << 0); > - Status = MmcHost->SendCommand (MmcHost, MMC_CMD8, CmdArg); > + Status = MmcHost->SendCommand (MmcHost, MMC_CMD8, (UINT32)CmdArg); > if (Status == EFI_SUCCESS) { > DEBUG ((DEBUG_ERROR, "Card is SD2.0 => Supports high capacity\n")); > IsHCS = TRUE; > @@ -668,7 +668,7 @@ MmcIdentificationMode ( > CmdArg |= BIT30; > } > > - Status = MmcHost->SendCommand (MmcHost, MMC_ACMD41, CmdArg); > + Status = MmcHost->SendCommand (MmcHost, MMC_ACMD41, (UINT32)CmdArg); > if (!EFI_ERROR (Status)) { > Status = MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_OCR, Response); > if (EFI_ERROR (Status)) { > @@ -751,7 +751,7 @@ MmcIdentificationMode ( > // The status returned for this CMD3 will be 2 - identification > // > CmdArg = 1; > - Status = MmcHost->SendCommand (MmcHost, MMC_CMD3, CmdArg); > + Status = MmcHost->SendCommand (MmcHost, MMC_CMD3, (UINT32)CmdArg); > if (EFI_ERROR (Status)) { > DEBUG ((DEBUG_ERROR, "MmcIdentificationMode(MMC_CMD3): Error\n")); > return Status; > @@ -769,7 +769,7 @@ MmcIdentificationMode ( > if (MmcHostInstance->CardInfo.CardType != MMC_CARD) { > MmcHostInstance->CardInfo.RCA = Response[0] >> 16; > } else { > - MmcHostInstance->CardInfo.RCA = CmdArg; > + MmcHostInstance->CardInfo.RCA = (UINT16)CmdArg; > } > > Status = MmcNotifyState (MmcHostInstance, MmcStandByState); > @@ -829,7 +829,7 @@ InitializeMmcDevice ( > > // Block Count (not used). Could return an error for SD card > if (MmcHostInstance->CardInfo.CardType == MMC_CARD) { > - Status = MmcHost->SendCommand (MmcHost, MMC_CMD23, BlockCount); > + Status = MmcHost->SendCommand (MmcHost, MMC_CMD23, (UINT32)BlockCount); > if (EFI_ERROR (Status)) { > DEBUG ((DEBUG_ERROR, "InitializeMmcDevice(MMC_CMD23): Error, Status=%r\n", Status)); > return Status; -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#115245): https://edk2.groups.io/g/devel/message/115245 Mute This Topic: https://groups.io/mt/104200931/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=- ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [edk2-devel] [edk2 Patch 1/1] EmbeddedPkg: Fix compiler errors due to implicit conversions 2024-02-07 19:59 ` Laszlo Ersek @ 2024-02-08 17:58 ` Leif Lindholm 0 siblings, 0 replies; 4+ messages in thread From: Leif Lindholm @ 2024-02-08 17:58 UTC (permalink / raw) To: Laszlo Ersek, Jayaprakash N, devel Cc: Rebecca Cran, Michael D Kinney, Ard Biesheuvel, Abner Chang On 2024-02-07 19:59, Laszlo Ersek wrote: > On 2/6/24 17:23, Jayaprakash N wrote: >> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4669 >> >> This commit fixes compilation issues reported through BZ4669. >> There were several compilation errors due to implicit type >> conversions in EmbeddedPkg. Fixed all the issues with the >> correct usage of explicit type conversions based on the >> context. >> >> Cc: Rebecca Cran <rebecca@bsdio.com> >> Cc: Michael D Kinney <michael.d.kinney@intel.com> >> Cc: Laszlo Ersek <lersek@redhat.com> >> Cc: Leif Lindholm <quic_llindhol@quicinc.com> >> Cc: Ard Biesheuvel <ardb+tianocore@kernel.org> >> Cc: Abner Chang <abner.chang@amd.com> >> Cc: Jayaprakash N <n.jayaprakash@intel.com> >> Signed-off-by: Jayaprakash N <n.jayaprakash@intel.com> >> --- >> EmbeddedPkg/GdbStub/X64/Processor.c | 36 +++++++++---------- >> EmbeddedPkg/Include/libfdt_env.h | 8 ++--- >> EmbeddedPkg/Library/FdtLib/fdt.c | 9 ++--- >> EmbeddedPkg/Library/FdtLib/fdt_overlay.c | 20 +++++------ >> EmbeddedPkg/Library/FdtLib/fdt_ro.c | 32 ++++++++--------- >> EmbeddedPkg/Library/FdtLib/fdt_rw.c | 24 ++++++------- >> EmbeddedPkg/Library/FdtLib/fdt_strerror.c | 2 +- >> EmbeddedPkg/Library/FdtLib/fdt_strtoul.c | 2 +- >> EmbeddedPkg/Library/FdtLib/fdt_sw.c | 10 +++--- >> EmbeddedPkg/Library/FdtLib/fdt_wip.c | 4 +-- >> .../MemoryAllocationLib.c | 2 +- >> EmbeddedPkg/Universal/MmcDxe/MmcBlockIo.c | 8 ++--- >> .../Universal/MmcDxe/MmcIdentification.c | 22 ++++++------ >> 13 files changed, 90 insertions(+), 89 deletions(-) > > This patch does way too many things at once. Please, minimally, split it > into multiple patches, at module boundaries. > > Second, I'm unsure if edk2 considers FdtLib a completely detached fork > of libfdt, at this point. If so, then fixing the warnings in the edk2 > tree is valid (but should still be likely structured with finer > granularity). If not (i.e., if we still intend to update FdtLib to more > recent libfdt versions in the future), then these fixes don't belong in > edk2 (we'd have to redo them after every update); they should be > upstreamed to libfdt. The EmbeddedPkg FdtLib is superseded by the MdePkg BaseFdtLib. My intent is to drop it, but I didn't get around to doing the rework of existing users in time for the soft freeze. / Leif -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#115271): https://edk2.groups.io/g/devel/message/115271 Mute This Topic: https://groups.io/mt/104200931/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=- ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-02-08 17:58 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2024-02-06 16:23 [edk2-devel] [edk2 Patch 0/1] Fix compiler errors due to implicit conversions Jayaprakash, N 2024-02-06 16:23 ` [edk2-devel] [edk2 Patch 1/1] EmbeddedPkg: " Jayaprakash, N 2024-02-07 19:59 ` Laszlo Ersek 2024-02-08 17:58 ` Leif Lindholm
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox