]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
platform/mellanox: mlxbf-pmc: Remove newline char from event name input
authorShravan Kumar Ramani <shravankr@nvidia.com>
Wed, 2 Jul 2025 10:09:01 +0000 (06:09 -0400)
committerIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Mon, 7 Jul 2025 12:53:23 +0000 (15:53 +0300)
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: 1a218d312e65 ("platform/mellanox: mlxbf-pmc: Add Mellanox BlueField PMC driver")
Signed-off-by: Shravan Kumar Ramani <shravankr@nvidia.com>
Reviewed-by: David Thompson <davthompson@nvidia.com>
Link: https://lore.kernel.org/r/4978c18e33313b48fa2ae7f3aa6dbcfce40877e4.1751380187.git.shravankr@nvidia.com
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
drivers/platform/mellanox/mlxbf-pmc.c

index a1c529f1ff1a4e72696ed0b7c3603fcfe8f625e8..2b692a76398e6909b1858916bca930c8f9366ed9 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/hwmon.h>
 #include <linux/platform_device.h>
 #include <linux/string.h>
+#include <linux/string_helpers.h>
 #include <uapi/linux/psci.h>
 
 #define MLXBF_PMC_WRITE_REG_32 0x82000009
@@ -1784,6 +1785,7 @@ static ssize_t mlxbf_pmc_event_store(struct device *dev,
                attr, struct mlxbf_pmc_attribute, dev_attr);
        unsigned int blk_num, cnt_num;
        bool is_l3 = false;
+       char *evt_name;
        int evt_num;
        int err;
 
@@ -1791,8 +1793,14 @@ static ssize_t mlxbf_pmc_event_store(struct device *dev,
        cnt_num = attr_event->index;
 
        if (isalpha(buf[0])) {
+               /* Remove the trailing newline character if present */
+               evt_name = kstrdup_and_replace(buf, '\n', '\0', GFP_KERNEL);
+               if (!evt_name)
+                       return -ENOMEM;
+
                evt_num = mlxbf_pmc_get_event_num(pmc->block_name[blk_num],
-                                                 buf);
+                                                 evt_name);
+               kfree(evt_name);
                if (evt_num < 0)
                        return -EINVAL;
        } else {