|
|
62f653 |
commit 09d7031cb462889392090e71991a89c522d387bc
|
|
|
62f653 |
Author: Lee Duncan <lduncan@suse.com>
|
|
|
62f653 |
Date: Mon Sep 24 16:37:19 2018 -0700
|
|
|
62f653 |
|
|
|
62f653 |
Fix reading of sysfs signed integers when negative.
|
|
|
62f653 |
|
|
|
62f653 |
The code for reading all sysfs integer types (of all
|
|
|
62f653 |
sizes) did not work when reading signed integers and
|
|
|
62f653 |
the return value was negative. So when the default was -1
|
|
|
62f653 |
and the value was not present, the code tried to return -1.
|
|
|
62f653 |
But the logic for checking against "max value" was
|
|
|
62f653 |
incorrect, causing INT_MAX to be returned instead of -1.
|
|
|
62f653 |
---
|
|
|
62f653 |
libopeniscsiusr/sysfs.c | 32 +++++++++++++++++++++++++++-----
|
|
|
62f653 |
1 file changed, 27 insertions(+), 5 deletions(-)
|
|
|
62f653 |
|
|
|
62f653 |
diff --git a/libopeniscsiusr/sysfs.c b/libopeniscsiusr/sysfs.c
|
|
|
62f653 |
index 08f71b317c55..c4f89a31aca0 100644
|
|
|
62f653 |
--- a/libopeniscsiusr/sysfs.c
|
|
|
62f653 |
+++ b/libopeniscsiusr/sysfs.c
|
|
|
62f653 |
@@ -47,7 +47,7 @@
|
|
|
62f653 |
|
|
|
62f653 |
#define _SYS_NULL_STR "(null)"
|
|
|
62f653 |
|
|
|
62f653 |
-#define _sysfs_prop_get_int_func_gen(func_name, out_type, type_max_value) \
|
|
|
62f653 |
+#define _sysfs_prop_get_uint_func_gen(func_name, out_type, type_max_value) \
|
|
|
62f653 |
int func_name(struct iscsi_context *ctx, const char *dir_path, \
|
|
|
62f653 |
const char *prop_name, out_type *val, \
|
|
|
62f653 |
out_type default_value, bool ignore_error) \
|
|
|
62f653 |
@@ -63,6 +63,28 @@
|
|
|
62f653 |
return rc; \
|
|
|
62f653 |
}
|
|
|
62f653 |
|
|
|
62f653 |
+#define _sysfs_prop_get_int_func_gen(func_name, out_type, type_min_value, type_max_value) \
|
|
|
62f653 |
+ int func_name(struct iscsi_context *ctx, const char *dir_path, \
|
|
|
62f653 |
+ const char *prop_name, out_type *val, \
|
|
|
62f653 |
+ out_type default_value, bool ignore_error) \
|
|
|
62f653 |
+ { \
|
|
|
62f653 |
+ long long int tmp_val = 0; \
|
|
|
62f653 |
+ int rc = LIBISCSI_OK; \
|
|
|
62f653 |
+ long long int dv = default_value; \
|
|
|
62f653 |
+ rc = iscsi_sysfs_prop_get_ll(ctx, dir_path, prop_name, \
|
|
|
62f653 |
+ &tmp_val, (long long int) dv, \
|
|
|
62f653 |
+ ignore_error); \
|
|
|
62f653 |
+ if (rc == LIBISCSI_OK) { \
|
|
|
62f653 |
+ if (tmp_val > type_max_value) \
|
|
|
62f653 |
+ *val = type_max_value; \
|
|
|
62f653 |
+ else if (tmp_val < type_min_value) \
|
|
|
62f653 |
+ *val = type_min_value; \
|
|
|
62f653 |
+ else \
|
|
|
62f653 |
+ *val = tmp_val; \
|
|
|
62f653 |
+ } \
|
|
|
62f653 |
+ return rc; \
|
|
|
62f653 |
+ }
|
|
|
62f653 |
+
|
|
|
62f653 |
|
|
|
62f653 |
enum _sysfs_dev_class {
|
|
|
62f653 |
_SYSFS_DEV_CLASS_ISCSI_SESSION,
|
|
|
62f653 |
@@ -82,10 +104,10 @@ static int iscsi_sysfs_prop_get_ll(struct iscsi_context *ctx,
|
|
|
62f653 |
static int sysfs_get_dev_path(struct iscsi_context *ctx, const char *path,
|
|
|
62f653 |
enum _sysfs_dev_class class, char **dev_path);
|
|
|
62f653 |
|
|
|
62f653 |
-_sysfs_prop_get_int_func_gen(_sysfs_prop_get_u8, uint8_t, UINT8_MAX);
|
|
|
62f653 |
-_sysfs_prop_get_int_func_gen(_sysfs_prop_get_u16, uint16_t, UINT16_MAX);
|
|
|
62f653 |
-_sysfs_prop_get_int_func_gen(_sysfs_prop_get_i32, int32_t, INT32_MAX);
|
|
|
62f653 |
-_sysfs_prop_get_int_func_gen(_sysfs_prop_get_u32, uint32_t, UINT32_MAX);
|
|
|
62f653 |
+_sysfs_prop_get_uint_func_gen(_sysfs_prop_get_u8, uint8_t, UINT8_MAX);
|
|
|
62f653 |
+_sysfs_prop_get_uint_func_gen(_sysfs_prop_get_u16, uint16_t, UINT16_MAX);
|
|
|
62f653 |
+_sysfs_prop_get_int_func_gen(_sysfs_prop_get_i32, int32_t, INT32_MIN, INT32_MAX);
|
|
|
62f653 |
+_sysfs_prop_get_uint_func_gen(_sysfs_prop_get_u32, uint32_t, UINT32_MAX);
|
|
|
62f653 |
|
|
|
62f653 |
static int sysfs_read_file(const char *path, uint8_t *buff, size_t buff_size)
|
|
|
62f653 |
{
|