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@nvidia.com>
Reviewed-by: David Thompson <davthomspson@nvidia.com>
---
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
On Wed, 18 Jun 2025, Shravan Kumar Ramani wrote:
> 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.
Please include () after any function name (don't forget those in the
shortlog).
> Fixes: 1a218d312e65 ("platform/mellanox: mlxbf-pmc: Add Mellanox BlueField PMC driver")
> Signed-off-by: Shravan Kumar Ramani <shravankr@nvidia.com>
> Reviewed-by: David Thompson <davthomspson@nvidia.com>
> ---
> 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)))
So if there's extra garbage behind the input, it will also match
spuriously? So store the len and reduce it if there's a trailing newline
to make it more robust?
> return events[i].evt_num;
> }
>
>
--
i.
© 2016 - 2026 Red Hat, Inc.