linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] uacce: use sysfs_emit instead of sprintf
@ 2021-05-17 10:25 Kai Ye
  2021-05-17 10:36 ` Greg KH
  0 siblings, 1 reply; 4+ messages in thread
From: Kai Ye @ 2021-05-17 10:25 UTC (permalink / raw)
  To: gregkh, linux-accelerators, linux-kernel, linuxarm, zhangfei.gao,
	wangzhou1, yekai13

Use the sysfs_emit to replace sprintf.

Signed-off-by: Kai Ye <yekai13@huawei.com>
---
 drivers/misc/uacce/uacce.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/misc/uacce/uacce.c b/drivers/misc/uacce/uacce.c
index d07af4e..c8db16c 100644
--- a/drivers/misc/uacce/uacce.c
+++ b/drivers/misc/uacce/uacce.c
@@ -289,7 +289,7 @@ static ssize_t api_show(struct device *dev,
 {
 	struct uacce_device *uacce = to_uacce_device(dev);
 
-	return sprintf(buf, "%s\n", uacce->api_ver);
+	return sysfs_emit(buf, "%s\n", uacce->api_ver);
 }
 
 static ssize_t flags_show(struct device *dev,
@@ -297,7 +297,7 @@ static ssize_t flags_show(struct device *dev,
 {
 	struct uacce_device *uacce = to_uacce_device(dev);
 
-	return sprintf(buf, "%u\n", uacce->flags);
+	return sysfs_emit(buf, "%u\n", uacce->flags);
 }
 
 static ssize_t available_instances_show(struct device *dev,
@@ -309,7 +309,7 @@ static ssize_t available_instances_show(struct device *dev,
 	if (!uacce->ops->get_available_instances)
 		return -ENODEV;
 
-	return sprintf(buf, "%d\n",
+	return sysfs_emit(buf, "%d\n",
 		       uacce->ops->get_available_instances(uacce));
 }
 
@@ -318,7 +318,7 @@ static ssize_t algorithms_show(struct device *dev,
 {
 	struct uacce_device *uacce = to_uacce_device(dev);
 
-	return sprintf(buf, "%s\n", uacce->algs);
+	return sysfs_emit(buf, "%s\n", uacce->algs);
 }
 
 static ssize_t region_mmio_size_show(struct device *dev,
@@ -326,7 +326,7 @@ static ssize_t region_mmio_size_show(struct device *dev,
 {
 	struct uacce_device *uacce = to_uacce_device(dev);
 
-	return sprintf(buf, "%lu\n",
+	return sysfs_emit(buf, "%lu\n",
 		       uacce->qf_pg_num[UACCE_QFRT_MMIO] << PAGE_SHIFT);
 }
 
@@ -335,7 +335,7 @@ static ssize_t region_dus_size_show(struct device *dev,
 {
 	struct uacce_device *uacce = to_uacce_device(dev);
 
-	return sprintf(buf, "%lu\n",
+	return sysfs_emit(buf, "%lu\n",
 		       uacce->qf_pg_num[UACCE_QFRT_DUS] << PAGE_SHIFT);
 }
 
-- 
2.8.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] uacce: use sysfs_emit instead of sprintf
  2021-05-17 10:25 [PATCH] uacce: use sysfs_emit instead of sprintf Kai Ye
@ 2021-05-17 10:36 ` Greg KH
  2021-05-17 11:49   ` yekai(A)
  0 siblings, 1 reply; 4+ messages in thread
From: Greg KH @ 2021-05-17 10:36 UTC (permalink / raw)
  To: Kai Ye
  Cc: linux-accelerators, linux-kernel, linuxarm, zhangfei.gao, wangzhou1

On Mon, May 17, 2021 at 06:25:37PM +0800, Kai Ye wrote:
> Use the sysfs_emit to replace sprintf.

That says _what_ you did, not _why_ you are doing this.  What problem
are you solving with this change?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] uacce: use sysfs_emit instead of sprintf
  2021-05-17 10:36 ` Greg KH
@ 2021-05-17 11:49   ` yekai(A)
  2021-05-17 11:56     ` Greg KH
  0 siblings, 1 reply; 4+ messages in thread
From: yekai(A) @ 2021-05-17 11:49 UTC (permalink / raw)
  To: Greg KH
  Cc: linux-accelerators, linux-kernel, linuxarm, zhangfei.gao, wangzhou1



On 2021/5/17 18:36, Greg KH wrote:
> On Mon, May 17, 2021 at 06:25:37PM +0800, Kai Ye wrote:
>> Use the sysfs_emit to replace sprintf.
>
> That says _what_ you did, not _why_ you are doing this.  What problem
> are you solving with this change?
>
> thanks,
>
> greg k-h
> .
>
sprintf is not safe, and it not recommended to use.
sprintf does not know the PAGE_SIZE maximum of the temporary buffer
used for outputting sysfs content and it's possible to overrun the
PAGE_SIZE buffer length. so used sysfs_emit that  knows that the size
of the call situations that also ensures that no overrun is done. so use 
sysfs_emit to replace sprintf maybe better.

thanks,
Kai Ye

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] uacce: use sysfs_emit instead of sprintf
  2021-05-17 11:49   ` yekai(A)
@ 2021-05-17 11:56     ` Greg KH
  0 siblings, 0 replies; 4+ messages in thread
From: Greg KH @ 2021-05-17 11:56 UTC (permalink / raw)
  To: yekai(A)
  Cc: linux-accelerators, linux-kernel, linuxarm, zhangfei.gao, wangzhou1

On Mon, May 17, 2021 at 07:49:37PM +0800, yekai(A) wrote:
> 
> 
> On 2021/5/17 18:36, Greg KH wrote:
> > On Mon, May 17, 2021 at 06:25:37PM +0800, Kai Ye wrote:
> > > Use the sysfs_emit to replace sprintf.
> > 
> > That says _what_ you did, not _why_ you are doing this.  What problem
> > are you solving with this change?
> > 
> > thanks,
> > 
> > greg k-h
> > .
> > 
> sprintf is not safe, and it not recommended to use.

Why not?  What is "unsafe" with it in this function?

> sprintf does not know the PAGE_SIZE maximum of the temporary buffer
> used for outputting sysfs content and it's possible to overrun the
> PAGE_SIZE buffer length. so used sysfs_emit that  knows that the size
> of the call situations that also ensures that no overrun is done. so use
> sysfs_emit to replace sprintf maybe better.

But that's not a problem at all for these calls, right?  If so, please
show me how that could ever happen.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-05-17 11:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-17 10:25 [PATCH] uacce: use sysfs_emit instead of sprintf Kai Ye
2021-05-17 10:36 ` Greg KH
2021-05-17 11:49   ` yekai(A)
2021-05-17 11:56     ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).