platform/mellanox: mlxbf-pmc: Use kstrtobool() to check 0/1 input

For setting the enable value, the input should be 0 or 1 only. Use
kstrtobool() in place of kstrtoint() in mlxbf_pmc_enable_store() to
accept only valid input.

Fixes: 423c336185 ("platform/mellanox: mlxbf-pmc: Add support for BlueField-3")
Signed-off-by: Shravan Kumar Ramani <shravankr@nvidia.com>
Reviewed-by: David Thompson <davthompson@nvidia.com>
Link: https://lore.kernel.org/r/2ee618c59976bcf1379d5ddce2fc60ab5014b3a9.1751380187.git.shravankr@nvidia.com
[ij: split kstrbool() change to own commit.]
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
This commit is contained in:
Shravan Kumar Ramani 2025-07-02 06:09:02 -04:00 committed by Ilpo Järvinen
parent f8c1311769
commit 0e2cebd723
No known key found for this signature in database
GPG key ID: 59AC4F6153E5CE31

View file

@ -1890,13 +1890,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;
@ -1916,14 +1917,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;