]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
platform/mellanox: mlxbf-pmc: Use kstrtobool() to check 0/1 input
authorShravan Kumar Ramani <shravankr@nvidia.com>
Wed, 2 Jul 2025 10:09:02 +0000 (06:09 -0400)
committerIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Mon, 7 Jul 2025 12:53:28 +0000 (15:53 +0300)
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: 423c3361855c ("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>
drivers/platform/mellanox/mlxbf-pmc.c

index c654b4bf141f2c59233aed257a9de0c606f9d432..4776013e07649ba9da55c64ebdafc28946fe7257 100644 (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;