diff mbox series

MIPS: BCM47XX: Cast memcmp() of function to (void *)

Message ID 20220907230556.73536-1-keescook@chromium.org (mailing list archive)
State Accepted
Headers show
Series MIPS: BCM47XX: Cast memcmp() of function to (void *) | expand

Commit Message

Kees Cook Sept. 7, 2022, 11:05 p.m. UTC
Clang is especially sensitive about argument type matching when using
__overloaded functions (like memcmp(), etc). Help it see that function
pointers are just "void *". Avoids this error:

arch/mips/bcm47xx/prom.c:89:8: error: no matching function for call to 'memcmp'
                   if (!memcmp(prom_init, prom_init + mem, 32))
                        ^~~~~~
include/linux/string.h:156:12: note: candidate function not viable: no known conversion from 'void (void)' to 'const void *' for 1st argument extern int memcmp(const void *,const void *,__kernel_size_t);

Cc: Hauke Mehrtens <hauke@hauke-m.de>
Cc: "Rafał Miłecki" <zajec5@gmail.com>
Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: linux-mips@vger.kernel.org
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: llvm@lists.linux.dev
Reported-by: kernel test robot <lkp@intel.com>
Link: https://lore.kernel.org/lkml/202209080652.sz2d68e5-lkp@intel.com
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 arch/mips/bcm47xx/prom.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Gustavo A. R. Silva Sept. 8, 2022, 12:22 p.m. UTC | #1
On Wed, Sep 07, 2022 at 04:05:56PM -0700, Kees Cook wrote:
> Clang is especially sensitive about argument type matching when using
> __overloaded functions (like memcmp(), etc). Help it see that function
> pointers are just "void *". Avoids this error:
> 
> arch/mips/bcm47xx/prom.c:89:8: error: no matching function for call to 'memcmp'
>                    if (!memcmp(prom_init, prom_init + mem, 32))
>                         ^~~~~~
> include/linux/string.h:156:12: note: candidate function not viable: no known conversion from 'void (void)' to 'const void *' for 1st argument extern int memcmp(const void *,const void *,__kernel_size_t);
> 

Don't we have the same problem at line 162?

(next-20220908)arch/mips/bcm47xx/prom.c:
161         for (extmem = 128 << 20; extmem < 512 << 20; extmem <<= 1) {
162                 if (!memcmp(prom_init, (void *)(off + extmem), 16))
163                         break;
164         }

--
Gustavo

> Cc: Hauke Mehrtens <hauke@hauke-m.de>
> Cc: "Rafał Miłecki" <zajec5@gmail.com>
> Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
> Cc: linux-mips@vger.kernel.org
> Cc: Nathan Chancellor <nathan@kernel.org>
> Cc: Nick Desaulniers <ndesaulniers@google.com>
> Cc: llvm@lists.linux.dev
> Reported-by: kernel test robot <lkp@intel.com>
> Link: https://lore.kernel.org/lkml/202209080652.sz2d68e5-lkp@intel.com
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
>  arch/mips/bcm47xx/prom.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/mips/bcm47xx/prom.c b/arch/mips/bcm47xx/prom.c
> index ab203e66ba0d..eb5c04a24531 100644
> --- a/arch/mips/bcm47xx/prom.c
> +++ b/arch/mips/bcm47xx/prom.c
> @@ -86,7 +86,7 @@ static __init void prom_init_mem(void)
>  			pr_debug("Assume 128MB RAM\n");
>  			break;
>  		}
> -		if (!memcmp(prom_init, prom_init + mem, 32))
> +		if (!memcmp((void *)prom_init, (void *)prom_init + mem, 32))
>  			break;
>  	}
>  	lowmem = mem;
> -- 
> 2.34.1
>
Thomas Bogendoerfer Sept. 19, 2022, 2:49 p.m. UTC | #2
On Wed, Sep 07, 2022 at 04:05:56PM -0700, Kees Cook wrote:
> Clang is especially sensitive about argument type matching when using
> __overloaded functions (like memcmp(), etc). Help it see that function
> pointers are just "void *". Avoids this error:
> 
> arch/mips/bcm47xx/prom.c:89:8: error: no matching function for call to 'memcmp'
>                    if (!memcmp(prom_init, prom_init + mem, 32))
>                         ^~~~~~
> include/linux/string.h:156:12: note: candidate function not viable: no known conversion from 'void (void)' to 'const void *' for 1st argument extern int memcmp(const void *,const void *,__kernel_size_t);
> 
> Cc: Hauke Mehrtens <hauke@hauke-m.de>
> Cc: "Rafał Miłecki" <zajec5@gmail.com>
> Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
> Cc: linux-mips@vger.kernel.org
> Cc: Nathan Chancellor <nathan@kernel.org>
> Cc: Nick Desaulniers <ndesaulniers@google.com>
> Cc: llvm@lists.linux.dev
> Reported-by: kernel test robot <lkp@intel.com>
> Link: https://lore.kernel.org/lkml/202209080652.sz2d68e5-lkp@intel.com
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
>  arch/mips/bcm47xx/prom.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/mips/bcm47xx/prom.c b/arch/mips/bcm47xx/prom.c
> index ab203e66ba0d..eb5c04a24531 100644
> --- a/arch/mips/bcm47xx/prom.c
> +++ b/arch/mips/bcm47xx/prom.c
> @@ -86,7 +86,7 @@ static __init void prom_init_mem(void)
>  			pr_debug("Assume 128MB RAM\n");
>  			break;
>  		}
> -		if (!memcmp(prom_init, prom_init + mem, 32))
> +		if (!memcmp((void *)prom_init, (void *)prom_init + mem, 32))
>  			break;
>  	}
>  	lowmem = mem;
> -- 
> 2.34.1

applied to mips-next with the second memcmp(prom_init changed as well.

Thomas.
diff mbox series

Patch

diff --git a/arch/mips/bcm47xx/prom.c b/arch/mips/bcm47xx/prom.c
index ab203e66ba0d..eb5c04a24531 100644
--- a/arch/mips/bcm47xx/prom.c
+++ b/arch/mips/bcm47xx/prom.c
@@ -86,7 +86,7 @@  static __init void prom_init_mem(void)
 			pr_debug("Assume 128MB RAM\n");
 			break;
 		}
-		if (!memcmp(prom_init, prom_init + mem, 32))
+		if (!memcmp((void *)prom_init, (void *)prom_init + mem, 32))
 			break;
 	}
 	lowmem = mem;