linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tty: 8250: replace snprintf in show functions with sysfs_emit
@ 2021-10-15  6:51 Qing Wang
  2021-10-15  6:57 ` Greg Kroah-Hartman
       [not found] ` <AOQACwDzEi5UM3m3ezm-D4o5.9.1634281082401.Hmail.wangqing@vivo.com>
  0 siblings, 2 replies; 3+ messages in thread
From: Qing Wang @ 2021-10-15  6:51 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby, Joel Stanley, Andrew Jeffery,
	linux-serial, linux-arm-kernel, linux-aspeed, linux-kernel
  Cc: Qing Wang

show() must not use snprintf() when formatting the value to be
returned to user space.

Fix the coccicheck warnings:
WARNING: use scnprintf or sprintf.

Signed-off-by: Qing Wang <wangqing@vivo.com>
---
 drivers/tty/serial/8250/8250_aspeed_vuart.c | 6 +++---
 drivers/tty/serial/8250/8250_port.c         | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_aspeed_vuart.c b/drivers/tty/serial/8250/8250_aspeed_vuart.c
index 2350fb3..082b9bd 100644
--- a/drivers/tty/serial/8250/8250_aspeed_vuart.c
+++ b/drivers/tty/serial/8250/8250_aspeed_vuart.c
@@ -82,7 +82,7 @@ static ssize_t lpc_address_show(struct device *dev,
 	addr = (aspeed_vuart_readb(vuart, ASPEED_VUART_ADDRH) << 8) |
 		(aspeed_vuart_readb(vuart, ASPEED_VUART_ADDRL));
 
-	return snprintf(buf, PAGE_SIZE - 1, "0x%x\n", addr);
+	return sysfs_emit(buf - 1, "0x%x\n", addr);
 }
 
 static int aspeed_vuart_set_lpc_address(struct aspeed_vuart *vuart, u32 addr)
@@ -124,7 +124,7 @@ static ssize_t sirq_show(struct device *dev,
 	reg &= ASPEED_VUART_GCRB_HOST_SIRQ_MASK;
 	reg >>= ASPEED_VUART_GCRB_HOST_SIRQ_SHIFT;
 
-	return snprintf(buf, PAGE_SIZE - 1, "%u\n", reg);
+	return sysfs_emit(buf - 1, "%u\n", reg);
 }
 
 static int aspeed_vuart_set_sirq(struct aspeed_vuart *vuart, u32 sirq)
@@ -171,7 +171,7 @@ static ssize_t sirq_polarity_show(struct device *dev,
 	reg = aspeed_vuart_readb(vuart, ASPEED_VUART_GCRA);
 	reg &= ASPEED_VUART_GCRA_HOST_SIRQ_POLARITY;
 
-	return snprintf(buf, PAGE_SIZE - 1, "%u\n", reg ? 1 : 0);
+	return sysfs_emit(buf - 1, "%u\n", reg ? 1 : 0);
 }
 
 static void aspeed_vuart_set_sirq_polarity(struct aspeed_vuart *vuart,
diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index 1da29a2..635cc42 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -3085,7 +3085,7 @@ static ssize_t rx_trig_bytes_show(struct device *dev,
 	if (rxtrig_bytes < 0)
 		return rxtrig_bytes;
 
-	return snprintf(buf, PAGE_SIZE, "%d\n", rxtrig_bytes);
+	return sysfs_emit(buf, "%d\n", rxtrig_bytes);
 }
 
 static int do_set_rxtrig(struct tty_port *port, unsigned char bytes)
-- 
2.7.4


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

* Re: [PATCH] tty: 8250: replace snprintf in show functions with sysfs_emit
  2021-10-15  6:51 [PATCH] tty: 8250: replace snprintf in show functions with sysfs_emit Qing Wang
@ 2021-10-15  6:57 ` Greg Kroah-Hartman
       [not found] ` <AOQACwDzEi5UM3m3ezm-D4o5.9.1634281082401.Hmail.wangqing@vivo.com>
  1 sibling, 0 replies; 3+ messages in thread
From: Greg Kroah-Hartman @ 2021-10-15  6:57 UTC (permalink / raw)
  To: Qing Wang
  Cc: Jiri Slaby, Joel Stanley, Andrew Jeffery, linux-serial,
	linux-arm-kernel, linux-aspeed, linux-kernel

On Thu, Oct 14, 2021 at 11:51:22PM -0700, Qing Wang wrote:
> show() must not use snprintf() when formatting the value to be
> returned to user space.

Why must it not?  What is broken in the existing code?

> 
> Fix the coccicheck warnings:
> WARNING: use scnprintf or sprintf.
> 
> Signed-off-by: Qing Wang <wangqing@vivo.com>
> ---
>  drivers/tty/serial/8250/8250_aspeed_vuart.c | 6 +++---
>  drivers/tty/serial/8250/8250_port.c         | 2 +-
>  2 files changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/tty/serial/8250/8250_aspeed_vuart.c b/drivers/tty/serial/8250/8250_aspeed_vuart.c
> index 2350fb3..082b9bd 100644
> --- a/drivers/tty/serial/8250/8250_aspeed_vuart.c
> +++ b/drivers/tty/serial/8250/8250_aspeed_vuart.c
> @@ -82,7 +82,7 @@ static ssize_t lpc_address_show(struct device *dev,
>  	addr = (aspeed_vuart_readb(vuart, ASPEED_VUART_ADDRH) << 8) |
>  		(aspeed_vuart_readb(vuart, ASPEED_VUART_ADDRL));
>  
> -	return snprintf(buf, PAGE_SIZE - 1, "0x%x\n", addr);
> +	return sysfs_emit(buf - 1, "0x%x\n", addr);

what is the buf-1 thing here for?

Doing a tree-wide change for this type of thing might not be wanted by
many maintainers, especially if you introduce bugs like this :(

greg k-h

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

* 回复: [PATCH] tty: 8250: replace snprintf in show functions with sysfs_emit
       [not found] ` <AOQACwDzEi5UM3m3ezm-D4o5.9.1634281082401.Hmail.wangqing@vivo.com>
@ 2021-10-15  7:13   ` 王擎
  0 siblings, 0 replies; 3+ messages in thread
From: 王擎 @ 2021-10-15  7:13 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Jiri Slaby, Joel Stanley, Andrew Jeffery, linux-serial,
	linux-arm-kernel, linux-aspeed, linux-kernel


>> show() must not use snprintf() when formatting the value to be
>> returned to user space.
>
>Why must it not?  What is broken in the existing code?

Replyed in another email.

>
>> 
>> Fix the coccicheck warnings:
>> WARNING: use scnprintf or sprintf.
>> 
>> Signed-off-by: Qing Wang <wangqing@vivo.com>
>> ---
>>  drivers/tty/serial/8250/8250_aspeed_vuart.c | 6 +++---
>>  drivers/tty/serial/8250/8250_port.c         | 2 +-
>>  2 files changed, 4 insertions(+), 4 deletions(-)
>> 
>> diff --git a/drivers/tty/serial/8250/8250_aspeed_vuart.c b/drivers/tty/serial/8250/8250_aspeed_vuart.c
>> index 2350fb3..082b9bd 100644
>> --- a/drivers/tty/serial/8250/8250_aspeed_vuart.c
>> +++ b/drivers/tty/serial/8250/8250_aspeed_vuart.c
>> @@ -82,7 +82,7 @@ static ssize_t lpc_address_show(struct device *dev,
>>        addr = (aspeed_vuart_readb(vuart, ASPEED_VUART_ADDRH) << 8) |
>>                (aspeed_vuart_readb(vuart, ASPEED_VUART_ADDRL));
>>  
>> -     return snprintf(buf, PAGE_SIZE - 1, "0x%x\n", addr);
>> +     return sysfs_emit(buf - 1, "0x%x\n", addr);
>
>what is the buf-1 thing here for?
>
>Doing a tree-wide change for this type of thing might not be wanted by
>many maintainers, especially if you introduce bugs like this :(

Sorry for this, my tool needs to be optimized.
Please ignore this patch.

Thanks,

Qing
>
>greg k-h
>

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

end of thread, other threads:[~2021-10-15  7:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-15  6:51 [PATCH] tty: 8250: replace snprintf in show functions with sysfs_emit Qing Wang
2021-10-15  6:57 ` Greg Kroah-Hartman
     [not found] ` <AOQACwDzEi5UM3m3ezm-D4o5.9.1634281082401.Hmail.wangqing@vivo.com>
2021-10-15  7:13   ` 回复: " 王擎

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).