net: hns3: There are some cleanup for the HNS3 ethernet driver
Subsystems (4)
v3 cover net: hns3: There are some cleanup for the HNS3 ethernet driver
There are some cleanup for the HNS3 ethernet driver.
Hao Chen (1):
net: hns3: fix strncpy() not using dest-buf length as length issue
Jian Shen (1):
net: hns3: refine the tcam key convert handle
Peiyang Wang (1):
net: hns3: clear hns unused parameter alarm
drivers/net/ethernet/hisilicon/hns3/hnae3.h | 3 +- .../hns3/hns3_common/hclge_comm_rss.c | 3 +- .../hns3/hns3_common/hclge_comm_rss.h | 3 +- .../ethernet/hisilicon/hns3/hns3_debugfs.c | 36 ++++++++++---- .../net/ethernet/hisilicon/hns3/hns3_enet.c | 2 +- .../ethernet/hisilicon/hns3/hns3_ethtool.c | 7 ++- .../hisilicon/hns3/hns3pf/hclge_debugfs.c | 29 ++++++++++-- .../hisilicon/hns3/hns3pf/hclge_main.c | 47 ++++++++----------- .../hisilicon/hns3/hns3pf/hclge_main.h | 11 ++--- .../hisilicon/hns3/hns3vf/hclgevf_main.c | 14 ++---- 10 files changed, 84 insertions(+), 71 deletions(-)
Signature · 1 line
2.30.0
PATCH v3 1/3 net: hns3: refine the tcam key convert handle
From: Jian Shen <[email protected]>
The result of expression '(k ^ ~v) & k' is exactly the same with 'k & v', so simplify it.
(k ^ ~v) & k == k & v
The truth table (in non table form):
k == 0, v == 0:
(k ^ ~v) & k == (0 ^ ~0) & 0 == (0 ^ 1) & 0 == 1 & 0 == 0 k & v == 0 & 0 == 0
k == 0, v == 1:
(k ^ ~v) & k == (0 ^ ~1) & 0 == (0 ^ 0) & 0 == 1 & 0 == 0 k & v == 0 & 1 == 0
k == 1, v == 0:
(k ^ ~v) & k == (1 ^ ~0) & 1 == (1 ^ 1) & 1 == 0 & 1 == 0 k & v == 1 & 0 == 0
k == 1, v == 1:
(k ^ ~v) & k == (1 ^ ~1) & 1 == (1 ^ 0) & 1 == 1 & 1 == 1 k & v == 1 & 1 == 1
---
ChangeLog:v1->v2:
Fixed the comment description error and added the truth table in the comment.
suggested by Simon Horman.
--- .../net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h +3 -8
@@ -835,15 +835,10 @@ struct hclge_vf_vlan_cfg {* Then for input key(k) and mask(v), we can calculate the value by * the formulae: * x = (~k) & v -* y = (k ^ ~v) & k +* y = k & v */ -#define calc_x (x, k, v) (x = ~(k) & (v)) -#define calc_y (y, k, v) \ - do { \ - const typeof(k) _k_ = (k); \ - const typeof(v) _v_ = (v); \ - (y) = (_k_ ^ ~_v_) & (_k_); \ - } while (0) +#define calc_x (x, k, v) ((x) = ~(k) & (v)) +#define calc_y (y, k, v) ((y) = (k) & (v))#define HCLGE_MAC_STATS_FIELD_OFF (f) (offsetof(struct hclge_mac_stats, f))#define HCLGE_STATS_READ (p, offset) (*(u64 *)((u8 *)(p) + (offset)))
Signature · 1 line
2.30.0
PATCH v3 2/3 net: hns3: fix strncpy() not using dest-buf length as length issue
In reply to Hao LanFrom: Hao Chen <[email protected]>
Now, strncpy() in hns3_dbg_fill_content() use src-length as copy-length, it may result in dest-buf overflow.
This patch is to fix intel compile warning for csky-linux-gcc (GCC) 12.1.0 compiler.
The warning reports as below:
hclge_debugfs.c:92:25: warning: 'strncpy' specified bound depends on the length of the source argument [-Wstringop-truncation]
strncpy(pos, items[i].name, strlen(items[i].name));
hclge_debugfs.c:90:25: warning: 'strncpy' output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation]
strncpy(pos, result[i], strlen(result[i]));
strncpy() use src-length as copy-length, it may result in dest-buf overflow.
So,this patch add some values check to avoid this issue.
---
ChangeLog:
v2-v3:
Use strscpy instead of strncpy
suggested by Paolo Abeni.v1->v2:
Use strcpy substitutes for memcpy
suggested by Simon Horman.
--- .../ethernet/hisilicon/hns3/hns3_debugfs.c | 31 ++++++++++++++----- .../hisilicon/hns3/hns3pf/hclge_debugfs.c | 29 ++++++++++++++--- 2 files changed, 48 insertions(+), 12 deletions(-)
drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c +24 -7
@@ -438,19 +438,36 @@ static void hns3_dbg_fill_content(char *content, u16 len,const struct hns3_dbg_item *items, const char **result, u16 size) { +#define HNS3_DBG_LINE_END_LEN 2 char *pos = content; +u16 item_len;u16 i; +if (!len) { +return ; + }else if (len <=HNS3_DBG_LINE_END_LEN ) { + *pos++ ='\0' ; +return ; + } +memset (content,' ' , len); -for (i =0 ; i < size; i++) { -if (result) -strncpy (pos, result[i],strlen (result[i])); -else -strncpy (pos, items[i].name,strlen (items[i].name)); + len -=HNS3_DBG_LINE_END_LEN ; - pos +=strlen (items[i].name) + items[i].interval; +for (i =0 ; i < size; i++) { + item_len =strlen (items[i].name) + items[i].interval; +if (len < item_len) +break ; + +if (result) { +if (item_len <strlen (result[i])) +break ; +strscpy (pos, result[i],strlen (result[i])); + }else { +strscpy (pos, items[i].name,strlen (items[i].name)); + } + pos += item_len; + len -= item_len; } - *pos++ ='\n' ; *pos++ ='\0' ; }
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c +24 -5
@@ -88,16 +88,35 @@ static void hclge_dbg_fill_content(char *content, u16 len,const struct hclge_dbg_item *items, const char **result, u16 size) { +#define HCLGE_DBG_LINE_END_LEN 2 char *pos = content; +u16 item_len;u16 i; +if (!len) { +return ; + }else if (len <=HCLGE_DBG_LINE_END_LEN ) { + *pos++ ='\0' ; +return ; + } +memset (content,' ' , len); + len -=HCLGE_DBG_LINE_END_LEN ; +for (i =0 ; i < size; i++) { -if (result) -strncpy (pos, result[i],strlen (result[i])); -else -strncpy (pos, items[i].name,strlen (items[i].name)); - pos +=strlen (items[i].name) + items[i].interval; + item_len =strlen (items[i].name) + items[i].interval; +if (len < item_len) +break ; + +if (result) { +if (item_len <strlen (result[i])) +break ; +strscpy (pos, result[i],strlen (result[i])); + }else { +strscpy (pos, items[i].name,strlen (items[i].name)); + } + pos += item_len; + len -= item_len; } *pos++ ='\n' ; *pos++ ='\0' ;
Signature · 1 line
2.30.0
PATCH v3 3/3 net: hns3: clear hns unused parameter alarm
In reply to Hao LanFrom: Peiyang Wang <[email protected]>
Several functions in the hns3 driver have unused parameters. The compiler will warn about them when building with -Wunused-parameter option of hns3.
---
ChangeLog:v1->v2:
Delete topic-independent code
suggested by Simon Horman.
--- drivers/net/ethernet/hisilicon/hns3/hnae3.h | 3 +- .../hns3/hns3_common/hclge_comm_rss.c | 3 +- .../hns3/hns3_common/hclge_comm_rss.h | 3 +- .../ethernet/hisilicon/hns3/hns3_debugfs.c | 5 +- .../net/ethernet/hisilicon/hns3/hns3_enet.c | 2 +- .../ethernet/hisilicon/hns3/hns3_ethtool.c | 7 ++- .../hisilicon/hns3/hns3pf/hclge_main.c | 47 ++++++++----------- .../hisilicon/hns3/hns3vf/hclgevf_main.c | 14 ++---- 8 files changed, 33 insertions(+), 51 deletions(-)
drivers/net/ethernet/hisilicon/hns3/hnae3.h +1 -2
@@ -647,8 +647,7 @@ struct hnae3_ae_ops {int (*rm_mc_addr)(struct hnae3_handle *handle,const unsigned char *addr);void (*set_tso_stats)(struct hnae3_handle *handle,int enable); -void (*update_stats)(struct hnae3_handle *handle, -struct net_device_stats *net_stats); +void (*update_stats)(struct hnae3_handle *handle);void (*get_stats)(struct hnae3_handle *handle,u64 *data);void (*get_mac_stats)(struct hnae3_handle *handle,struct hns3_mac_stats *mac_stats);
drivers/net/ethernet/hisilicon/hns3/hns3_common/hclge_comm_rss.c +1 -2
@@ -305,8 +305,7 @@ int hclge_comm_set_rss_indir_table(struct hnae3_ae_dev *ae_dev,return 0 ; } -int hclge_comm_set_rss_input_tuple (struct hnae3_handle *nic, -struct hclge_comm_hw *hw,bool is_pf, +int hclge_comm_set_rss_input_tuple (struct hclge_comm_hw *hw,struct hclge_comm_rss_cfg *rss_cfg) {struct hclge_comm_rss_input_tuple_cmd *req;
drivers/net/ethernet/hisilicon/hns3/hns3_common/hclge_comm_rss.h +1 -2
@@ -112,8 +112,7 @@ int hclge_comm_init_rss_tuple_cmd(struct hclge_comm_rss_cfg *rss_cfg,struct hnae3_ae_dev *ae_dev, struct hclge_comm_rss_input_tuple_cmd *req);u64 hclge_comm_convert_rss_tuple (u8 tuple_sets); -int hclge_comm_set_rss_input_tuple (struct hnae3_handle *nic, -struct hclge_comm_hw *hw,bool is_pf, +int hclge_comm_set_rss_input_tuple (struct hclge_comm_hw *hw,struct hclge_comm_rss_cfg *rss_cfg);int hclge_comm_set_rss_indir_table (struct hnae3_ae_dev *ae_dev,struct hclge_comm_hw *hw,const u16 *indir);
drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c +2 -3
@@ -958,8 +958,7 @@ static const struct hns3_dbg_item tx_bd_info_items[] = { { "MSS_HW_CSUM", 0 }, }; -static void hns3_dump_tx_bd_info (struct hns3_nic_priv *priv, -struct hns3_desc *desc,char **result,int idx) +static void hns3_dump_tx_bd_info (struct hns3_desc *desc,char **result,int idx) {unsigned int j =0 ;
@@ -1008,7 +1007,7 @@ static int hns3_dbg_tx_bd_info(struct hns3_dbg_data *d, char *buf, int len)for (i =0 ; i < ring->desc_num; i++) { desc = &ring->desc[i]; -hns3_dump_tx_bd_info (priv, desc, result, i); +hns3_dump_tx_bd_info (desc, result, i);hns3_dbg_fill_content (content,sizeof (content), tx_bd_info_items, (const char **)result,ARRAY_SIZE (tx_bd_info_items));
drivers/net/ethernet/hisilicon/hns3/hns3_enet.c +1 -1
@@ -2538,7 +2538,7 @@ static void hns3_nic_get_stats64(struct net_device *netdev,if (test_bit (HNS3_NIC_STATE_DOWN , &priv->state))return ; - handle->ae_algo->ops->update_stats (handle, &netdev->stats); + handle->ae_algo->ops->update_stats (handle);memset (&ring_total_stats,0 ,sizeof (ring_total_stats));for (idx =0 ; idx < queue_num; idx++) {
drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c +3 -4
@@ -228,7 +228,7 @@ static u32 hns3_lb_check_rx_ring(struct hns3_nic_priv *priv, u32 budget) }static void hns3_lb_clear_tx_ring (struct hns3_nic_priv *priv,u32 start_ringid, -u32 end_ringid,u32 budget) +u32 end_ringid) {u32 i;
@@ -295,8 +295,7 @@ static int hns3_lp_run_test(struct net_device *ndev, enum hnae3_loop mode) out:hns3_lb_clear_tx_ring (priv,HNS3_NIC_LB_TEST_RING_ID , -HNS3_NIC_LB_TEST_RING_ID , -HNS3_NIC_LB_TEST_PKT_NUM ); +HNS3_NIC_LB_TEST_RING_ID );kfree_skb (skb);return ret_val;
@@ -618,7 +617,7 @@ static void hns3_get_stats(struct net_device *netdev,return ; } - h->ae_algo->ops->update_stats (h, &netdev->stats); + h->ae_algo->ops->update_stats (h);/* get per-queue stats */ p =hns3_get_stats_tqps (h, p);
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c +19 -28
129 lines not on this page · raw message
drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c +5 -9
@@ -121,8 +121,7 @@ static struct hclgevf_dev *hclgevf_ae_get_hdev(struct hnae3_handle *handle) return container_of(handle, struct hclgevf_dev, nic); } -static void hclgevf_update_stats (struct hnae3_handle *handle, -struct net_device_stats *net_stats) +static void hclgevf_update_stats (struct hnae3_handle *handle) {struct hclgevf_dev *hdev =hclgevf_ae_get_hdev (handle);int status;
@@ -1645,8 +1644,7 @@ static void hclgevf_reset(struct hclgevf_dev *hdev)hclgevf_reset_err_handle (hdev); } -static enum hnae3_reset_type hclgevf_get_reset_level (struct hclgevf_dev *hdev, -unsigned long *addr) +static enum hnae3_reset_type hclgevf_get_reset_level (unsigned long *addr) {enum hnae3_reset_type rst_level =HNAE3_NONE_RESET ;
@@ -1685,8 +1683,7 @@ static void hclgevf_reset_event(struct pci_dev *pdev,if (hdev->default_reset_request) hdev->reset_level = -hclgevf_get_reset_level (hdev, - &hdev->default_reset_request); +hclgevf_get_reset_level (&hdev->default_reset_request);else hdev->reset_level =HNAE3_VF_FUNC_RESET ;
@@ -1828,7 +1825,7 @@ static void hclgevf_reset_service_task(struct hclgevf_dev *hdev) hdev->last_reset_time = jiffies; hdev->reset_type = -hclgevf_get_reset_level (hdev, &hdev->reset_pending); +hclgevf_get_reset_level (&hdev->reset_pending);if (hdev->reset_type !=HNAE3_NONE_RESET )hclgevf_reset (hdev); } else if (test_and_clear_bit(HCLGEVF_RESET_REQUESTED,
@@ -2160,8 +2157,7 @@ static int hclgevf_rss_init_hw(struct hclgevf_dev *hdev)if (ret)return ret; - ret =hclge_comm_set_rss_input_tuple (&hdev->nic, &hdev->hw.hw, - false, rss_cfg); + ret =hclge_comm_set_rss_input_tuple (&hdev->hw.hw, rss_cfg);if (ret)return ret; }
Signature · 1 line
2.30.0
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Quoted 9 lines · On Wed, 21 Jun 2023 20:33:06 +0800 you wrote:
There are some cleanup for the HNS3 ethernet driver.
Hao Chen (1):
net: hns3: fixstrncpy()not using dest-buf length as length issueJian Shen (1):
net: hns3: refine the tcam key convert handle[...]
Here is the summary with links:
- [net-next,v3,1/3] net: hns3: refine the tcam key convert handle
https://git.kernel.org/netdev/net-next/c/9b476494da1a - [net-next,v3,2/3] net: hns3: fix strncpy() not using dest-buf length as length issue https://git.kernel.org/netdev/net-next/c/1cf3d5567f27 - [net-next,v3,3/3] net: hns3: clear hns unused parameter alarm https://git.kernel.org/netdev/net-next/c/ed1c6f35b73e
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html