From: Yu Watanabe Date: Thu, 18 Feb 2021 08:25:51 +0000 (+0900) Subject: sd-device: move comment about NULL value X-Git-Tag: v248-rc1~19^2~18 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2f7a2e395267138f5279e3e53d24413157663559;p=thirdparty%2Fsystemd.git sd-device: move comment about NULL value It is not intuitive, and I do not know why the function behave so. But let's keep that behavior for compatibility, as such behavior may be already used explicitly by callers. --- diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c index a05e7f8d0bc..cc0220b04e3 100644 --- a/src/libsystemd/sd-device/sd-device.c +++ b/src/libsystemd/sd-device/sd-device.c @@ -1946,8 +1946,6 @@ static void device_remove_cached_sysattr_value(sd_device *device, const char *_k free(hashmap_remove2(device->sysattr_values, _key, (void **) &key)); } -/* set the attribute and save it in the cache. If a NULL value is passed the - * attribute is cleared from the cache */ _public_ int sd_device_set_sysattr_value(sd_device *device, const char *sysattr, const char *_value) { _cleanup_free_ char *value = NULL; const char *syspath, *path; @@ -1957,7 +1955,10 @@ _public_ int sd_device_set_sysattr_value(sd_device *device, const char *sysattr, assert_return(device, -EINVAL); assert_return(sysattr, -EINVAL); + /* Set the attribute and save it in the cache. */ + if (!_value) { + /* If input value is NULL, then clear cache and not write anything. */ device_remove_cached_sysattr_value(device, sysattr); return 0; }