Re: [PATCH net-next 4/7] net: hibmcge: Add register dump supported in this module
From: Jijie Shao
Date: Thu Oct 24 2024 - 00:03:04 EST
on 2024/10/23 21:42, Jijie Shao wrote:
+#define HBG_REG_NAEM_MAX_LEN 24
+#define HBG_REG_TYPE_MAX_LEN 8
......
+
+struct hbg_reg_offset_name_map {
+ u32 reg_offset;
+ char name[HBG_REG_NAEM_MAX_LEN];
+};
+
+struct hbg_reg_type_info {
+ char name[HBG_REG_TYPE_MAX_LEN];
+ u32 offset_base;
+ const struct hbg_reg_offset_name_map *reg_maps;
+ u32 reg_num;
+};
+
+struct hbg_reg_info {
+ char name[HBG_REG_NAEM_MAX_LEN + HBG_REG_TYPE_MAX_LEN];
+ u32 offset;
+ u32 val;
......
+
+static u32 hbg_get_reg_info(struct hbg_priv *priv,
+ const struct hbg_reg_type_info *type_info,
+ const struct hbg_reg_offset_name_map *reg_map,
+ struct hbg_reg_info *info)
+{
+ info->val = hbg_reg_read(priv, reg_map->reg_offset);
+ info->offset = reg_map->reg_offset - type_info->offset_base;
+ snprintf(info->name, sizeof(info->name),
+ "[%s] %s", type_info->name, reg_map->name);
+
In addition, there are compilation warning here:
../drivers/net/ethernet/hisilicon/hibmcge/hbg_ethtool.c: In function ‘hbg_ethtool_get_regs’:
../drivers/net/ethernet/hisilicon/hibmcge/hbg_ethtool.c:322:20: warning: ‘%s’ directive output may be truncated writing up to 127 bytes into a region of size 31 [-Wformat-truncation=]
322 | "[%s] %s", type_info->name, reg_map->name);
| ^~
In function ‘hbg_get_reg_info’,
inlined from ‘hbg_ethtool_get_regs’ at ../drivers/net/ethernet/hisilicon/hibmcge/hbg_ethtool.c:338:14:
../drivers/net/ethernet/hisilicon/hibmcge/hbg_ethtool.c:321:9: note: ‘snprintf’ output between 4 and 154 bytes into a destination of size 32
321 | snprintf(info->name, sizeof(info->name),
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
322 | "[%s] %s", type_info->name, reg_map->name);
But in fact, sizeof(info->name) is (24+8), type_info->name length is 8, and reg_map->name length is 24.
I understand that it should be fine to use here.
Thanks,
Jijie Shao