Fix below warning caused by smatch by using array_index_nospec() to clamp the index within the range. "warn: potential spectre issue 'plat_dev.sock' [r] (local cap)" Signed-off-by: Suma Hegde <suma.hegde@xxxxxxx> Reviewed-by: Naveen Krishna Chatradhi <naveenkrishna.chatradhi@xxxxxxx> --- drivers/platform/x86/amd/hsmp/acpi.c | 3 +++ drivers/platform/x86/amd/hsmp/plat.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/drivers/platform/x86/amd/hsmp/acpi.c b/drivers/platform/x86/amd/hsmp/acpi.c index 087cb360814a..f6d990fe0cb1 100644 --- a/drivers/platform/x86/amd/hsmp/acpi.c +++ b/drivers/platform/x86/amd/hsmp/acpi.c @@ -14,6 +14,7 @@ #include <linux/acpi.h> #include <asm/amd_hsmp.h> #include <asm/amd_nb.h> +#include <linux/nospec.h> #include <linux/platform_device.h> #define DRIVER_NAME "amd_hsmp" @@ -267,6 +268,8 @@ static int init_acpi(struct device *dev) if (sock_ind >= plat_dev.num_sockets) return -EINVAL; + sock_ind = array_index_nospec(sock_ind, plat_dev.num_sockets); + ret = hsmp_parse_acpi_table(dev, sock_ind); if (ret) { dev_err(dev, "Failed to parse ACPI table\n"); diff --git a/drivers/platform/x86/amd/hsmp/plat.c b/drivers/platform/x86/amd/hsmp/plat.c index da4ddb6e9819..04d1da455257 100644 --- a/drivers/platform/x86/amd/hsmp/plat.c +++ b/drivers/platform/x86/amd/hsmp/plat.c @@ -15,6 +15,7 @@ #include <asm/amd_nb.h> #include <linux/module.h> #include <linux/pci.h> +#include <linux/nospec.h> #include <linux/platform_device.h> #define DRIVER_NAME "amd_hsmp" @@ -75,6 +76,8 @@ static ssize_t hsmp_metric_tbl_read(struct file *filp, struct kobject *kobj, if (sock_ind >= plat_dev.num_sockets) return -EINVAL; + sock_ind = array_index_nospec(sock_ind, plat_dev.num_sockets); + sock = &plat_dev.sock[sock_ind]; if (!sock) return -EINVAL; -- 2.25.1