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

Configure Feed

Select the types of activity you want to include in your feed.

of: Add __of_device_is_status() and makes more generic status check

Linux Kernel has __of_device_is_available() / __of_device_is_fail(),
these are checking if the status was "okay" / "ok" / "fail" / "fail-".

Add more generic __of_device_is_status() function for these.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Tested-by: Yusuke Goda <yusuke.goda.sx@renesas.com>
Reviewed-by: Rob Herring <robh@kernel.org>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Link: https://lore.kernel.org/r/87cyuagfba.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>

authored by

Kuninori Morimoto and committed by
Geert Uytterhoeven
b5056ecf 6613476e

+36 -21
+36 -21
drivers/of/base.c
··· 415 415 } 416 416 EXPORT_SYMBOL(of_machine_is_compatible); 417 417 418 + static bool __of_device_is_status(const struct device_node *device, 419 + const char * const*strings) 420 + { 421 + const char *status; 422 + int statlen; 423 + 424 + if (!device) 425 + return false; 426 + 427 + status = __of_get_property(device, "status", &statlen); 428 + if (status == NULL) 429 + return false; 430 + 431 + if (statlen > 0) { 432 + while (*strings) { 433 + unsigned int len = strlen(*strings); 434 + 435 + if ((*strings)[len - 1] == '-') { 436 + if (!strncmp(status, *strings, len)) 437 + return true; 438 + } else { 439 + if (!strcmp(status, *strings)) 440 + return true; 441 + } 442 + strings++; 443 + } 444 + } 445 + 446 + return false; 447 + } 448 + 418 449 /** 419 450 * __of_device_is_available - check if a device is available for use 420 451 * ··· 456 425 */ 457 426 static bool __of_device_is_available(const struct device_node *device) 458 427 { 459 - const char *status; 460 - int statlen; 428 + static const char * const ok[] = {"okay", "ok", NULL}; 461 429 462 430 if (!device) 463 431 return false; 464 432 465 - status = __of_get_property(device, "status", &statlen); 466 - if (status == NULL) 467 - return true; 468 - 469 - if (statlen > 0) { 470 - if (!strcmp(status, "okay") || !strcmp(status, "ok")) 471 - return true; 472 - } 473 - 474 - return false; 433 + return !__of_get_property(device, "status", NULL) || 434 + __of_device_is_status(device, ok); 475 435 } 476 436 477 437 /** ··· 496 474 */ 497 475 static bool __of_device_is_fail(const struct device_node *device) 498 476 { 499 - const char *status; 477 + static const char * const fail[] = {"fail", "fail-", NULL}; 500 478 501 - if (!device) 502 - return false; 503 - 504 - status = __of_get_property(device, "status", NULL); 505 - if (status == NULL) 506 - return false; 507 - 508 - return !strcmp(status, "fail") || !strncmp(status, "fail-", 5); 479 + return __of_device_is_status(device, fail); 509 480 } 510 481 511 482 /**