mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] net: can: replace snprintf in show functions with sysfs_emit
@ 2021-10-15  6:50 Qing Wang
  2021-10-17 10:18 ` Marc Kleine-Budde
  0 siblings, 1 reply; 2+ messages in thread
From: Qing Wang @ 2021-10-15  6:50 UTC (permalink / raw)
  To: Wolfgang Grandegger, Marc Kleine-Budde, David S. Miller,
	Jakub Kicinski, Nicolas Ferre, Alexandre Belloni,
	Ludovic Desroches, linux-can, netdev, linux-arm-kernel,
	linux-kernel
  Cc: Qing Wang

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

Fix the following coccicheck warning:
drivers/net/can/at91_can.c:1185: WARNING: use scnprintf or sprintf.
drivers/net/can/janz-ican3.c:1834: WARNING: use scnprintf or sprintf.

Use sysfs_emit instead of scnprintf or sprintf makes more sense.

Signed-off-by: Qing Wang <wangqing@vivo.com>
---
 drivers/net/can/at91_can.c   | 4 ++--
 drivers/net/can/janz-ican3.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/can/at91_can.c b/drivers/net/can/at91_can.c
index 04d0bb3..e4e754e 100644
--- a/drivers/net/can/at91_can.c
+++ b/drivers/net/can/at91_can.c
@@ -1182,9 +1182,9 @@ static ssize_t at91_sysfs_show_mb0_id(struct device *dev,
 	struct at91_priv *priv = netdev_priv(to_net_dev(dev));
 
 	if (priv->mb0_id & CAN_EFF_FLAG)
-		return snprintf(buf, PAGE_SIZE, "0x%08x\n", priv->mb0_id);
+		return sysfs_emit(buf, "0x%08x\n", priv->mb0_id);
 	else
-		return snprintf(buf, PAGE_SIZE, "0x%03x\n", priv->mb0_id);
+		return sysfs_emit(buf, "0x%03x\n", priv->mb0_id);
 }
 
 static ssize_t at91_sysfs_set_mb0_id(struct device *dev,
diff --git a/drivers/net/can/janz-ican3.c b/drivers/net/can/janz-ican3.c
index 2a6c918..feedc13 100644
--- a/drivers/net/can/janz-ican3.c
+++ b/drivers/net/can/janz-ican3.c
@@ -1831,7 +1831,7 @@ static ssize_t ican3_sysfs_show_term(struct device *dev,
 		return -ETIMEDOUT;
 	}
 
-	return snprintf(buf, PAGE_SIZE, "%u\n", mod->termination_enabled);
+	return sysfs_emit(buf, "%u\n", mod->termination_enabled);
 }
 
 static ssize_t ican3_sysfs_set_term(struct device *dev,
-- 
2.7.4


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

* Re: [PATCH] net: can: replace snprintf in show functions with sysfs_emit
  2021-10-15  6:50 [PATCH] net: can: replace snprintf in show functions with sysfs_emit Qing Wang
@ 2021-10-17 10:18 ` Marc Kleine-Budde
  0 siblings, 0 replies; 2+ messages in thread
From: Marc Kleine-Budde @ 2021-10-17 10:18 UTC (permalink / raw)
  To: Qing Wang
  Cc: Wolfgang Grandegger, David S. Miller, Jakub Kicinski,
	Nicolas Ferre, Alexandre Belloni, Ludovic Desroches, linux-can,
	netdev, linux-arm-kernel, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 772 bytes --]

On 14.10.2021 23:50:24, Qing Wang wrote:
> show() must not use snprintf() when formatting the value to be
> returned to user space.
> 
> Fix the following coccicheck warning:
> drivers/net/can/at91_can.c:1185: WARNING: use scnprintf or sprintf.
> drivers/net/can/janz-ican3.c:1834: WARNING: use scnprintf or sprintf.
> 
> Use sysfs_emit instead of scnprintf or sprintf makes more sense.
> 
> Signed-off-by: Qing Wang <wangqing@vivo.com>

Added to linux-can-next/testing.

Thanks,
Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

end of thread, other threads:[~2021-10-17 10:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-15  6:50 [PATCH] net: can: replace snprintf in show functions with sysfs_emit Qing Wang
2021-10-17 10:18 ` Marc Kleine-Budde

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®