Skip to content

Commit 0e2cebd

Browse files
shravankumarrij-intel
authored andcommitted
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: 423c336 ("platform/mellanox: mlxbf-pmc: Add support for BlueField-3") Signed-off-by: Shravan Kumar Ramani <[email protected]> Reviewed-by: David Thompson <[email protected]> Link: https://lore.kernel.org/r/2ee618c59976bcf1379d5ddce2fc60ab5014b3a9.1751380187.git.shravankr@nvidia.com [ij: split kstrbool() change to own commit.] Reviewed-by: Ilpo Järvinen <[email protected]> Signed-off-by: Ilpo Järvinen <[email protected]>
1 parent f8c1311 commit 0e2cebd

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

drivers/platform/mellanox/mlxbf-pmc.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1890,13 +1890,14 @@ static ssize_t mlxbf_pmc_enable_store(struct device *dev,
18901890
{
18911891
struct mlxbf_pmc_attribute *attr_enable = container_of(
18921892
attr, struct mlxbf_pmc_attribute, dev_attr);
1893-
unsigned int en, blk_num;
1893+
unsigned int blk_num;
18941894
u32 word;
18951895
int err;
1896+
bool en;
18961897

18971898
blk_num = attr_enable->nr;
18981899

1899-
err = kstrtouint(buf, 0, &en);
1900+
err = kstrtobool(buf, &en);
19001901
if (err < 0)
19011902
return err;
19021903

@@ -1916,14 +1917,11 @@ static ssize_t mlxbf_pmc_enable_store(struct device *dev,
19161917
MLXBF_PMC_CRSPACE_PERFMON_CTL(pmc->block[blk_num].counters),
19171918
MLXBF_PMC_WRITE_REG_32, word);
19181919
} else {
1919-
if (en && en != 1)
1920-
return -EINVAL;
1921-
19221920
err = mlxbf_pmc_config_l3_counters(blk_num, false, !!en);
19231921
if (err)
19241922
return err;
19251923

1926-
if (en == 1) {
1924+
if (en) {
19271925
err = mlxbf_pmc_config_l3_counters(blk_num, true, false);
19281926
if (err)
19291927
return err;

0 commit comments

Comments
 (0)