netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 0/2] There are a cleancode and a parameter check for hns3 driver
@ 2025-08-15 10:04 Jijie Shao
  2025-08-15 10:04 ` [PATCH net-next 1/2] net: hns3: add parameter check for tx_copybreak and tx_spare_buf_size Jijie Shao
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Jijie Shao @ 2025-08-15 10:04 UTC (permalink / raw)
  To: davem, edumazet, kuba, pabeni, andrew+netdev, horms
  Cc: shenjian15, liuyonglong, chenhao418, jonathan.cameron,
	salil.mehta, netdev, linux-kernel, shaojijie

This patchset includes:
 1. a parameter check omitted from fix code in net branch
   https://lore.kernel.org/all/20250723072900.GV2459@horms.kernel.org/
 2. a small clean code

Jijie Shao (2):
  net: hns3: add parameter check for tx_copybreak and tx_spare_buf_size
  net: hns3: change the function return type from int to bool

 .../ethernet/hisilicon/hns3/hns3_ethtool.c    | 33 +++++++++++++++++++
 .../hisilicon/hns3/hns3pf/hclge_main.c        |  4 +--
 2 files changed, 35 insertions(+), 2 deletions(-)

-- 
2.33.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH net-next 1/2] net: hns3: add parameter check for tx_copybreak and tx_spare_buf_size
  2025-08-15 10:04 [PATCH net-next 0/2] There are a cleancode and a parameter check for hns3 driver Jijie Shao
@ 2025-08-15 10:04 ` Jijie Shao
  2025-08-15 10:04 ` [PATCH net-next 2/2] net: hns3: change the function return type from int to bool Jijie Shao
  2025-08-20  3:11 ` [PATCH net-next 0/2] There are a cleancode and a parameter check for hns3 driver patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Jijie Shao @ 2025-08-15 10:04 UTC (permalink / raw)
  To: davem, edumazet, kuba, pabeni, andrew+netdev, horms
  Cc: shenjian15, liuyonglong, chenhao418, jonathan.cameron,
	salil.mehta, netdev, linux-kernel, shaojijie

Since the driver always enables tx bounce buffer,
there are minimum values for `copybreak` and `tx_spare_buf_size`.

This patch will check and reject configurations
with values smaller than these minimums.

Closes: https://lore.kernel.org/all/20250723072900.GV2459@horms.kernel.org/
Signed-off-by: Jijie Shao <shaojijie@huawei.com>
---
 .../ethernet/hisilicon/hns3/hns3_ethtool.c    | 33 +++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
index d5454e126c85..a752d0e3db3a 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
@@ -1927,6 +1927,31 @@ static int hns3_set_tx_spare_buf_size(struct net_device *netdev,
 	return ret;
 }
 
+static int hns3_check_tx_copybreak(struct net_device *netdev, u32 copybreak)
+{
+	struct hns3_nic_priv *priv = netdev_priv(netdev);
+
+	if (copybreak < priv->min_tx_copybreak) {
+		netdev_err(netdev, "tx copybreak %u should be no less than %u!\n",
+			   copybreak, priv->min_tx_copybreak);
+		return -EINVAL;
+	}
+	return 0;
+}
+
+static int hns3_check_tx_spare_buf_size(struct net_device *netdev, u32 buf_size)
+{
+	struct hns3_nic_priv *priv = netdev_priv(netdev);
+
+	if (buf_size < priv->min_tx_spare_buf_size) {
+		netdev_err(netdev,
+			   "tx spare buf size %u should be no less than %u!\n",
+			   buf_size, priv->min_tx_spare_buf_size);
+		return -EINVAL;
+	}
+	return 0;
+}
+
 static int hns3_set_tunable(struct net_device *netdev,
 			    const struct ethtool_tunable *tuna,
 			    const void *data)
@@ -1943,6 +1968,10 @@ static int hns3_set_tunable(struct net_device *netdev,
 
 	switch (tuna->id) {
 	case ETHTOOL_TX_COPYBREAK:
+		ret = hns3_check_tx_copybreak(netdev, *(u32 *)data);
+		if (ret)
+			return ret;
+
 		priv->tx_copybreak = *(u32 *)data;
 
 		for (i = 0; i < h->kinfo.num_tqps; i++)
@@ -1957,6 +1986,10 @@ static int hns3_set_tunable(struct net_device *netdev,
 
 		break;
 	case ETHTOOL_TX_COPYBREAK_BUF_SIZE:
+		ret = hns3_check_tx_spare_buf_size(netdev, *(u32 *)data);
+		if (ret)
+			return ret;
+
 		old_tx_spare_buf_size = h->kinfo.tx_spare_buf_size;
 		new_tx_spare_buf_size = *(u32 *)data;
 		netdev_info(netdev, "request to set tx spare buf size from %u to %u\n",
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH net-next 2/2] net: hns3: change the function return type from int to bool
  2025-08-15 10:04 [PATCH net-next 0/2] There are a cleancode and a parameter check for hns3 driver Jijie Shao
  2025-08-15 10:04 ` [PATCH net-next 1/2] net: hns3: add parameter check for tx_copybreak and tx_spare_buf_size Jijie Shao
@ 2025-08-15 10:04 ` Jijie Shao
  2025-08-20  3:11 ` [PATCH net-next 0/2] There are a cleancode and a parameter check for hns3 driver patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Jijie Shao @ 2025-08-15 10:04 UTC (permalink / raw)
  To: davem, edumazet, kuba, pabeni, andrew+netdev, horms
  Cc: shenjian15, liuyonglong, chenhao418, jonathan.cameron,
	salil.mehta, netdev, linux-kernel, shaojijie

hclge_only_alloc_priv_buff() only return true or false,
So, change the function return type from integer to boolean.

Signed-off-by: Jijie Shao <shaojijie@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index f209a05e2033..f5457ae0b64f 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -2182,8 +2182,8 @@ static bool hclge_drop_pfc_buf_till_fit(struct hclge_dev *hdev,
 	return hclge_is_rx_buf_ok(hdev, buf_alloc, rx_all);
 }
 
-static int hclge_only_alloc_priv_buff(struct hclge_dev *hdev,
-				      struct hclge_pkt_buf_alloc *buf_alloc)
+static bool hclge_only_alloc_priv_buff(struct hclge_dev *hdev,
+				       struct hclge_pkt_buf_alloc *buf_alloc)
 {
 #define COMPENSATE_BUFFER	0x3C00
 #define COMPENSATE_HALF_MPS_NUM	5
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next 0/2] There are a cleancode and a parameter check for hns3 driver
  2025-08-15 10:04 [PATCH net-next 0/2] There are a cleancode and a parameter check for hns3 driver Jijie Shao
  2025-08-15 10:04 ` [PATCH net-next 1/2] net: hns3: add parameter check for tx_copybreak and tx_spare_buf_size Jijie Shao
  2025-08-15 10:04 ` [PATCH net-next 2/2] net: hns3: change the function return type from int to bool Jijie Shao
@ 2025-08-20  3:11 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-08-20  3:11 UTC (permalink / raw)
  To: Jijie Shao
  Cc: davem, edumazet, kuba, pabeni, andrew+netdev, horms, shenjian15,
	liuyonglong, chenhao418, jonathan.cameron, salil.mehta, netdev,
	linux-kernel

Hello:

This series was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Fri, 15 Aug 2025 18:04:12 +0800 you wrote:
> This patchset includes:
>  1. a parameter check omitted from fix code in net branch
>    https://lore.kernel.org/all/20250723072900.GV2459@horms.kernel.org/
>  2. a small clean code
> 
> Jijie Shao (2):
>   net: hns3: add parameter check for tx_copybreak and tx_spare_buf_size
>   net: hns3: change the function return type from int to bool
> 
> [...]

Here is the summary with links:
  - [net-next,1/2] net: hns3: add parameter check for tx_copybreak and tx_spare_buf_size
    https://git.kernel.org/netdev/net-next/c/e16e973c576f
  - [net-next,2/2] net: hns3: change the function return type from int to bool
    https://git.kernel.org/netdev/net-next/c/021f989c863b

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-08-20  3:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-15 10:04 [PATCH net-next 0/2] There are a cleancode and a parameter check for hns3 driver Jijie Shao
2025-08-15 10:04 ` [PATCH net-next 1/2] net: hns3: add parameter check for tx_copybreak and tx_spare_buf_size Jijie Shao
2025-08-15 10:04 ` [PATCH net-next 2/2] net: hns3: change the function return type from int to bool Jijie Shao
2025-08-20  3:11 ` [PATCH net-next 0/2] There are a cleancode and a parameter check for hns3 driver patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).