From: Paweł Szewczyk
Date: Wed, 28 Feb 2018 15:08:21 +0000 (+0100)
Subject: Fix getting ints from sysfs
X-Git-Tag: accepted/tizen/unified/20180412.073814~7
X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bcc3c85eaa16bda6436549c82ae24e600fed9d18;p=platform%2Fadaptation%2Fsamsung_exynos%2Fdevice-manager-plugin-artik.git
Fix getting ints from sysfs
Some integers are represented in hex, without leading 0x.
Change-Id: If6b950a24496eae52a34623b2fa9735390e26795
Signed-off-by: Paweł Szewczyk
---
diff --git a/hw/usb_client/usb_client.c b/hw/usb_client/usb_client.c
index f7faa5b..f8bdd3a 100644
--- a/hw/usb_client/usb_client.c
+++ b/hw/usb_client/usb_client.c
@@ -119,7 +119,7 @@ static int systemd_stop_service(const char *service_name)
return systemd_unit_interface("StopUnit", unit);
}
-static int get_int_from_file(char *path, int *_val)
+static int get_int_from_file(char *path, int *_val, int base)
{
char buf[INT_BUF_SIZE];
char *endptr;
@@ -130,7 +130,7 @@ static int get_int_from_file(char *path, int *_val)
if (ret)
return ret;
- val = strtol(buf, &endptr, 0);
+ val = strtol(buf, &endptr, base);
if (val == LONG_MIN || val == LONG_MAX ||
buf[0] == '\0' || (*endptr != '\0' && *endptr != '\n')
|| val > INT_MAX)
@@ -145,21 +145,21 @@ static int legacy_read_gadget_attrs_strs(struct usb_gadget *gadget)
int val;
int ret;
/* We assume that values received from kernel will be valid */
-#define GET_VALUE_FROM_SYSFS(path, field, type) \
+#define GET_VALUE_FROM_SYSFS(path, field, type, base) \
do { \
- ret = get_int_from_file(path, &val); \
+ ret = get_int_from_file(path, &val, base); \
if (ret) \
return ret; \
\
gadget->attrs.field = (type)val; \
} while (0)
- GET_VALUE_FROM_SYSFS(LEGACY_CLASS_PATH, bDeviceClass, uint8_t);
- GET_VALUE_FROM_SYSFS(LEGACY_SUBCLASS_PATH, bDeviceSubClass, uint8_t);
- GET_VALUE_FROM_SYSFS(LEGACY_PROTOCOL_PATH, bDeviceProtocol, uint8_t);
- GET_VALUE_FROM_SYSFS(LEGACY_ID_VENDOR_PATH, idVendor, uint16_t);
- GET_VALUE_FROM_SYSFS(LEGACY_ID_PRODUCT_PATH, idVendor, uint16_t);
- GET_VALUE_FROM_SYSFS(LEGACY_BCD_DEVICE_PATH, bcdDevice, uint16_t);
+ GET_VALUE_FROM_SYSFS(LEGACY_CLASS_PATH, bDeviceClass, uint8_t, 0);
+ GET_VALUE_FROM_SYSFS(LEGACY_SUBCLASS_PATH, bDeviceSubClass, uint8_t, 0);
+ GET_VALUE_FROM_SYSFS(LEGACY_PROTOCOL_PATH, bDeviceProtocol, uint8_t, 0);
+ GET_VALUE_FROM_SYSFS(LEGACY_ID_VENDOR_PATH, idVendor, uint16_t, 16);
+ GET_VALUE_FROM_SYSFS(LEGACY_ID_PRODUCT_PATH, idProduct, uint16_t, 16);
+ GET_VALUE_FROM_SYSFS(LEGACY_BCD_DEVICE_PATH, bcdDevice, uint16_t, 0);
#undef GET_VALUE_FROM_SYSFS
#define GET_STRING_FROM_SYSFS(path, field) \