Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

s390/ipl: Rename and change strncpy_skip_quote()

Rename strncpy_skip_quote() to strscpy_skip_quote() and change its
implementation so that the destination string is always NUL terminated.

Signed-off-by: Heiko Carstens <hca@linux.ibm.com>

+12 -13
+12 -13
arch/s390/kernel/ipl.c
··· 2249 2249 2250 2250 __initcall(s390_ipl_init); 2251 2251 2252 - static void __init strncpy_skip_quote(char *dst, char *src, int n) 2252 + static void __init strscpy_skip_quote(char *dst, char *src, int n) 2253 2253 { 2254 2254 int sx, dx; 2255 2255 2256 - dx = 0; 2257 - for (sx = 0; src[sx] != 0; sx++) { 2256 + if (!n) 2257 + return; 2258 + for (sx = 0, dx = 0; src[sx]; sx++) { 2258 2259 if (src[sx] == '"') 2259 2260 continue; 2260 - dst[dx++] = src[sx]; 2261 - if (dx >= n) 2261 + dst[dx] = src[sx]; 2262 + if (dx + 1 == n) 2262 2263 break; 2264 + dx++; 2263 2265 } 2266 + dst[dx] = '\0'; 2264 2267 } 2265 2268 2266 2269 static int __init vmcmd_on_reboot_setup(char *str) 2267 2270 { 2268 2271 if (!machine_is_vm()) 2269 2272 return 1; 2270 - strncpy_skip_quote(vmcmd_on_reboot, str, VMCMD_MAX_SIZE); 2271 - vmcmd_on_reboot[VMCMD_MAX_SIZE] = 0; 2273 + strscpy_skip_quote(vmcmd_on_reboot, str, sizeof(vmcmd_on_reboot)); 2272 2274 on_reboot_trigger.action = &vmcmd_action; 2273 2275 return 1; 2274 2276 } ··· 2280 2278 { 2281 2279 if (!machine_is_vm()) 2282 2280 return 1; 2283 - strncpy_skip_quote(vmcmd_on_panic, str, VMCMD_MAX_SIZE); 2284 - vmcmd_on_panic[VMCMD_MAX_SIZE] = 0; 2281 + strscpy_skip_quote(vmcmd_on_panic, str, sizeof(vmcmd_on_panic)); 2285 2282 on_panic_trigger.action = &vmcmd_action; 2286 2283 return 1; 2287 2284 } ··· 2290 2289 { 2291 2290 if (!machine_is_vm()) 2292 2291 return 1; 2293 - strncpy_skip_quote(vmcmd_on_halt, str, VMCMD_MAX_SIZE); 2294 - vmcmd_on_halt[VMCMD_MAX_SIZE] = 0; 2292 + strscpy_skip_quote(vmcmd_on_halt, str, sizeof(vmcmd_on_halt)); 2295 2293 on_halt_trigger.action = &vmcmd_action; 2296 2294 return 1; 2297 2295 } ··· 2300 2300 { 2301 2301 if (!machine_is_vm()) 2302 2302 return 1; 2303 - strncpy_skip_quote(vmcmd_on_poff, str, VMCMD_MAX_SIZE); 2304 - vmcmd_on_poff[VMCMD_MAX_SIZE] = 0; 2303 + strscpy_skip_quote(vmcmd_on_poff, str, sizeof(vmcmd_on_poff)); 2305 2304 on_poff_trigger.action = &vmcmd_action; 2306 2305 return 1; 2307 2306 }