sonic-buildimage/platform/mellanox/non-upstream-patches/patches/0216-UBUNTU-SAUCE-mlxbf_pmc-Fix-references-to-sprintf.patch

70 lines
2.2 KiB
Diff
Raw Normal View History

From 597a665f88fd16c595dd804c7567ccd5aab34ad9 Mon Sep 17 00:00:00 2001
From: Jitendra Lanka <jlanka@nvidia.com>
Date: Tue, 16 Aug 2022 16:18:39 -0400
Subject: [PATCH backport 5.10 17/63] UBUNTU: SAUCE: mlxbf_pmc: Fix references
to sprintf
BugLink: https://bugs.launchpad.net/bugs/1986849
Replace sprintf with snprintf with a defined upper boundary of
PAGE_SIZE for sysfs store/show functions and max array size defined
otherwise.
Change-Id: If586302684d60a435abc9f5aaf28b08de9b2df16
Signed-off-by: Jitendra Lanka <jlanka@nvidia.com>
Signed-off-by: Ike Panhc <ike.pan@canonical.com>
---
drivers/platform/mellanox/mlxbf-pmc.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/drivers/platform/mellanox/mlxbf-pmc.c b/drivers/platform/mellanox/mlxbf-pmc.c
index a9debcdf9..3305d2a5d 100644
--- a/drivers/platform/mellanox/mlxbf-pmc.c
+++ b/drivers/platform/mellanox/mlxbf-pmc.c
@@ -681,7 +681,7 @@ static ssize_t mlxbf_counter_read(struct kobject *ko,
} else
return -EINVAL;
- return sprintf(buf, "0x%llx\n", value);
+ return snprintf(buf, PAGE_SIZE, "0x%llx\n", value);
}
/* Store function for "counter" sysfs files */
@@ -758,7 +758,7 @@ static ssize_t mlxbf_event_find(struct kobject *ko,
evt_name = mlxbf_pmc_get_event_name((char *)ko->name, evt_num);
- return sprintf(buf, "0x%llx: %s\n", evt_num, evt_name);
+ return snprintf(buf, PAGE_SIZE, "0x%llx: %s\n", evt_num, evt_name);
}
/* Store function for "event" sysfs files */
@@ -811,9 +811,12 @@ static ssize_t mlxbf_print_event_list(struct kobject *ko,
buf[0] = '\0';
while (events[i].evt_name != NULL) {
- size += sprintf(e_info, "%x: %s\n", events[i].evt_num,
- events[i].evt_name);
- if (size > PAGE_SIZE)
+ size += snprintf(e_info,
+ sizeof(e_info),
+ "%x: %s\n",
+ events[i].evt_num,
+ events[i].evt_name);
+ if (size >= PAGE_SIZE)
break;
strcat(buf, e_info);
ret = size;
@@ -840,7 +843,7 @@ static ssize_t mlxbf_show_counter_state(struct kobject *ko,
value = FIELD_GET(MLXBF_L3C_PERF_CNT_CFG__EN, perfcnt_cfg);
- return sprintf(buf, "%d\n", value);
+ return snprintf(buf, PAGE_SIZE, "%d\n", value);
}
/* Store function for "enable" sysfs files - only for l3cache */
--
2.20.1