[PATCH] vfio/mdev: Use sysfs_emit() to instead of sprintf()

Bo Liu posted 1 patch 2 years, 7 months ago
drivers/vfio/mdev/mdev_sysfs.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] vfio/mdev: Use sysfs_emit() to instead of sprintf()
Posted by Bo Liu 2 years, 7 months ago
Follow the advice of the Documentation/filesystems/sysfs.rst and show()
should only use sysfs_emit() or sysfs_emit_at() when formatting the
value to be returned to user space.

Signed-off-by: Bo Liu <liubo03@inspur.com>
---
 drivers/vfio/mdev/mdev_sysfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/vfio/mdev/mdev_sysfs.c b/drivers/vfio/mdev/mdev_sysfs.c
index abe3359dd477..e4490639d383 100644
--- a/drivers/vfio/mdev/mdev_sysfs.c
+++ b/drivers/vfio/mdev/mdev_sysfs.c
@@ -96,7 +96,7 @@ static MDEV_TYPE_ATTR_RO(device_api);
 static ssize_t name_show(struct mdev_type *mtype,
 			 struct mdev_type_attribute *attr, char *buf)
 {
-	return sprintf(buf, "%s\n",
+	return sysfs_emit(buf, "%s\n",
 		mtype->pretty_name ? mtype->pretty_name : mtype->sysfs_name);
 }
 
-- 
2.27.0
Re: [PATCH] vfio/mdev: Use sysfs_emit() to instead of sprintf()
Posted by Alex Williamson 2 years, 7 months ago
On Sun, 29 Jan 2023 03:41:17 -0500
Bo Liu <liubo03@inspur.com> wrote:

> Follow the advice of the Documentation/filesystems/sysfs.rst and show()
> should only use sysfs_emit() or sysfs_emit_at() when formatting the
> value to be returned to user space.
> 
> Signed-off-by: Bo Liu <liubo03@inspur.com>
> ---
>  drivers/vfio/mdev/mdev_sysfs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/vfio/mdev/mdev_sysfs.c b/drivers/vfio/mdev/mdev_sysfs.c
> index abe3359dd477..e4490639d383 100644
> --- a/drivers/vfio/mdev/mdev_sysfs.c
> +++ b/drivers/vfio/mdev/mdev_sysfs.c
> @@ -96,7 +96,7 @@ static MDEV_TYPE_ATTR_RO(device_api);
>  static ssize_t name_show(struct mdev_type *mtype,
>  			 struct mdev_type_attribute *attr, char *buf)
>  {
> -	return sprintf(buf, "%s\n",
> +	return sysfs_emit(buf, "%s\n",
>  		mtype->pretty_name ? mtype->pretty_name : mtype->sysfs_name);
>  }
>  

Applied to vfio next branch for v6.3.  Thanks,

Alex
Re: [PATCH] vfio/mdev: Use sysfs_emit() to instead of sprintf()
Posted by Jason Gunthorpe 2 years, 7 months ago
On Sun, Jan 29, 2023 at 03:41:17AM -0500, Bo Liu wrote:
> Follow the advice of the Documentation/filesystems/sysfs.rst and show()
> should only use sysfs_emit() or sysfs_emit_at() when formatting the
> value to be returned to user space.
> 
> Signed-off-by: Bo Liu <liubo03@inspur.com>
> ---
>  drivers/vfio/mdev/mdev_sysfs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Sure

Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>

Jason