diff mbox series

[v2] usb: core: use sysfs_emit() instead of sprintf()

Message ID 20241023082439.2430696-2-lijiayi@kylinos.cn (mailing list archive)
State Superseded
Headers show
Series [v2] usb: core: use sysfs_emit() instead of sprintf() | expand

Commit Message

Jiayi Li Oct. 23, 2024, 8:24 a.m. UTC
Follow the advice in Documentation/filesystems/sysfs.rst:
show() should only use sysfs_emit() or sysfs_emit_at() when formatting
the value to be returned to user space.

Signed-off-by: Jiayi Li <lijiayi@kylinos.cn>
---
 drivers/usb/core/endpoint.c        | 11 ++++++-----
 drivers/usb/core/ledtrig-usbport.c |  3 ++-
 drivers/usb/core/port.c            | 11 ++++++-----
 3 files changed, 14 insertions(+), 11 deletions(-)

Comments

Greg Kroah-Hartman Oct. 23, 2024, 8:34 a.m. UTC | #1
On Wed, Oct 23, 2024 at 04:24:39PM +0800, Jiayi Li wrote:
> Follow the advice in Documentation/filesystems/sysfs.rst:
> show() should only use sysfs_emit() or sysfs_emit_at() when formatting
> the value to be returned to user space.
> 
> Signed-off-by: Jiayi Li <lijiayi@kylinos.cn>
> ---
>  drivers/usb/core/endpoint.c        | 11 ++++++-----
>  drivers/usb/core/ledtrig-usbport.c |  3 ++-
>  drivers/usb/core/port.c            | 11 ++++++-----
>  3 files changed, 14 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/usb/core/endpoint.c b/drivers/usb/core/endpoint.c
> index 4b38b87a1343..e48399401608 100644
> --- a/drivers/usb/core/endpoint.c
> +++ b/drivers/usb/core/endpoint.c
> @@ -14,6 +14,7 @@
>  #include <linux/kernel.h>
>  #include <linux/spinlock.h>
>  #include <linux/slab.h>
> +#include <linux/sysfs.h>
>  #include <linux/usb.h>
>  #include "usb.h"
>  
> @@ -39,7 +40,7 @@ static ssize_t field##_show(struct device *dev,			\
>  			       char *buf)			\
>  {								\
>  	struct ep_device *ep = to_ep_device(dev);		\
> -	return sprintf(buf, format_string, ep->desc->field);	\
> +	return sysfs_emit(buf, format_string, ep->desc->field);	\
>  }								\
>  static DEVICE_ATTR_RO(field)
>  
> @@ -52,7 +53,7 @@ static ssize_t wMaxPacketSize_show(struct device *dev,
>  				   struct device_attribute *attr, char *buf)
>  {
>  	struct ep_device *ep = to_ep_device(dev);
> -	return sprintf(buf, "%04x\n", usb_endpoint_maxp(ep->desc));
> +	return sysfs_emit(buf, "%04x\n", usb_endpoint_maxp(ep->desc));
>  }
>  static DEVICE_ATTR_RO(wMaxPacketSize);
>  
> @@ -76,7 +77,7 @@ static ssize_t type_show(struct device *dev, struct device_attribute *attr,
>  		type = "Interrupt";
>  		break;
>  	}
> -	return sprintf(buf, "%s\n", type);
> +	return sysfs_emit(buf, "%s\n", type);
>  }
>  static DEVICE_ATTR_RO(type);
>  
> @@ -95,7 +96,7 @@ static ssize_t interval_show(struct device *dev, struct device_attribute *attr,
>  		interval /= 1000;
>  	}
>  
> -	return sprintf(buf, "%d%cs\n", interval, unit);
> +	return sysfs_emit(buf, "%d%cs\n", interval, unit);
>  }
>  static DEVICE_ATTR_RO(interval);
>  
> @@ -111,7 +112,7 @@ static ssize_t direction_show(struct device *dev, struct device_attribute *attr,
>  		direction = "in";
>  	else
>  		direction = "out";
> -	return sprintf(buf, "%s\n", direction);
> +	return sysfs_emit(buf, "%s\n", direction);
>  }
>  static DEVICE_ATTR_RO(direction);
>  
> diff --git a/drivers/usb/core/ledtrig-usbport.c b/drivers/usb/core/ledtrig-usbport.c
> index 85c999f71ad7..5e3c515991f3 100644
> --- a/drivers/usb/core/ledtrig-usbport.c
> +++ b/drivers/usb/core/ledtrig-usbport.c
> @@ -10,6 +10,7 @@
>  #include <linux/module.h>
>  #include <linux/of.h>
>  #include <linux/slab.h>
> +#include <linux/sysfs.h>
>  #include <linux/usb.h>
>  #include <linux/usb/of.h>
>  
> @@ -87,7 +88,7 @@ static ssize_t usbport_trig_port_show(struct device *dev,
>  						      struct usbport_trig_port,
>  						      attr);
>  
> -	return sprintf(buf, "%d\n", port->observed) + 1;
> +	return sysfs_emit(buf, "%d\n", port->observed) + 1;
>  }
>  
>  static ssize_t usbport_trig_port_store(struct device *dev,
> diff --git a/drivers/usb/core/port.c b/drivers/usb/core/port.c
> index e7da2fca11a4..45d7af00f8d1 100644
> --- a/drivers/usb/core/port.c
> +++ b/drivers/usb/core/port.c
> @@ -9,6 +9,7 @@
>  
>  #include <linux/kstrtox.h>
>  #include <linux/slab.h>
> +#include <linux/sysfs.h>
>  #include <linux/pm_qos.h>
>  #include <linux/component.h>
>  #include <linux/usb/of.h>
> @@ -166,7 +167,7 @@ static ssize_t location_show(struct device *dev,
>  {
>  	struct usb_port *port_dev = to_usb_port(dev);
>  
> -	return sprintf(buf, "0x%08x\n", port_dev->location);
> +	return sysfs_emit(buf, "0x%08x\n", port_dev->location);
>  }
>  static DEVICE_ATTR_RO(location);
>  
> @@ -191,7 +192,7 @@ static ssize_t connect_type_show(struct device *dev,
>  		break;
>  	}
>  
> -	return sprintf(buf, "%s\n", result);
> +	return sysfs_emit(buf, "%s\n", result);
>  }
>  static DEVICE_ATTR_RO(connect_type);
>  
> @@ -210,7 +211,7 @@ static ssize_t over_current_count_show(struct device *dev,
>  {
>  	struct usb_port *port_dev = to_usb_port(dev);
>  
> -	return sprintf(buf, "%u\n", port_dev->over_current_count);
> +	return sysfs_emit(buf, "%u\n", port_dev->over_current_count);
>  }
>  static DEVICE_ATTR_RO(over_current_count);
>  
> @@ -219,7 +220,7 @@ static ssize_t quirks_show(struct device *dev,
>  {
>  	struct usb_port *port_dev = to_usb_port(dev);
>  
> -	return sprintf(buf, "%08x\n", port_dev->quirks);
> +	return sysfs_emit(buf, "%08x\n", port_dev->quirks);
>  }
>  
>  static ssize_t quirks_store(struct device *dev, struct device_attribute *attr,
> @@ -254,7 +255,7 @@ static ssize_t usb3_lpm_permit_show(struct device *dev,
>  			p = "0";
>  	}
>  
> -	return sprintf(buf, "%s\n", p);
> +	return sysfs_emit(buf, "%s\n", p);
>  }
>  
>  static ssize_t usb3_lpm_permit_store(struct device *dev,
> -- 
> 2.45.2
> 
> 

Hi,

This is the friendly patch-bot of Greg Kroah-Hartman.  You have sent him
a patch that has triggered this response.  He used to manually respond
to these common problems, but in order to save his sanity (he kept
writing the same thing over and over, yet to different people), I was
created.  Hopefully you will not take offence and will fix the problem
in your patch and resubmit it so that it can be accepted into the Linux
kernel tree.

You are receiving this message because of the following common error(s)
as indicated below:

- This looks like a new version of a previously submitted patch, but you
  did not list below the --- line any changes from the previous version.
  Please read the section entitled "The canonical patch format" in the
  kernel file, Documentation/process/submitting-patches.rst for what
  needs to be done here to properly describe this.

If you wish to discuss this problem further, or you have questions about
how to resolve this issue, please feel free to respond to this email and
Greg will reply once he has dug out from the pending patches received
from other developers.

thanks,

greg k-h's patch email bot
diff mbox series

Patch

diff --git a/drivers/usb/core/endpoint.c b/drivers/usb/core/endpoint.c
index 4b38b87a1343..e48399401608 100644
--- a/drivers/usb/core/endpoint.c
+++ b/drivers/usb/core/endpoint.c
@@ -14,6 +14,7 @@ 
 #include <linux/kernel.h>
 #include <linux/spinlock.h>
 #include <linux/slab.h>
+#include <linux/sysfs.h>
 #include <linux/usb.h>
 #include "usb.h"
 
@@ -39,7 +40,7 @@  static ssize_t field##_show(struct device *dev,			\
 			       char *buf)			\
 {								\
 	struct ep_device *ep = to_ep_device(dev);		\
-	return sprintf(buf, format_string, ep->desc->field);	\
+	return sysfs_emit(buf, format_string, ep->desc->field);	\
 }								\
 static DEVICE_ATTR_RO(field)
 
@@ -52,7 +53,7 @@  static ssize_t wMaxPacketSize_show(struct device *dev,
 				   struct device_attribute *attr, char *buf)
 {
 	struct ep_device *ep = to_ep_device(dev);
-	return sprintf(buf, "%04x\n", usb_endpoint_maxp(ep->desc));
+	return sysfs_emit(buf, "%04x\n", usb_endpoint_maxp(ep->desc));
 }
 static DEVICE_ATTR_RO(wMaxPacketSize);
 
@@ -76,7 +77,7 @@  static ssize_t type_show(struct device *dev, struct device_attribute *attr,
 		type = "Interrupt";
 		break;
 	}
-	return sprintf(buf, "%s\n", type);
+	return sysfs_emit(buf, "%s\n", type);
 }
 static DEVICE_ATTR_RO(type);
 
@@ -95,7 +96,7 @@  static ssize_t interval_show(struct device *dev, struct device_attribute *attr,
 		interval /= 1000;
 	}
 
-	return sprintf(buf, "%d%cs\n", interval, unit);
+	return sysfs_emit(buf, "%d%cs\n", interval, unit);
 }
 static DEVICE_ATTR_RO(interval);
 
@@ -111,7 +112,7 @@  static ssize_t direction_show(struct device *dev, struct device_attribute *attr,
 		direction = "in";
 	else
 		direction = "out";
-	return sprintf(buf, "%s\n", direction);
+	return sysfs_emit(buf, "%s\n", direction);
 }
 static DEVICE_ATTR_RO(direction);
 
diff --git a/drivers/usb/core/ledtrig-usbport.c b/drivers/usb/core/ledtrig-usbport.c
index 85c999f71ad7..5e3c515991f3 100644
--- a/drivers/usb/core/ledtrig-usbport.c
+++ b/drivers/usb/core/ledtrig-usbport.c
@@ -10,6 +10,7 @@ 
 #include <linux/module.h>
 #include <linux/of.h>
 #include <linux/slab.h>
+#include <linux/sysfs.h>
 #include <linux/usb.h>
 #include <linux/usb/of.h>
 
@@ -87,7 +88,7 @@  static ssize_t usbport_trig_port_show(struct device *dev,
 						      struct usbport_trig_port,
 						      attr);
 
-	return sprintf(buf, "%d\n", port->observed) + 1;
+	return sysfs_emit(buf, "%d\n", port->observed) + 1;
 }
 
 static ssize_t usbport_trig_port_store(struct device *dev,
diff --git a/drivers/usb/core/port.c b/drivers/usb/core/port.c
index e7da2fca11a4..45d7af00f8d1 100644
--- a/drivers/usb/core/port.c
+++ b/drivers/usb/core/port.c
@@ -9,6 +9,7 @@ 
 
 #include <linux/kstrtox.h>
 #include <linux/slab.h>
+#include <linux/sysfs.h>
 #include <linux/pm_qos.h>
 #include <linux/component.h>
 #include <linux/usb/of.h>
@@ -166,7 +167,7 @@  static ssize_t location_show(struct device *dev,
 {
 	struct usb_port *port_dev = to_usb_port(dev);
 
-	return sprintf(buf, "0x%08x\n", port_dev->location);
+	return sysfs_emit(buf, "0x%08x\n", port_dev->location);
 }
 static DEVICE_ATTR_RO(location);
 
@@ -191,7 +192,7 @@  static ssize_t connect_type_show(struct device *dev,
 		break;
 	}
 
-	return sprintf(buf, "%s\n", result);
+	return sysfs_emit(buf, "%s\n", result);
 }
 static DEVICE_ATTR_RO(connect_type);
 
@@ -210,7 +211,7 @@  static ssize_t over_current_count_show(struct device *dev,
 {
 	struct usb_port *port_dev = to_usb_port(dev);
 
-	return sprintf(buf, "%u\n", port_dev->over_current_count);
+	return sysfs_emit(buf, "%u\n", port_dev->over_current_count);
 }
 static DEVICE_ATTR_RO(over_current_count);
 
@@ -219,7 +220,7 @@  static ssize_t quirks_show(struct device *dev,
 {
 	struct usb_port *port_dev = to_usb_port(dev);
 
-	return sprintf(buf, "%08x\n", port_dev->quirks);
+	return sysfs_emit(buf, "%08x\n", port_dev->quirks);
 }
 
 static ssize_t quirks_store(struct device *dev, struct device_attribute *attr,
@@ -254,7 +255,7 @@  static ssize_t usb3_lpm_permit_show(struct device *dev,
 			p = "0";
 	}
 
-	return sprintf(buf, "%s\n", p);
+	return sysfs_emit(buf, "%s\n", p);
 }
 
 static ssize_t usb3_lpm_permit_store(struct device *dev,