dm: core: of_access: fix return value in of_property_match_string
authorEugen Hristev <eugen.hristev@collabora.com>
Thu, 4 May 2023 12:22:21 +0000 (15:22 +0300)
committerSimon Glass <sjg@chromium.org>
Thu, 20 Jul 2023 20:10:57 +0000 (14:10 -0600)
commit15a2865515fdd77d1edbc10e275b7b5a4914aa79
tree13ee35f34a90e32a5439a7b16ef6f425ec72afa9
parent0274eb61e1f2a8e053fb028b6c668c67c0b75b9c
dm: core: of_access: fix return value in of_property_match_string

of_property_match_string calls of_find_property to search for the
string property.
If the device node does not exist, of_find_property returns NULL, and
of_property_match_string returns -EINVAL, which is correct.
However, if the device node exists, but the property is not found,
of_find_property still returns NULL, but it will place -FDT_ERR_NOTFOUND
in the *lenp variable.
of_property_match_string does not use the lenp parameter, thus this error
case is being lost, and treated as if the node is NULL, and returns
-EINVAL, which is incorrect.

The callers of of_property_match_string treat the error differently if
the return value is -EINVAL or -ENOENT, e.g. in dwc3 driver:

ret = generic_phy_get_by_name(dev, "usb3-phy", &phy);
if (!ret) {
ret = generic_phy_init(&phy);
if (ret)
return ret;
} else if (ret != -ENOENT && ret != -ENODATA) {
debug("could not get phy (err %d)\n", ret);
return ret;
} else {
phy.dev = NULL;
}

So the caller drivers will just consider the property missing if -ENOENT
is returned, versus the case of -EINVAL, which means something else.

To fix this situation, changed the code to call the of_find_property
with the right third argument to catch this error code and treat it
accordingly.

Signed-off-by: Eugen Hristev <eugen.hristev@collabora.com>
drivers/core/of_access.c