return 0;
}
-static int device_get_cached_sysattr_value(sd_device *device, const char *_key, const char **_value) {
- const char *key = NULL, *value;
+static int device_get_cached_sysattr_value(sd_device *device, const char *key, const char **ret_value) {
+ const char *k = NULL, *value;
assert(device);
- assert(_key);
-
- value = hashmap_get2(device->sysattr_values, _key, (void **) &key);
- if (!key)
- return -ENOENT;
+ assert(key);
- if (_value)
- *_value = value;
+ value = hashmap_get2(device->sysattr_values, key, (void **) &k);
+ if (!k)
+ return -ENODATA; /* We have not read the attribute. */
+ if (!value)
+ return -ENOENT; /* We have looked up the attribute before and it did not exist. */
+ if (ret_value)
+ *ret_value = value;
return 0;
}
* with a NULL value in the cache, otherwise the returned string is stored */
_public_ int sd_device_get_sysattr_value(sd_device *device, const char *sysattr, const char **ret_value) {
_cleanup_free_ char *value = NULL;
- const char *path, *syspath, *cached_value = NULL;
+ const char *path, *syspath;
struct stat statbuf;
int r;
assert_return(sysattr, -EINVAL);
/* look for possibly already cached result */
- r = device_get_cached_sysattr_value(device, sysattr, &cached_value);
- if (r != -ENOENT) {
- if (r < 0)
- return r;
-
- if (!cached_value)
- /* we looked up the sysattr before and it did not exist */
- return -ENOENT;
-
- if (ret_value)
- *ret_value = cached_value;
-
- return 0;
- }
+ r = device_get_cached_sysattr_value(device, sysattr, ret_value);
+ if (r != -ENODATA)
+ return r;
r = sd_device_get_syspath(device, &syspath);
if (r < 0)