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

power: supply: test-power: revise parameter printing to use sprintf

Simplify code by using sprintf instead of strcpy+strcat+strlen.

Signed-off-by: Harley A.W. Lorenzo <hl1998@protonmail.com>
Suggested-by: Joe Perches <joe@perches.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>

authored by

Harley A.W. Lorenzo and committed by
Sebastian Reichel
411643e9 10a4357f

+13 -19
+13 -19
drivers/power/supply/test_power.c
··· 352 352 353 353 static int param_get_ac_online(char *buffer, const struct kernel_param *kp) 354 354 { 355 - strcpy(buffer, map_get_key(map_ac_online, ac_online, "unknown")); 356 - strcat(buffer, "\n"); 357 - return strlen(buffer); 355 + return sprintf(buffer, "%s\n", 356 + map_get_key(map_ac_online, ac_online, "unknown")); 358 357 } 359 358 360 359 static int param_set_usb_online(const char *key, const struct kernel_param *kp) ··· 365 366 366 367 static int param_get_usb_online(char *buffer, const struct kernel_param *kp) 367 368 { 368 - strcpy(buffer, map_get_key(map_ac_online, usb_online, "unknown")); 369 - strcat(buffer, "\n"); 370 - return strlen(buffer); 369 + return sprintf(buffer, "%s\n", 370 + map_get_key(map_ac_online, usb_online, "unknown")); 371 371 } 372 372 373 373 static int param_set_battery_status(const char *key, ··· 379 381 380 382 static int param_get_battery_status(char *buffer, const struct kernel_param *kp) 381 383 { 382 - strcpy(buffer, map_get_key(map_status, battery_status, "unknown")); 383 - strcat(buffer, "\n"); 384 - return strlen(buffer); 384 + return sprintf(buffer, "%s\n", 385 + map_get_key(map_ac_online, battery_status, "unknown")); 385 386 } 386 387 387 388 static int param_set_battery_health(const char *key, ··· 393 396 394 397 static int param_get_battery_health(char *buffer, const struct kernel_param *kp) 395 398 { 396 - strcpy(buffer, map_get_key(map_health, battery_health, "unknown")); 397 - strcat(buffer, "\n"); 398 - return strlen(buffer); 399 + return sprintf(buffer, "%s\n", 400 + map_get_key(map_ac_online, battery_health, "unknown")); 399 401 } 400 402 401 403 static int param_set_battery_present(const char *key, ··· 408 412 static int param_get_battery_present(char *buffer, 409 413 const struct kernel_param *kp) 410 414 { 411 - strcpy(buffer, map_get_key(map_present, battery_present, "unknown")); 412 - strcat(buffer, "\n"); 413 - return strlen(buffer); 415 + return sprintf(buffer, "%s\n", 416 + map_get_key(map_ac_online, battery_present, "unknown")); 414 417 } 415 418 416 419 static int param_set_battery_technology(const char *key, ··· 424 429 static int param_get_battery_technology(char *buffer, 425 430 const struct kernel_param *kp) 426 431 { 427 - strcpy(buffer, 428 - map_get_key(map_technology, battery_technology, "unknown")); 429 - strcat(buffer, "\n"); 430 - return strlen(buffer); 432 + return sprintf(buffer, "%s\n", 433 + map_get_key(map_ac_online, battery_technology, 434 + "unknown")); 431 435 } 432 436 433 437 static int param_set_battery_capacity(const char *key,