Skip to content

Commit c8f80f9

Browse files
tobluxmaddy-kerneldev
authored andcommitted
powerpc/pseries/lparcfg: Replace deprecated strcpy in parse_system_parameter_string
strcpy() is deprecated; use strscpy() instead. Use the return value of strscpy() instead of calling strlen() again, and ignore any potential string truncation since both strings are much shorter than the buffer size SPLPAR_MAXLENGTH. Change both if conditions to silence the following checkpatch warnings: Comparisons should place the constant on the right side of the test Link: KSPP/linux#88 Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev> Signed-off-by: Madhavan Srinivasan <maddy@linux.ibm.com> Link: https://patch.msgid.link/20251013135703.97260-2-thorsten.blum@linux.dev
1 parent 457cf3d commit c8f80f9

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

arch/powerpc/platforms/pseries/lparcfg.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <asm/papr-sysparm.h>
2323
#include <linux/seq_file.h>
2424
#include <linux/slab.h>
25+
#include <linux/string.h>
2526
#include <linux/uaccess.h>
2627
#include <linux/hugetlb.h>
2728
#include <asm/lppaca.h>
@@ -431,17 +432,18 @@ static void parse_system_parameter_string(struct seq_file *m)
431432
w_idx = 0;
432433
} else if (local_buffer[idx] == '=') {
433434
/* code here to replace workbuffer contents
434-
with different keyword strings */
435-
if (0 == strcmp(workbuffer, "MaxEntCap")) {
436-
strcpy(workbuffer,
437-
"partition_max_entitled_capacity");
438-
w_idx = strlen(workbuffer);
439-
}
440-
if (0 == strcmp(workbuffer, "MaxPlatProcs")) {
441-
strcpy(workbuffer,
442-
"system_potential_processors");
443-
w_idx = strlen(workbuffer);
444-
}
435+
* with different keyword strings. Truncation
436+
* by strscpy is deliberately ignored because
437+
* SPLPAR_MAXLENGTH >= maximum string size.
438+
*/
439+
if (!strcmp(workbuffer, "MaxEntCap"))
440+
w_idx = strscpy(workbuffer,
441+
"partition_max_entitled_capacity",
442+
SPLPAR_MAXLENGTH);
443+
if (!strcmp(workbuffer, "MaxPlatProcs"))
444+
w_idx = strscpy(workbuffer,
445+
"system_potential_processors",
446+
SPLPAR_MAXLENGTH);
445447
}
446448
}
447449
kfree(workbuffer);

0 commit comments

Comments
 (0)