Re: [PATCH] platform/x86/amd/hsmp: fix compile-testing without CONFiG_AMD_NB
From: Ilpo Järvinen
Date: Tue Oct 29 2024 - 08:40:03 EST
On Tue, 29 Oct 2024, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@xxxxxxxx>
>
> node_to_amd_nb() is defined to NULL in non-AMD configs:
>
> drivers/platform/x86/amd/hsmp/plat.c: In function 'init_platform_device':
> drivers/platform/x86/amd/hsmp/plat.c:165:68: error: dereferencing 'void *' pointer [-Werror]
> 165 | sock->root = node_to_amd_nb(i)->root;
> | ^~
> drivers/platform/x86/amd/hsmp/plat.c:165:68: error: request for member 'root' in something not a structure or union
>
> Change the definition to something that builds. This does introduce a
> NULL pointer dereference but the code is never called since the driver
> won't probe successfully.
I don't like this very wording because what the code very much does is
NULL check on node_to_amd_nb() which leads to immediate failure of
.probe(). (We don't call other deferences after a NULL check "NULL pointer
dereference" either so none is introduced by this patch, IMO.)
With that fixed,
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@xxxxxxxxxxxxxxx>
--
i.
> Fixes: 7d3135d16356 ("platform/x86/amd/hsmp: Create separate ACPI, plat and common drivers")
> Signed-off-by: Arnd Bergmann <arnd@xxxxxxxx>
> ---
> arch/x86/include/asm/amd_nb.h | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/include/asm/amd_nb.h b/arch/x86/include/asm/amd_nb.h
> index 6f3b6aef47ba..d0caac26533f 100644
> --- a/arch/x86/include/asm/amd_nb.h
> +++ b/arch/x86/include/asm/amd_nb.h
> @@ -116,7 +116,10 @@ static inline bool amd_gart_present(void)
>
> #define amd_nb_num(x) 0
> #define amd_nb_has_feature(x) false
> -#define node_to_amd_nb(x) NULL
> +static inline struct amd_northbridge *node_to_amd_nb(int node)
> +{
> + return NULL;
> +}
> #define amd_gart_present(x) false
>
> #endif
>