lkml.org 
[lkml]   [2024]   [Feb]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH] platform/mellanox: mlxbf-pmc: fix signedness bugs
These need to be signed for the error handling to work.  The
mlxbf_pmc_get_event_num() function returns int so int type is correct.

Fixes: 1ae9ffd303c2 ("platform/mellanox: mlxbf-pmc: Cleanup signed/unsigned mix-up")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
The code in mlxbf_pmc_valid_range() has a check for negatives but that
has a signedness bug too. Fortunately "(u32)-EINVAL + 8" will not
result in an integer overflow so the offset is treated as invalid.

drivers/platform/mellanox/mlxbf-pmc.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/platform/mellanox/mlxbf-pmc.c b/drivers/platform/mellanox/mlxbf-pmc.c
index 250405bb59a7..bc91423c96b9 100644
--- a/drivers/platform/mellanox/mlxbf-pmc.c
+++ b/drivers/platform/mellanox/mlxbf-pmc.c
@@ -1496,8 +1496,9 @@ static ssize_t mlxbf_pmc_counter_show(struct device *dev,
{
struct mlxbf_pmc_attribute *attr_counter = container_of(
attr, struct mlxbf_pmc_attribute, dev_attr);
- unsigned int blk_num, cnt_num, offset;
+ unsigned int blk_num, cnt_num;
bool is_l3 = false;
+ int offset;
u64 value;

blk_num = attr_counter->nr;
@@ -1530,9 +1531,10 @@ static ssize_t mlxbf_pmc_counter_store(struct device *dev,
{
struct mlxbf_pmc_attribute *attr_counter = container_of(
attr, struct mlxbf_pmc_attribute, dev_attr);
- unsigned int blk_num, cnt_num, offset, data;
+ unsigned int blk_num, cnt_num, data;
bool is_l3 = false;
u64 evt_num;
+ int offset;
int err;

blk_num = attr_counter->nr;
@@ -1612,8 +1614,9 @@ static ssize_t mlxbf_pmc_event_store(struct device *dev,
{
struct mlxbf_pmc_attribute *attr_event = container_of(
attr, struct mlxbf_pmc_attribute, dev_attr);
- unsigned int blk_num, cnt_num, evt_num;
+ unsigned int blk_num, cnt_num;
bool is_l3 = false;
+ int evt_num;
int err;

blk_num = attr_event->nr;
--
2.43.0

\
 
 \ /
  Last update: 2024-05-27 15:28    [W:0.077 / U:0.320 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site