Skip to contentSkip to conversation

usb: gadget: u_ether: Improve print in gether_setup_name_default()

PATCH Superseded Jon Hunter 3 participants 8 messages Jan 16, 2023 – Jan 19, 2023

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Jon Hunter

author maintainer
#0 lore raw

PATCH v2 1/2 usb: gadget: u_ether: Improve print in gether_setup_name_default()

The print in in gether_setup_name_default() does not provide any useful information because a random MAC address will always be generated when calling this function. Rather than removing the print, update the print to show MAC address that is generated which is similar to other ethernet drivers.

Finally, given that the strings 'self' and 'host' are static we do not need to pass these strings as an arguments.

---
V1 -> V2: Added this patch

 drivers/usb/gadget/function/u_ether.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/gadget/function/u_ether.c +2 -2
index 8f12f3f8f6ee..be8e7b448933 100644
@@ -845,13 +845,13 @@ struct net_device *gether_setup_name_default(const char *netname)
 	snprintf(net->name, sizeof(net->name), "%s%%d", netname);
 
 	eth_random_addr(dev->dev_mac);
-	pr_warn("using random %s ethernet address\n", "self");
+	pr_warn("using random self ethernet address %pM\n", dev->dev_mac);
 
 	/* by default we always have a random MAC address */
 	net->addr_assign_type = NET_ADDR_RANDOM;
 
 	eth_random_addr(dev->host_mac);
-	pr_warn("using random %s ethernet address\n", "host");
+	pr_warn("using random host ethernet address %pM\n", dev->host_mac);
 
 	net->netdev_ops = &eth_netdev_ops;
 
Signature · 1 line
2.25.1
author maintainer
#1 lore raw

PATCH v2 2/2 usb: gadget: u_ether: Don't warn in gether_setup_name_default()

The function gether_setup_name_default() is called by various USB ethernet gadget drivers. This function always generates the MAC address for the ethernet gadget device and always prints a warning when generating the MAC address. Given that these messages are expected, make these debug prints instead of warnings.

---
V1 -> V2: Changed print to debug instead of info.

 drivers/usb/gadget/function/u_ether.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/gadget/function/u_ether.c +2 -2
index be8e7b448933..8feb40e38137 100644
@@ -845,13 +845,13 @@ struct net_device *gether_setup_name_default(const char *netname)
 	snprintf(net->name, sizeof(net->name), "%s%%d", netname);
 
 	eth_random_addr(dev->dev_mac);
-	pr_warn("using random self ethernet address %pM\n", dev->dev_mac);
+	pr_debug("using random self ethernet address %pM\n", dev->dev_mac);
 
 	/* by default we always have a random MAC address */
 	net->addr_assign_type = NET_ADDR_RANDOM;
 
 	eth_random_addr(dev->host_mac);
-	pr_warn("using random host ethernet address %pM\n", dev->host_mac);
+	pr_debug("using random host ethernet address %pM\n", dev->host_mac);
 
 	net->netdev_ops = &eth_netdev_ops;
 
Signature · 1 line
2.25.1
Reviewed-by on v2 1/2
#4 lore raw
In reply to Jon Hunter

W dniu 16.01.2023 o 16:55, Jon Hunter pisze:

Quoted 5 lines

The print in in gether_setup_name_default() does not provide any useful information because a random MAC address will always be generated when calling this function. Rather than removing the print, update the print to show MAC address that is generated which is similar to other ethernet drivers.

I'd say the above part is redundant. It is supposed to be a message understood by future readers of the commit log, who will not necessarily know that we were considering a complete removal of these messages.

Quoted 3 lines

Finally, given that the strings 'self' and 'host' are static we do not need to pass these strings as an arguments.

Just drop the "Finally, ", the indefinite article "an" before the plural noun "arguments" and the above sentence will accurately describe what the patch is about.

With that

Quoted 28 lines

---
V1 -> V2: Added this patch

  drivers/usb/gadget/function/u_ether.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/gadget/function/u_ether.c +2 -2
index 8f12f3f8f6ee..be8e7b448933 100644
@@ -845,13 +845,13 @@ struct net_device *gether_setup_name_default(const char *netname)
  	snprintf(net->name, sizeof(net->name), "%s%%d", netname);
 
  	eth_random_addr(dev->dev_mac);
-	pr_warn("using random %s ethernet address\n", "self");
+	pr_warn("using random self ethernet address %pM\n", dev->dev_mac);
 
  	/* by default we always have a random MAC address */
  	net->addr_assign_type = NET_ADDR_RANDOM;
 
  	eth_random_addr(dev->host_mac);
-	pr_warn("using random %s ethernet address\n", "host");
+	pr_warn("using random host ethernet address %pM\n", dev->host_mac);
 
  	net->netdev_ops = &eth_netdev_ops;
 
Reviewed-by on v2 2/2
#2 lore raw

Re: [PATCH V2 2/2] usb: gadget: u_ether: Don't warn in gether_setup_name_default()

In reply to Jon Hunter

Hi,

W dniu 16.01.2023 o 16:55, Jon Hunter pisze:

Quoted 7 lines

The function gether_setup_name_default() is called by various USB ethernet gadget drivers. This function always generates the MAC address for the ethernet gadget device and always prints a warning when generating the MAC address. Given that these messages are expected, make these debug prints instead of warnings.

Quoted 26 lines

---
V1 -> V2: Changed print to debug instead of info.

  drivers/usb/gadget/function/u_ether.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/gadget/function/u_ether.c +2 -2
index be8e7b448933..8feb40e38137 100644
@@ -845,13 +845,13 @@ struct net_device *gether_setup_name_default(const char *netname)
  	snprintf(net->name, sizeof(net->name), "%s%%d", netname);
 
  	eth_random_addr(dev->dev_mac);
-	pr_warn("using random self ethernet address %pM\n", dev->dev_mac);
+	pr_debug("using random self ethernet address %pM\n", dev->dev_mac);
 
  	/* by default we always have a random MAC address */
  	net->addr_assign_type = NET_ADDR_RANDOM;
 
  	eth_random_addr(dev->host_mac);
-	pr_warn("using random host ethernet address %pM\n", dev->host_mac);
+	pr_debug("using random host ethernet address %pM\n", dev->host_mac);
 
  	net->netdev_ops = &eth_netdev_ops;
 
#3 lore raw

Re: [PATCH V2 2/2] usb: gadget: u_ether: Don't warn in gether_setup_name_default()

Hi again,

W dniu 17.01.2023 o 15:13, Andrzej Pietrasiewicz pisze:

Quoted 8 lines

Hi,

W dniu 16.01.2023 o 16:55, Jon Hunter pisze:

Quoted 5 lines

The function gether_setup_name_default() is called by various USB ethernet gadget drivers. This function always generates the MAC address for the ethernet gadget device and always prints a warning when generating the MAC address. Given that these messages are expected, make these debug prints instead of warnings.

Actually, I have second thoughts about this commit message. If the messages were expected, why would you change them?

I think that just as in PATCH V2 1/1, there's an implicit context required to understand your commit message: it answers the question "why don't we just remove these messages altogether?" Answer: "because they might be expected by some guys, so let's keep them".

IMO, what _is_ expected is random selection of addresses. So, something on the lines of this would look better to me:

"Randomly selecting host and device MAC addresses is a proper and expected default behavior. A properly working driver should be silent, so don't warn the user about default MAC addresses selection happening and convert the warnings into debug messages."

Quoted 4 lines
Quoted 2 lines

With the above taken into account I uphold my R-b tag.

Andrzej

Quoted 24 lines
Quoted 23 lines

---
V1 -> V2: Changed print to debug instead of info.

  drivers/usb/gadget/function/u_ether.c | 4 ++--

  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/gadget/function/u_ether.c +2 -2
index be8e7b448933..8feb40e38137 100644
@@ -845,13 +845,13 @@ struct net_device *gether_setup_name_default(const char 
 *netname)
       snprintf(net->name, sizeof(net->name), "%s%%d", netname);
       eth_random_addr(dev->dev_mac);
-    pr_warn("using random self ethernet address %pM\n", dev->dev_mac);
+    pr_debug("using random self ethernet address %pM\n", dev->dev_mac);
       /* by default we always have a random MAC address */
       net->addr_assign_type = NET_ADDR_RANDOM;
       eth_random_addr(dev->host_mac);
-    pr_warn("using random host ethernet address %pM\n", dev->host_mac);
+    pr_debug("using random host ethernet address %pM\n", dev->host_mac);
       net->netdev_ops = &eth_netdev_ops;
#5 lore raw
In reply to Jon Hunter
Quoted 21 lines · Jon Hunter

The print in in gether_setup_name_default() does not provide any useful information because a random MAC address will always be generated when calling this function. Rather than removing the print, update the print to show MAC address that is generated which is similar to other ethernet drivers.

Finally, given that the strings 'self' and 'host' are static we do not need to pass these strings as an arguments.

---
V1 -> V2: Added this patch

 drivers/usb/gadget/function/u_ether.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/gadget/function/u_ether.c +0 -0
index 8f12f3f8f6ee..be8e7b448933 100644

drivers/usb/gadget/function/u_ether.c struct net_device *gether_setup_name_default(const char *netname) · line 848

Quoted 5 lines
drivers/usb/gadget/function/u_ether.c +1 -1
@@ -845,13 +845,13 @@ struct net_device *gether_setup_name_default(const char *netname)
 	snprintf(net->name, sizeof(net->name), "%s%%d", netname);
 
 	eth_random_addr(dev->dev_mac);
-	pr_warn("using random %s ethernet address\n", "self");
+	pr_warn("using random self ethernet address %pM\n", dev->dev_mac);

If you are going to fix these up, please use dev_warn() and friends, don't use "raw" pr_* calls in a driver.

thanks,

greg k-h

author maintainer
#6 lore raw
Quoted 24 lines · Greg Kroah-Hartman
Quoted 23 lines · Jon Hunter

The print in in gether_setup_name_default() does not provide any useful information because a random MAC address will always be generated when calling this function. Rather than removing the print, update the print to show MAC address that is generated which is similar to other ethernet drivers.

Finally, given that the strings 'self' and 'host' are static we do not need to pass these strings as an arguments.

---
V1 -> V2: Added this patch

  drivers/usb/gadget/function/u_ether.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/gadget/function/u_ether.c +0 -0
index 8f12f3f8f6ee..be8e7b448933 100644
@@ -845,13 +845,13 @@ struct net_device *gether_setup_name_default(const char *netname)
  	snprintf(net->name, sizeof(net->name), "%s%%d", netname);
 
Quoted 6 lines

drivers/usb/gadget/function/u_ether.c struct net_device *gether_setup_name_default(const char *netname) · line 848

Quoted 3 lines
drivers/usb/gadget/function/u_ether.c +1 -1
  	eth_random_addr(dev->dev_mac);
-	pr_warn("using random %s ethernet address\n", "self");
+	pr_warn("using random self ethernet address %pM\n", dev->dev_mac);

If you are going to fix these up, please use dev_warn() and friends, don't use "raw" pr_* calls in a driver.

I had a look at that, but I don't think we can in this case. The 'dev' structure you see above is of type 'struct eth_dev' and not 'struct device'. In other places in the driver where dev_warn is used the device structure comes from the 'struct usb_gadget' but FWICT this is not initialised in the above function.

Jon

Signature · 1 line
nvpublic
#7 lore raw
Quoted 33 lines · Jon Hunter
Quoted 17 lines · Greg Kroah-Hartman
Quoted 16 lines · Jon Hunter

The print in in gether_setup_name_default() does not provide any useful information because a random MAC address will always be generated when calling this function. Rather than removing the print, update the print to show MAC address that is generated which is similar to other ethernet drivers.

Finally, given that the strings 'self' and 'host' are static we do not need to pass these strings as an arguments.

---
V1 -> V2: Added this patch

  drivers/usb/gadget/function/u_ether.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 12 lines

drivers/usb/gadget/function/u_ether.c struct net_device *gether_setup_name_default(const char *netname) · line 847

Quoted 9 lines
drivers/usb/gadget/function/u_ether.c +1 -1
index 8f12f3f8f6ee..be8e7b448933 100644
@@ -845,13 +845,13 @@ struct net_device *gether_setup_name_default(const char *netname)
  	snprintf(net->name, sizeof(net->name), "%s%%d", netname);
  	eth_random_addr(dev->dev_mac);
-	pr_warn("using random %s ethernet address\n", "self");
+	pr_warn("using random self ethernet address %pM\n", dev->dev_mac);

If you are going to fix these up, please use dev_warn() and friends, don't use "raw" pr_* calls in a driver.

Quoted 2 lines

I had a look at that, but I don't think we can in this case. The 'dev' structure you see above is of type 'struct eth_dev' and not 'struct device'.

Then use the networking macro for this. And underneath it all is a real struct device anyway, so it should be possible.

Quoted 3 lines

In other places in the driver where dev_warn is used the device structure comes from the 'struct usb_gadget' but FWICT this is not initialised in the above function.

There's a structure somewhere in here, NEVER use raw pr_* calls in a driver, especially for a message like this. It needs to point to the correct device that is making the message, otherwise it's impossible to know what is going on (and is why we created those macros decades ago...)

thanks,

greg k-h