[PATCH v3 2/2] x86/apic: Replace deprecated simple_strtol() with sscanf() in x86_fwspec_is_hpet()

From: Habil Eren Türker

Date: Tue Oct 06 2026 - 15:34:55 EST


The simple_strtol() function is deprecated because it explicitly ignores
overflows. Replace it with the sscanf for proper check
in x86_fwspec_is_hpet(). Also add early returns.

It was detected while running a static analysis on the use of
simple_strtol() in the kernel.

Reported-by: kernel test robot <lkp@xxxxxxxxx>
Closes: https://lore.kernel.org/oe-kbuild-all/202610061159.7E9WkD7I-lkp@xxxxxxxxx/
Closes: https://lore.kernel.org/oe-kbuild-all/202610061356.8VHVO1CY-lkp@xxxxxxxxx/
Signed-off-by: Habil Eren Türker <habilerenturker@xxxxxxxxxxx>
---
arch/x86/kernel/apic/vector.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/arch/x86/kernel/apic/vector.c b/arch/x86/kernel/apic/vector.c
index 1a30b47c5..99f74e447 100644
--- a/arch/x86/kernel/apic/vector.c
+++ b/arch/x86/kernel/apic/vector.c
@@ -685,14 +685,21 @@ int x86_fwspec_is_ioapic(struct irq_fwspec *fwspec)

int x86_fwspec_is_hpet(struct irq_fwspec *fwspec)
{
+ const char *fwname;
+ unsigned int val;
+
if (fwspec->param_count != 1)
return 0;

- if (is_fwnode_irqchip(fwspec->fwnode)) {
- const char *fwname = fwnode_get_name(fwspec->fwnode);
- return fwname && !strncmp(fwname, "HPET-MSI-", 9) &&
- simple_strtol(fwname+9, NULL, 10) == fwspec->param[0];
- }
+ if (!is_fwnode_irqchip(fwspec->fwnode))
+ return 0;
+
+ fwname = fwnode_get_name(fwspec->fwnode);
+
+ if (fwname && sscanf(fwname, "HPET-MSI-%u", &val) == 1 &&
+ val == fwspec->param[0])
+ return 1;
+
return 0;
}

--
2.47.3