Skip to content

Commit 44e6ca8

Browse files
shravankumarrij-intel
authored andcommitted
platform/mellanox: mlxbf-pmc: Remove newline char from event name input
Since the input string passed via the command line appends a newline char, it needs to be removed before comparison with the event_list. Fixes: 1a218d3 ("platform/mellanox: mlxbf-pmc: Add Mellanox BlueField PMC driver") Signed-off-by: Shravan Kumar Ramani <[email protected]> Reviewed-by: David Thompson <[email protected]> Link: https://lore.kernel.org/r/4978c18e33313b48fa2ae7f3aa6dbcfce40877e4.1751380187.git.shravankr@nvidia.com Reviewed-by: Ilpo Järvinen <[email protected]> Signed-off-by: Ilpo Järvinen <[email protected]>
1 parent d4e8378 commit 44e6ca8

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

drivers/platform/mellanox/mlxbf-pmc.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/hwmon.h>
1616
#include <linux/platform_device.h>
1717
#include <linux/string.h>
18+
#include <linux/string_helpers.h>
1819
#include <uapi/linux/psci.h>
1920

2021
#define MLXBF_PMC_WRITE_REG_32 0x82000009
@@ -1784,15 +1785,22 @@ static ssize_t mlxbf_pmc_event_store(struct device *dev,
17841785
attr, struct mlxbf_pmc_attribute, dev_attr);
17851786
unsigned int blk_num, cnt_num;
17861787
bool is_l3 = false;
1788+
char *evt_name;
17871789
int evt_num;
17881790
int err;
17891791

17901792
blk_num = attr_event->nr;
17911793
cnt_num = attr_event->index;
17921794

17931795
if (isalpha(buf[0])) {
1796+
/* Remove the trailing newline character if present */
1797+
evt_name = kstrdup_and_replace(buf, '\n', '\0', GFP_KERNEL);
1798+
if (!evt_name)
1799+
return -ENOMEM;
1800+
17941801
evt_num = mlxbf_pmc_get_event_num(pmc->block_name[blk_num],
1795-
buf);
1802+
evt_name);
1803+
kfree(evt_name);
17961804
if (evt_num < 0)
17971805
return -EINVAL;
17981806
} else {

0 commit comments

Comments
 (0)