Skip to contentSkip to conversation

eea: Improvements in the driver

PATCH In review Andy Shevchenko 4 participants 14 messages Oct 2 – Oct 8

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover eea: Improvements in the driver

My attention was caught by the explicit call of string_escape_str() which is not required in this case and saves a lot of memory on the stack (see patch 1). But then I noticed more to improve, hence this mini-series.

In v2:
- addressed Sashiko conserns
- added patches 2-5

v1: [email protected]

Andy Shevchenko (5):
eea: Drop temporary buffer by using %*pEhp directly
eea: Remove unneeded assignment
eea: Refactor error handling in eea_adminq_config_host_info()
eea: unify return code variable name
eea: Use 2-argument strscpy()

 drivers/net/ethernet/alibaba/eea/eea_adminq.c | 65 +++++++++----------
 .../net/ethernet/alibaba/eea/eea_ethtool.c    |  4 +-
 2 files changed, 32 insertions(+), 37 deletions(-)
Signature · 1 line
2.50.1
#1 lore raw

PATCH v2 1/5 eea: Drop temporary buffer by using %*pEhp directly

Instead of calling string_escape_str() followed by %s specifier, use %*pEhp specifier directly. With this being done, drop temporary buffer.

Note, as Sashiko pointed out in [1] the %*pEp, which is the direct substitution of the original call to string_escape_str() with ESCAPE_NP flag set, makes the whole thing like "no escape". To add some sanity to this the used specifier also includes ESCAPE_HEX.

---
 drivers/net/ethernet/alibaba/eea/eea_adminq.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/net/ethernet/alibaba/eea/eea_adminq.c +2 -9
index 73d0caf25700..f2284fc885c3 100644
@@ -522,16 +522,9 @@ void eea_adminq_config_host_info(struct eea_net *enet)
 			dev_warn(dev, "The hardware-driven state validation may be abnormal.\n");
 
 		if (rep->has_reply) {
-			char buf[EEA_HINFO_MAX_REP_LEN] = {0};
-
 			rep->reply_str[EEA_HINFO_MAX_REP_LEN - 1] = '\0';
-
-			string_escape_str(rep->reply_str, buf, sizeof(buf),
-					  ESCAPE_NP, NULL);
-
-			buf[EEA_HINFO_MAX_REP_LEN - 1] = '\0';
-
-			dev_warn(dev, "Device replied: %s\n", buf);
+			dev_warn(dev, "Device replied: %*pEhp\n",
+				 (int)strlen(rep->reply_str), rep->reply_str);
 		}
 	}
 
Signature · 1 line
2.50.1
Reviewed-by on v2 1/5
#2 lore raw

Re: [PATCH net-next v2 1/5] eea: Drop temporary buffer by using %*pEhp directly

Quoted 25 lines · Andy Shevchenko

Instead of calling string_escape_str() followed by %s specifier, use %*pEhp specifier directly. With this being done, drop temporary buffer.

Note, as Sashiko pointed out in [1] the %*pEp, which is the direct substitution of the original call to string_escape_str() with ESCAPE_NP flag set, makes the whole thing like "no escape". To add some sanity to this the used specifier also includes ESCAPE_HEX.

---
 drivers/net/ethernet/alibaba/eea/eea_adminq.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/net/ethernet/alibaba/eea/eea_adminq.c +0 -2
index 73d0caf25700..f2284fc885c3 100644
@@ -522,16 +522,9 @@ void eea_adminq_config_host_info(struct eea_net *enet)
 			dev_warn(dev, "The hardware-driven state validation may be abnormal.\n");
 
 		if (rep->has_reply) {
-			char buf[EEA_HINFO_MAX_REP_LEN] = {0};
-

drivers/net/ethernet/alibaba/eea/eea_adminq.c void eea_adminq_config_host_info(struct eea_net *enet) · line 527

Quoted 10 lines
drivers/net/ethernet/alibaba/eea/eea_adminq.c +2 -7
 			rep->reply_str[EEA_HINFO_MAX_REP_LEN - 1] = '\0';
-
-			string_escape_str(rep->reply_str, buf, sizeof(buf),
-					  ESCAPE_NP, NULL);
-
-			buf[EEA_HINFO_MAX_REP_LEN - 1] = '\0';
-
-			dev_warn(dev, "Device replied: %s\n", buf);
+			dev_warn(dev, "Device replied: %*pEhp\n",
+				 (int)strlen(rep->reply_str), rep->reply_str);

i have no idea what this otuput could be but i suppose if you wanted to remove the terminator write above, you could do:

strnlen(rep->reply_str, ....)

instead, but that feels like a fairly useless nit so:

#3 lore raw

Re: [PATCH net-next v2 1/5] eea: Drop temporary buffer by using %*pEhp directly

Quoted 1 line · Joe Damato

On Fri, Oct 02, 2026 at 11:59:19AM +0200, Andy Shevchenko wrote:

...

Quoted 1 line
Quoted 1 line

rep->reply_str[EEA_HINFO_MAX_REP_LEN - 1] = '\0';

^^^ (see below)

Quoted 7 lines

drivers/net/ethernet/alibaba/eea/eea_adminq.c void eea_adminq_config_host_info(struct eea_net *enet) · line 527

Quoted 2 lines
drivers/net/ethernet/alibaba/eea/eea_adminq.c +2 -0
+			dev_warn(dev, "Device replied: %*pEhp\n",
+				 (int)strlen(rep->reply_str), rep->reply_str);

i have no idea what this otuput could be but i suppose if you wanted to remove the terminator write above, you could do:

   strnlen(rep->reply_str, ....)

I haven't touched original code, which as you see above NUL-terminates the reply string. So this has no difference with strlen(), but the latter is shorter (doesn't need an additional argument).

Quoted 1 line

instead, but that feels like a fairly useless nit so:

Indeed :-)

Quoted 1 line

Thanks!

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw

PATCH v2 2/5 eea: Remove unneeded assignment

In reply to Andy Shevchenko

The initial err is not used anywhere, drop the unneeded assignment.

---
 drivers/net/ethernet/alibaba/eea/eea_adminq.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/net/ethernet/alibaba/eea/eea_adminq.c +4 -3
index f2284fc885c3..4876f8a1e686 100644
@@ -266,7 +266,7 @@ int eea_create_adminq(struct eea_net *enet, u32 qid)
 	u32 db_size, q_size, num;
 	struct eea_ring *ering;
 	struct eea_aq *aq;
-	int err = -ENOMEM;
+	int err;
 
 	num = enet->edev->rx_num + enet->edev->tx_num;
 	aq = &enet->adminq;
@@ -347,11 +347,12 @@ static void qcfg_fill(struct eea_aq_create *qcfg, struct eea_ring *ering,
 
 int eea_adminq_create_q(struct eea_net *enet, u32 num, u32 flags)
 {
-	int i, db_size, q_size, err = -ENOMEM;
 	struct eea_net_cfg *cfg;
 	struct eea_ring *ering;
+	int i, db_size, q_size;
 	struct eea_aq *aq;
 	u32 reply_len;
+	int err;
 
 	cfg = &enet->cfg;
 	aq = &enet->adminq;
@@ -483,7 +484,7 @@ void eea_adminq_config_host_info(struct eea_net *enet)
 	struct device *dev = enet->edev->dma_dev;
 	struct eea_aq_host_info_cfg *cfg;
 	struct eea_aq_host_info_rep *rep;
-	int rc = -ENOMEM;
+	int rc;
 
 	cfg = kzalloc_obj(*cfg);
 	if (!cfg)
Signature · 1 line
2.50.1
Reviewed-by on v2 2/5
#5 lore raw

Re: [PATCH net-next v2 2/5] eea: Remove unneeded assignment

Quoted 6 lines · Andy Shevchenko

The initial err is not used anywhere, drop the unneeded assignment.

---
 drivers/net/ethernet/alibaba/eea/eea_adminq.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
#6 lore raw

PATCH v2 3/5 eea: Refactor error handling in eea_adminq_config_host_info()

In reply to Andy Shevchenko

Use traditional pattern to check for error first in eea_adminq_config_host_info().

---
 drivers/net/ethernet/alibaba/eea/eea_adminq.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/net/ethernet/alibaba/eea/eea_adminq.c +9 -8
index 4876f8a1e686..92eeff32b00c 100644
@@ -517,18 +517,19 @@ void eea_adminq_config_host_info(struct eea_net *enet)
 
 	rc = eea_adminq_exec(enet, EEA_AQ_CMD_HOST_INFO,
 			     cfg, sizeof(*cfg), rep, sizeof(*rep), NULL);
+	if (rc)
+		goto err_free_rep;
 
-	if (!rc) {
-		if (rep->op_code == EEA_HINFO_REP_BAD)
-			dev_warn(dev, "The hardware-driven state validation may be abnormal.\n");
+	if (rep->op_code == EEA_HINFO_REP_BAD)
+		dev_warn(dev, "The hardware-driven state validation may be abnormal.\n");
 
-		if (rep->has_reply) {
-			rep->reply_str[EEA_HINFO_MAX_REP_LEN - 1] = '\0';
-			dev_warn(dev, "Device replied: %*pEhp\n",
-				 (int)strlen(rep->reply_str), rep->reply_str);
-		}
+	if (rep->has_reply) {
+		rep->reply_str[EEA_HINFO_MAX_REP_LEN - 1] = '\0';
+		dev_warn(dev, "Device replied: %*pEhp\n",
+			 (int)strlen(rep->reply_str), rep->reply_str);
 	}
 
+err_free_rep:
 	kfree(rep);
 err_free_cfg:
 	kfree(cfg);
Signature · 1 line
2.50.1
Reviewed-by on v2 3/5
#7 lore raw

Re: [PATCH net-next v2 3/5] eea: Refactor error handling in eea_adminq_config_host_info()

Quoted 7 lines · Andy Shevchenko

Use traditional pattern to check for error first in eea_adminq_config_host_info().

---
 drivers/net/ethernet/alibaba/eea/eea_adminq.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
#8 lore raw

PATCH v2 4/5 eea: unify return code variable name

In reply to Andy Shevchenko

In one case 'rc' is used in the other 'ret', the most use 'err'. Make the latter use the former, id est 'err'.

---
 drivers/net/ethernet/alibaba/eea/eea_adminq.c | 34 +++++++++----------
 1 file changed, 17 insertions(+), 17 deletions(-)
drivers/net/ethernet/alibaba/eea/eea_adminq.c +17 -17
index 92eeff32b00c..f493afbcc41b 100644
@@ -133,7 +133,7 @@ static int eea_adminq_submit(struct eea_net *enet, u16 cmd,
 {
 	struct eea_aq_cdesc *cdesc;
 	struct eea_aq_desc *desc;
-	int ret;
+	int err;
 
 	if (enet->adminq.broken)
 		return -EIO;
@@ -163,9 +163,9 @@ static int eea_adminq_submit(struct eea_net *enet, u16 cmd,
 	if ((enet->adminq.num % enet->adminq.ring->num) == 0)
 		enet->adminq.phase ^= EEA_RING_DESC_F_AQ_PHASE;
 
-	ret = read_poll_timeout(eea_ering_cq_get_desc, cdesc, cdesc, 10,
+	err = read_poll_timeout(eea_ering_cq_get_desc, cdesc, cdesc, 10,
 				EEA_AQ_TIMEOUT_US, false, enet->adminq.ring);
-	if (ret) {
+	if (err) {
 		netdev_err(enet->netdev,
 			   "adminq exec timeout. cmd: %d reset device.\n",
 			   cmd);
@@ -173,21 +173,21 @@ static int eea_adminq_submit(struct eea_net *enet, u16 cmd,
 		 * potential DMA writes after the memory is freed.
 		 */
 		eea_device_broken(enet);
-		return ret;
+		return err;
 	}
 
 	/* Returns 0 on success, or a negative error code on failure. */
-	ret = le32_to_cpu(cdesc->status);
+	err = le32_to_cpu(cdesc->status);
 
 	eea_ering_cq_ack_desc(enet->adminq.ring, 1);
 
-	if (ret)
+	if (err)
 		netdev_err(enet->netdev,
-			   "adminq exec failed. cmd: %d ret %d\n", cmd, ret);
+			   "adminq exec failed. cmd: %d ret %d\n", cmd, err);
 	else
 		*reply_len = le32_to_cpu(cdesc->reply_len);
 
-	return ret;
+	return err;
 }
 
 static int eea_adminq_exec(struct eea_net *enet, u16 cmd,
@@ -198,7 +198,7 @@ static int eea_adminq_exec(struct eea_net *enet, u16 cmd,
 	dma_addr_t req_addr = 0, res_addr = 0;
 	struct device *dma;
 	u32 reply_len = 0;
-	int ret;
+	int err;
 
 	if (reply)
 		*reply = 0;
@@ -214,19 +214,19 @@ static int eea_adminq_exec(struct eea_net *enet, u16 cmd,
 	if (res) {
 		res_addr = dma_map_single(dma, res, res_size, DMA_FROM_DEVICE);
 		if (unlikely(dma_mapping_error(dma, res_addr))) {
-			ret = -ENOMEM;
+			err = -ENOMEM;
 			goto err_unmap_req;
 		}
 	}
 
 	mutex_lock(&enet->adminq.lock);
-	ret = eea_adminq_submit(enet, cmd, req_addr, res_addr,
+	err = eea_adminq_submit(enet, cmd, req_addr, res_addr,
 				req_size, res_size, &reply_len);
 	mutex_unlock(&enet->adminq.lock);
 	if (res) {
 		dma_unmap_single(dma, res_addr, res_size, DMA_FROM_DEVICE);
 
-		if (ret)
+		if (err)
 			memset(res, 0, res_size);
 		else if (res_size > reply_len)
 			memset(res + reply_len, 0, res_size - reply_len);
@@ -239,7 +239,7 @@ static int eea_adminq_exec(struct eea_net *enet, u16 cmd,
 	if (req)
 		dma_unmap_single(dma, req_addr, req_size, DMA_TO_DEVICE);
 
-	return ret;
+	return err;
 }
 
 void eea_destroy_adminq(struct eea_net *enet)
@@ -484,7 +484,7 @@ void eea_adminq_config_host_info(struct eea_net *enet)
 	struct device *dev = enet->edev->dma_dev;
 	struct eea_aq_host_info_cfg *cfg;
 	struct eea_aq_host_info_rep *rep;
-	int rc;
+	int err;
 
 	cfg = kzalloc_obj(*cfg);
 	if (!cfg)
@@ -515,9 +515,9 @@ void eea_adminq_config_host_info(struct eea_net *enet)
 	strscpy(cfg->os_ver_str, utsname()->release, sizeof(cfg->os_ver_str));
 	strscpy(cfg->isa_str, utsname()->machine, sizeof(cfg->isa_str));
 
-	rc = eea_adminq_exec(enet, EEA_AQ_CMD_HOST_INFO,
-			     cfg, sizeof(*cfg), rep, sizeof(*rep), NULL);
-	if (rc)
+	err = eea_adminq_exec(enet, EEA_AQ_CMD_HOST_INFO,
+			      cfg, sizeof(*cfg), rep, sizeof(*rep), NULL);
+	if (err)
 		goto err_free_rep;
 
 	if (rep->op_code == EEA_HINFO_REP_BAD)
Signature · 1 line
2.50.1
Reviewed-by on v2 4/5
#9 lore raw

Re: [PATCH net-next v2 4/5] eea: unify return code variable name

Quoted 7 lines · Andy Shevchenko

In one case 'rc' is used in the other 'ret', the most use 'err'. Make the latter use the former, id est 'err'.

---
 drivers/net/ethernet/alibaba/eea/eea_adminq.c | 34 +++++++++----------
 1 file changed, 17 insertions(+), 17 deletions(-)
maintainer
#10 lore raw

Re: [PATCH net-next v2 4/5] eea: unify return code variable name

In reply to Andy Shevchenko
Quoted 2 lines · On Fri, 2 Oct 2026 11:59:22 +0200 Andy Shevchenko wrote:

In one case 'rc' is used in the other 'ret', the most use 'err'. Make the latter use the former, id est 'err'.

this is below the bar for things worth changing in someone else's driver

#11 lore raw

PATCH v2 5/5 eea: Use 2-argument strscpy()

In reply to Andy Shevchenko

From: Andy Shevchenko <[email protected]>

Use 2-argument strscpy(), which is not only shorter but also provides an additional check that destination buffer is an array.

---
 drivers/net/ethernet/alibaba/eea/eea_adminq.c  | 4 ++--
 drivers/net/ethernet/alibaba/eea/eea_ethtool.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/net/ethernet/alibaba/eea/eea_adminq.c +2 -2
index f493afbcc41b..942f1f1911af 100644
@@ -512,8 +512,8 @@ void eea_adminq_config_host_info(struct eea_net *enet)
 	cfg->pci_bdf            = cpu_to_le16(eea_pci_bdf(enet->edev));
 	cfg->pci_domain         = cpu_to_le32(eea_pci_domain_nr(enet->edev));
 
-	strscpy(cfg->os_ver_str, utsname()->release, sizeof(cfg->os_ver_str));
-	strscpy(cfg->isa_str, utsname()->machine, sizeof(cfg->isa_str));
+	strscpy(cfg->os_ver_str, utsname()->release);
+	strscpy(cfg->isa_str, utsname()->machine);
 
 	err = eea_adminq_exec(enet, EEA_AQ_CMD_HOST_INFO,
 			      cfg, sizeof(*cfg), rep, sizeof(*rep), NULL);
drivers/net/ethernet/alibaba/eea/eea_ethtool.c +2 -2
index 479779aa2dd8..15f4c7b2d898 100644
@@ -40,8 +40,8 @@ static void eea_get_drvinfo(struct net_device *netdev,
 	struct eea_net *enet = netdev_priv(netdev);
 	struct eea_device *edev = enet->edev;
 
-	strscpy(info->driver,   KBUILD_MODNAME,     sizeof(info->driver));
-	strscpy(info->bus_info, eea_pci_name(edev), sizeof(info->bus_info));
+	strscpy(info->driver, KBUILD_MODNAME);
+	strscpy(info->bus_info, eea_pci_name(edev));
 }
 
 static void eea_get_ringparam(struct net_device *netdev,
Signature · 1 line
2.50.1
Reviewed-by on v2 5/5
#12 lore raw

Re: [PATCH net-next v2 5/5] eea: Use 2-argument strscpy()

Quoted 11 lines · Andy Shevchenko

From: Andy Shevchenko <[email protected]>

Use 2-argument strscpy(), which is not only shorter but also provides an additional check that destination buffer is an array.

---
 drivers/net/ethernet/alibaba/eea/eea_adminq.c  | 4 ++--
 drivers/net/ethernet/alibaba/eea/eea_ethtool.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
#13 lore raw
In reply to Andy Shevchenko
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Fri, 2 Oct 2026 11:59:18 +0200 you wrote:

My attention was caught by the explicit call of string_escape_str() which is not required in this case and saves a lot of memory on the stack (see patch 1). But then I noticed more to improve, hence this mini-series.

In v2:
- addressed Sashiko conserns
- added patches 2-5

[...]

Here is the summary with links:
- [net-next,v2,1/5] eea: Drop temporary buffer by using %*pEhp directly

    https://git.kernel.org/netdev/net-next/c/f46b52335f76
  - [net-next,v2,2/5] eea: Remove unneeded assignment
    https://git.kernel.org/netdev/net-next/c/c1333be192b0
  - [net-next,v2,3/5] eea: Refactor error handling in eea_adminq_config_host_info()
    https://git.kernel.org/netdev/net-next/c/8724ed6e604c
  - [net-next,v2,4/5] eea: unify return code variable name
    (no matching commit)
  - [net-next,v2,5/5] eea: Use 2-argument strscpy()
    https://git.kernel.org/netdev/net-next/c/ecc57880bbb0

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html