lkml.org 
[lkml]   [2021]   [Oct]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] tty: 8250: replace snprintf in show functions with sysfs_emit
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

\
 
 \ /
  Last update: 2021-10-15 08:58    [W:0.100 / U:0.112 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site