[PATCH v2 1/2] platform/mellanox: mlxbf-pmc: Replace strcmp with strncmp

From: Shravan Kumar Ramani
Date: Wed Jun 18 2025 - 07:41:32 EST


Since the input string passed via the command line appends a newline char,
comparison using strcmp is not correct. Use the string length of the
event_list entries to match the string using strncmp instead.

Fixes: 1a218d312e65 ("platform/mellanox: mlxbf-pmc: Add Mellanox BlueField PMC driver")
Signed-off-by: Shravan Kumar Ramani <shravankr@xxxxxxxxxx>
Reviewed-by: David Thompson <davthomspson@xxxxxxxxxx>
---
drivers/platform/mellanox/mlxbf-pmc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/platform/mellanox/mlxbf-pmc.c b/drivers/platform/mellanox/mlxbf-pmc.c
index 900069eb186e..366c0cba447f 100644
--- a/drivers/platform/mellanox/mlxbf-pmc.c
+++ b/drivers/platform/mellanox/mlxbf-pmc.c
@@ -1215,7 +1215,7 @@ static int mlxbf_pmc_get_event_num(const char *blk, const char *evt)
return -EINVAL;

for (i = 0; i < size; ++i) {
- if (!strcmp(evt, events[i].evt_name))
+ if (!strncmp(evt, events[i].evt_name, strlen(events[i].evt_name)))
return events[i].evt_num;
}

--
2.30.1