linux-alpha.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] alpha: move from strlcpy with unused retval to strscpy
@ 2022-08-18 20:59 Wolfram Sang
  2022-08-18 23:40 ` Joe Perches
  0 siblings, 1 reply; 3+ messages in thread
From: Wolfram Sang @ 2022-08-18 20:59 UTC (permalink / raw)
  To: linux-kernel
  Cc: Wolfram Sang, Richard Henderson, Ivan Kokshaysky, Matt Turner,
	linux-alpha

Follow the advice of the below link and prefer 'strscpy' in this
subsystem. Conversion is 1:1 because the return value is not used.
Generated by a coccinelle script.

Link: https://lore.kernel.org/r/CAHk-=wgfRnXz0W3D37d01q3JFkr_i_uTL=V6A6G1oUZcprmknw@mail.gmail.com/
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
 arch/alpha/kernel/setup.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/alpha/kernel/setup.c b/arch/alpha/kernel/setup.c
index b4fbbba30aa2..33bf3a627002 100644
--- a/arch/alpha/kernel/setup.c
+++ b/arch/alpha/kernel/setup.c
@@ -491,9 +491,9 @@ setup_arch(char **cmdline_p)
 	   boot flags depending on the boot mode, we need some shorthand.
 	   This should do for installation.  */
 	if (strcmp(COMMAND_LINE, "INSTALL") == 0) {
-		strlcpy(command_line, "root=/dev/fd0 load_ramdisk=1", sizeof command_line);
+		strscpy(command_line, "root=/dev/fd0 load_ramdisk=1", sizeof(command_line));
 	} else {
-		strlcpy(command_line, COMMAND_LINE, sizeof command_line);
+		strscpy(command_line, COMMAND_LINE, sizeof(command_line));
 	}
 	strcpy(boot_command_line, command_line);
 	*cmdline_p = command_line;
-- 
2.35.1


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

* Re: [PATCH] alpha: move from strlcpy with unused retval to strscpy
  2022-08-18 20:59 [PATCH] alpha: move from strlcpy with unused retval to strscpy Wolfram Sang
@ 2022-08-18 23:40 ` Joe Perches
  2022-08-19  5:37   ` Wolfram Sang
  0 siblings, 1 reply; 3+ messages in thread
From: Joe Perches @ 2022-08-18 23:40 UTC (permalink / raw)
  To: Wolfram Sang, linux-kernel
  Cc: Richard Henderson, Ivan Kokshaysky, Matt Turner, linux-alpha,
	Julia Lawall

On Thu, 2022-08-18 at 22:59 +0200, Wolfram Sang wrote:
> Follow the advice of the below link and prefer 'strscpy' in this
> subsystem. Conversion is 1:1 because the return value is not used.
> Generated by a coccinelle script.

Nice.

Last time I posted a coccinelle script for strlcpy->strscpy conversions
with unused returns, there were several variants that were not converted.

https://lore.kernel.org/cocci/a3279a5772b2e49b57890cd75e97360b82890798.camel@perches.com/T/#m502108bfe0cc6a41d499a4c1b55d5f5db1423465

Did you post the script you used?


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

* Re: [PATCH] alpha: move from strlcpy with unused retval to strscpy
  2022-08-18 23:40 ` Joe Perches
@ 2022-08-19  5:37   ` Wolfram Sang
  0 siblings, 0 replies; 3+ messages in thread
From: Wolfram Sang @ 2022-08-19  5:37 UTC (permalink / raw)
  To: Joe Perches
  Cc: linux-kernel, Richard Henderson, Ivan Kokshaysky, Matt Turner,
	linux-alpha, Julia Lawall

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

Hi Joe,

Glad you like this series.

> Last time I posted a coccinelle script for strlcpy->strscpy conversions
> with unused returns, there were several variants that were not converted.
> 
> https://lore.kernel.org/cocci/a3279a5772b2e49b57890cd75e97360b82890798.camel@perches.com/T/#m502108bfe0cc6a41d499a4c1b55d5f5db1423465
> 
> Did you post the script you used?

First version here, very similar to yours:

https://lore.kernel.org/all/YvhXzarjOLEJ8nsW@shikoro/

The final version has another rule to add missing parens to the argument
of a sizeof operator:

@ main @
@@
- strlcpy
+ strscpy
  (...);

// make sure sizeof always has parens. Isomorphs will remove existing ones if present before.
@ add_parens depends on main @
expression dst, src, E;
@@
  strscpy(dst, src,
- sizeof(E)
+ sizeof(E)
  );

Like your try, some header files are missing. I guess Julia's remarks
about that from the thread above will fix this as well. However, since
there are the instances left where the return value of strlcpy is used
anyhow, I left those for manual fixing.

Thanks,

   Wolfram


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

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

end of thread, other threads:[~2022-08-19  5:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-18 20:59 [PATCH] alpha: move from strlcpy with unused retval to strscpy Wolfram Sang
2022-08-18 23:40 ` Joe Perches
2022-08-19  5:37   ` Wolfram Sang

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