mirror of
https://github.com/torvalds/linux.git
synced 2024-09-20 15:03:04 +00:00
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>
This commit is contained in:
parent
6613476e22
commit
b5056ecf7c
|
@ -415,6 +415,37 @@ int of_machine_is_compatible(const char *compat)
|
|||
}
|
||||
EXPORT_SYMBOL(of_machine_is_compatible);
|
||||
|
||||
static bool __of_device_is_status(const struct device_node *device,
|
||||
const char * const*strings)
|
||||
{
|
||||
const char *status;
|
||||
int statlen;
|
||||
|
||||
if (!device)
|
||||
return false;
|
||||
|
||||
status = __of_get_property(device, "status", &statlen);
|
||||
if (status == NULL)
|
||||
return false;
|
||||
|
||||
if (statlen > 0) {
|
||||
while (*strings) {
|
||||
unsigned int len = strlen(*strings);
|
||||
|
||||
if ((*strings)[len - 1] == '-') {
|
||||
if (!strncmp(status, *strings, len))
|
||||
return true;
|
||||
} else {
|
||||
if (!strcmp(status, *strings))
|
||||
return true;
|
||||
}
|
||||
strings++;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* __of_device_is_available - check if a device is available for use
|
||||
*
|
||||
|
@ -425,22 +456,13 @@ EXPORT_SYMBOL(of_machine_is_compatible);
|
|||
*/
|
||||
static bool __of_device_is_available(const struct device_node *device)
|
||||
{
|
||||
const char *status;
|
||||
int statlen;
|
||||
static const char * const ok[] = {"okay", "ok", NULL};
|
||||
|
||||
if (!device)
|
||||
return false;
|
||||
|
||||
status = __of_get_property(device, "status", &statlen);
|
||||
if (status == NULL)
|
||||
return true;
|
||||
|
||||
if (statlen > 0) {
|
||||
if (!strcmp(status, "okay") || !strcmp(status, "ok"))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return !__of_get_property(device, "status", NULL) ||
|
||||
__of_device_is_status(device, ok);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -474,16 +496,9 @@ EXPORT_SYMBOL(of_device_is_available);
|
|||
*/
|
||||
static bool __of_device_is_fail(const struct device_node *device)
|
||||
{
|
||||
const char *status;
|
||||
static const char * const fail[] = {"fail", "fail-", NULL};
|
||||
|
||||
if (!device)
|
||||
return false;
|
||||
|
||||
status = __of_get_property(device, "status", NULL);
|
||||
if (status == NULL)
|
||||
return false;
|
||||
|
||||
return !strcmp(status, "fail") || !strncmp(status, "fail-", 5);
|
||||
return __of_device_is_status(device, fail);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue
Block a user