diff mbox series

[v4,8/9] platform/x86/amd/hsmp: Check num_sockets against MAX_AMD_SOCKETS

Message ID 20240105074618.1667898-9-suma.hegde@amd.com (mailing list archive)
State Superseded, archived
Headers show
Series Add ACPI probing support for HSMP | expand

Commit Message

Suma Hegde Jan. 5, 2024, 7:46 a.m. UTC
AMD supports connecting up to 8 AMD EPYCs in a system.
Hence, verify the num_sockets returned from amd_nb_num().
Also remove the WARN_ON() since the num_sockets is already verified.

Signed-off-by: Suma Hegde <suma.hegde@amd.com>
Reviewed-by: Naveen Krishna Chatradhi <nchatrad@amd.com>
---
Changes since v3:
New patch

 drivers/platform/x86/amd/hsmp.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

Comments

Ilpo Järvinen Jan. 5, 2024, 9:36 a.m. UTC | #1
On Fri, 5 Jan 2024, Suma Hegde wrote:

> AMD supports connecting up to 8 AMD EPYCs in a system.
> Hence, verify the num_sockets returned from amd_nb_num().
> Also remove the WARN_ON() since the num_sockets is already verified.
> 
> Signed-off-by: Suma Hegde <suma.hegde@amd.com>
> Reviewed-by: Naveen Krishna Chatradhi <nchatrad@amd.com>
> ---
> Changes since v3:
> New patch
> 
>  drivers/platform/x86/amd/hsmp.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/platform/x86/amd/hsmp.c b/drivers/platform/x86/amd/hsmp.c
> index 05255102e0a0..99bebb0ca5a9 100644
> --- a/drivers/platform/x86/amd/hsmp.c
> +++ b/drivers/platform/x86/amd/hsmp.c
> @@ -62,6 +62,8 @@
>  #define MSG_ARGOFF_STR		"MsgArgOffset"
>  #define MSG_RESPOFF_STR		"MsgRspOffset"
>  
> +#define MAX_AMD_SOCKETS 8
> +
>  struct hsmp_mbaddr_info {
>  	u32 base_addr;
>  	u32 msg_id_off;
> @@ -671,10 +673,6 @@ static int hsmp_create_non_acpi_sysfs_if(struct device *dev)
>  	struct attribute_group *attr_grp;
>  	u16 i;
>  
> -	/* String formatting is currently limited to u8 sockets */
> -	if (WARN_ON(plat_dev.num_sockets > U8_MAX))
> -		return -ERANGE;
> -
>  	hsmp_attr_grps = devm_kzalloc(dev, sizeof(struct attribute_group *) *
>  				      (plat_dev.num_sockets + 1), GFP_KERNEL);
>  	if (!hsmp_attr_grps)
> @@ -925,7 +923,7 @@ static int __init hsmp_plt_init(void)
>  	 * if we have N SMN/DF interfaces that ideally means N sockets
>  	 */
>  	plat_dev.num_sockets = amd_nb_num();
> -	if (plat_dev.num_sockets == 0)
> +	if (plat_dev.num_sockets == 0 || plat_dev.num_sockets > MAX_AMD_SOCKETS)
>  		return ret;
>  
>  	ret = platform_driver_register(&amd_hsmp_driver);
> 

Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
diff mbox series

Patch

diff --git a/drivers/platform/x86/amd/hsmp.c b/drivers/platform/x86/amd/hsmp.c
index 05255102e0a0..99bebb0ca5a9 100644
--- a/drivers/platform/x86/amd/hsmp.c
+++ b/drivers/platform/x86/amd/hsmp.c
@@ -62,6 +62,8 @@ 
 #define MSG_ARGOFF_STR		"MsgArgOffset"
 #define MSG_RESPOFF_STR		"MsgRspOffset"
 
+#define MAX_AMD_SOCKETS 8
+
 struct hsmp_mbaddr_info {
 	u32 base_addr;
 	u32 msg_id_off;
@@ -671,10 +673,6 @@  static int hsmp_create_non_acpi_sysfs_if(struct device *dev)
 	struct attribute_group *attr_grp;
 	u16 i;
 
-	/* String formatting is currently limited to u8 sockets */
-	if (WARN_ON(plat_dev.num_sockets > U8_MAX))
-		return -ERANGE;
-
 	hsmp_attr_grps = devm_kzalloc(dev, sizeof(struct attribute_group *) *
 				      (plat_dev.num_sockets + 1), GFP_KERNEL);
 	if (!hsmp_attr_grps)
@@ -925,7 +923,7 @@  static int __init hsmp_plt_init(void)
 	 * if we have N SMN/DF interfaces that ideally means N sockets
 	 */
 	plat_dev.num_sockets = amd_nb_num();
-	if (plat_dev.num_sockets == 0)
+	if (plat_dev.num_sockets == 0 || plat_dev.num_sockets > MAX_AMD_SOCKETS)
 		return ret;
 
 	ret = platform_driver_register(&amd_hsmp_driver);