[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <13de226d679511149cc1515c423461eca763f257.1751286845.git.shravankr@nvidia.com>
Date: Mon, 30 Jun 2025 09:26:57 -0400
From: Shravan Kumar Ramani <shravankr@...dia.com>
To: Ilpo Jarvinen <ilpo.jarvinen@...ux.intel.com>, Vadim Pasternak
<vadimp@...dia.com>, David Thompson <davthompson@...dia.com>
CC: Shravan Kumar Ramani <shravankr@...dia.com>,
<platform-driver-x86@...r.kernel.org>, <linux-kernel@...r.kernel.org>
Subject: [PATCH v3 2/2] platform/mellanox: mlxbf-pmc: Validate event/enable input
Before programming the event info, validate the event number received as input
by checking if it exists in the event_list. Also fix a typo in the comment for
mlxbf_pmc_get_event_name() to correctly mention that it returns the event name
when taking the event number as input, and not the other way round. For setting
the enable value, the input should be 0 or 1 only. Use kstrtobool() in place of
kstrtouint() in mlxbf_pmc_enable_store() to accept only valid input.
Fixes: 423c3361855c ("platform/mellanox: mlxbf-pmc: Add support for BlueField-3")
Signed-off-by: Shravan Kumar Ramani <shravankr@...dia.com>
Reviewed-by: David Thompson <davthompson@...dia.com>
---
drivers/platform/mellanox/mlxbf-pmc.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/drivers/platform/mellanox/mlxbf-pmc.c b/drivers/platform/mellanox/mlxbf-pmc.c
index 16cc909aecab..baf3f60e66ed 100644
--- a/drivers/platform/mellanox/mlxbf-pmc.c
+++ b/drivers/platform/mellanox/mlxbf-pmc.c
@@ -1227,7 +1227,7 @@ static int mlxbf_pmc_get_event_num(const char *blk, char *evt)
return -ENODEV;
}
-/* Get the event number given the name */
+/* Get the event name given the number */
static char *mlxbf_pmc_get_event_name(const char *blk, u32 evt)
{
const struct mlxbf_pmc_events *events;
@@ -1804,6 +1804,9 @@ static ssize_t mlxbf_pmc_event_store(struct device *dev,
err = kstrtouint(buf, 0, &evt_num);
if (err < 0)
return err;
+
+ if (!mlxbf_pmc_get_event_name(pmc->block_name[blk_num], evt_num))
+ return -EINVAL;
}
if (strstr(pmc->block_name[blk_num], "l3cache"))
@@ -1884,13 +1887,14 @@ static ssize_t mlxbf_pmc_enable_store(struct device *dev,
{
struct mlxbf_pmc_attribute *attr_enable = container_of(
attr, struct mlxbf_pmc_attribute, dev_attr);
- unsigned int en, blk_num;
+ unsigned int blk_num;
u32 word;
int err;
+ bool en;
blk_num = attr_enable->nr;
- err = kstrtouint(buf, 0, &en);
+ err = kstrtobool(buf, &en);
if (err < 0)
return err;
@@ -1910,14 +1914,11 @@ static ssize_t mlxbf_pmc_enable_store(struct device *dev,
MLXBF_PMC_CRSPACE_PERFMON_CTL(pmc->block[blk_num].counters),
MLXBF_PMC_WRITE_REG_32, word);
} else {
- if (en && en != 1)
- return -EINVAL;
-
err = mlxbf_pmc_config_l3_counters(blk_num, false, !!en);
if (err)
return err;
- if (en == 1) {
+ if (en) {
err = mlxbf_pmc_config_l3_counters(blk_num, true, false);
if (err)
return err;
--
2.43.2
Powered by blists - more mailing lists