[openwrt/openwrt] realtek: dsa: Build check size of drop counter names
LEDE Commits
lede-commits at lists.infradead.org
Mon Nov 24 08:43:08 PST 2025
robimarko pushed a commit to openwrt/openwrt.git, branch main:
https://git.openwrt.org/4dab2a94057513b8a013ff2fd90f213c3e6c6ed0
commit 4dab2a94057513b8a013ff2fd90f213c3e6c6ed0
Author: Sven Eckelmann <sven at narfation.org>
AuthorDate: Mon Nov 24 08:54:30 2025 +0100
realtek: dsa: Build check size of drop counter names
The commit 1cfd45ae0bad ("realtek: Add debugfs support for RTL9300") caused
previously an out of bounds access on the array holding the names of drop
counters (and incorrect names in the output) fur RTL839x because of a
missing comma. To avoid such situation in the future, calculate the size of
the array during compilation. And to ensure that this count matches the
actual number of counters in HW, compare this number during compile time
with the expected value.
Suggested-by: Hauke Mehrtens <hauke at hauke-m.de>
Signed-off-by: Sven Eckelmann <sven at narfation.org>
Link: https://github.com/openwrt/openwrt/pull/20905
Signed-off-by: Robert Marko <robimarko at gmail.com>
---
.../realtek/files-6.12/drivers/net/dsa/rtl83xx/debugfs.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/debugfs.c b/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/debugfs.c
index e95ffc5b0a..11420c4c4e 100644
--- a/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/debugfs.c
+++ b/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/debugfs.c
@@ -205,22 +205,26 @@ static ssize_t drop_counter_read(struct file *filp, char __user *buffer, size_t
case RTL8380_FAMILY_ID:
d = rtl838x_drop_cntr;
offset = RTL838X_STAT_PRVTE_DROP_COUNTERS;
- num = 40;
+ num = ARRAY_SIZE(rtl838x_drop_cntr);
+ BUILD_BUG_ON(num != 40);
break;
case RTL8390_FAMILY_ID:
d = rtl839x_drop_cntr;
offset = RTL839X_STAT_PRVTE_DROP_COUNTERS;
- num = 45;
+ num = ARRAY_SIZE(rtl839x_drop_cntr);
+ BUILD_BUG_ON(num != 45);
break;
case RTL9300_FAMILY_ID:
d = rtl930x_drop_cntr;
offset = RTL930X_STAT_PRVTE_DROP_COUNTERS;
- num = 85;
+ num = ARRAY_SIZE(rtl930x_drop_cntr);
+ BUILD_BUG_ON(num != 85);
break;
case RTL9310_FAMILY_ID:
d = rtl931x_drop_cntr;
offset = RTL931X_STAT_PRVTE_DROP_COUNTERS;
- num = 81;
+ num = ARRAY_SIZE(rtl931x_drop_cntr);
+ BUILD_BUG_ON(num != 81);
break;
}
More information about the lede-commits
mailing list