Skip to content

Commit b5056ec

Browse files
morimotogeertu
authored andcommitted
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 <[email protected]> Tested-by: Yusuke Goda <[email protected]> Reviewed-by: Rob Herring <[email protected]> Reviewed-by: Geert Uytterhoeven <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Geert Uytterhoeven <[email protected]>
1 parent 6613476 commit b5056ec

File tree

1 file changed

+36
-21
lines changed

1 file changed

+36
-21
lines changed

drivers/of/base.c

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -415,15 +415,8 @@ int of_machine_is_compatible(const char *compat)
415415
}
416416
EXPORT_SYMBOL(of_machine_is_compatible);
417417

418-
/**
419-
* __of_device_is_available - check if a device is available for use
420-
*
421-
* @device: Node to check for availability, with locks already held
422-
*
423-
* Return: True if the status property is absent or set to "okay" or "ok",
424-
* false otherwise
425-
*/
426-
static bool __of_device_is_available(const struct device_node *device)
418+
static bool __of_device_is_status(const struct device_node *device,
419+
const char * const*strings)
427420
{
428421
const char *status;
429422
int statlen;
@@ -433,16 +426,45 @@ static bool __of_device_is_available(const struct device_node *device)
433426

434427
status = __of_get_property(device, "status", &statlen);
435428
if (status == NULL)
436-
return true;
429+
return false;
437430

438431
if (statlen > 0) {
439-
if (!strcmp(status, "okay") || !strcmp(status, "ok"))
440-
return true;
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+
}
441444
}
442445

443446
return false;
444447
}
445448

449+
/**
450+
* __of_device_is_available - check if a device is available for use
451+
*
452+
* @device: Node to check for availability, with locks already held
453+
*
454+
* Return: True if the status property is absent or set to "okay" or "ok",
455+
* false otherwise
456+
*/
457+
static bool __of_device_is_available(const struct device_node *device)
458+
{
459+
static const char * const ok[] = {"okay", "ok", NULL};
460+
461+
if (!device)
462+
return false;
463+
464+
return !__of_get_property(device, "status", NULL) ||
465+
__of_device_is_status(device, ok);
466+
}
467+
446468
/**
447469
* of_device_is_available - check if a device is available for use
448470
*
@@ -474,16 +496,9 @@ EXPORT_SYMBOL(of_device_is_available);
474496
*/
475497
static bool __of_device_is_fail(const struct device_node *device)
476498
{
477-
const char *status;
478-
479-
if (!device)
480-
return false;
481-
482-
status = __of_get_property(device, "status", NULL);
483-
if (status == NULL)
484-
return false;
499+
static const char * const fail[] = {"fail", "fail-", NULL};
485500

486-
return !strcmp(status, "fail") || !strncmp(status, "fail-", 5);
501+
return __of_device_is_status(device, fail);
487502
}
488503

489504
/**

0 commit comments

Comments
 (0)