Skip to content

Commit 8beead2

Browse files
committed
Merge branch 'there-are-a-cleancode-and-a-parameter-check-for-hns3-driver'
Jijie Shao says: ==================== There are a cleancode and a parameter check for hns3 driver This patchset includes: 1. a parameter check omitted from fix code in net branch https://lore.kernel.org/all/[email protected]/ 2. a small clean code ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 3a752e6 + 021f989 commit 8beead2

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1927,6 +1927,31 @@ static int hns3_set_tx_spare_buf_size(struct net_device *netdev,
19271927
return ret;
19281928
}
19291929

1930+
static int hns3_check_tx_copybreak(struct net_device *netdev, u32 copybreak)
1931+
{
1932+
struct hns3_nic_priv *priv = netdev_priv(netdev);
1933+
1934+
if (copybreak < priv->min_tx_copybreak) {
1935+
netdev_err(netdev, "tx copybreak %u should be no less than %u!\n",
1936+
copybreak, priv->min_tx_copybreak);
1937+
return -EINVAL;
1938+
}
1939+
return 0;
1940+
}
1941+
1942+
static int hns3_check_tx_spare_buf_size(struct net_device *netdev, u32 buf_size)
1943+
{
1944+
struct hns3_nic_priv *priv = netdev_priv(netdev);
1945+
1946+
if (buf_size < priv->min_tx_spare_buf_size) {
1947+
netdev_err(netdev,
1948+
"tx spare buf size %u should be no less than %u!\n",
1949+
buf_size, priv->min_tx_spare_buf_size);
1950+
return -EINVAL;
1951+
}
1952+
return 0;
1953+
}
1954+
19301955
static int hns3_set_tunable(struct net_device *netdev,
19311956
const struct ethtool_tunable *tuna,
19321957
const void *data)
@@ -1943,6 +1968,10 @@ static int hns3_set_tunable(struct net_device *netdev,
19431968

19441969
switch (tuna->id) {
19451970
case ETHTOOL_TX_COPYBREAK:
1971+
ret = hns3_check_tx_copybreak(netdev, *(u32 *)data);
1972+
if (ret)
1973+
return ret;
1974+
19461975
priv->tx_copybreak = *(u32 *)data;
19471976

19481977
for (i = 0; i < h->kinfo.num_tqps; i++)
@@ -1957,6 +1986,10 @@ static int hns3_set_tunable(struct net_device *netdev,
19571986

19581987
break;
19591988
case ETHTOOL_TX_COPYBREAK_BUF_SIZE:
1989+
ret = hns3_check_tx_spare_buf_size(netdev, *(u32 *)data);
1990+
if (ret)
1991+
return ret;
1992+
19601993
old_tx_spare_buf_size = h->kinfo.tx_spare_buf_size;
19611994
new_tx_spare_buf_size = *(u32 *)data;
19621995
netdev_info(netdev, "request to set tx spare buf size from %u to %u\n",

drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2182,8 +2182,8 @@ static bool hclge_drop_pfc_buf_till_fit(struct hclge_dev *hdev,
21822182
return hclge_is_rx_buf_ok(hdev, buf_alloc, rx_all);
21832183
}
21842184

2185-
static int hclge_only_alloc_priv_buff(struct hclge_dev *hdev,
2186-
struct hclge_pkt_buf_alloc *buf_alloc)
2185+
static bool hclge_only_alloc_priv_buff(struct hclge_dev *hdev,
2186+
struct hclge_pkt_buf_alloc *buf_alloc)
21872187
{
21882188
#define COMPENSATE_BUFFER 0x3C00
21892189
#define COMPENSATE_HALF_MPS_NUM 5

0 commit comments

Comments
 (0)