summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaweł Szewczyk <p.szewczyk@samsung.com>2018-02-28 16:08:21 +0100
committerPaweł Szewczyk <p.szewczyk@samsung.com>2018-04-06 15:53:31 +0200
commitbcc3c85eaa16bda6436549c82ae24e600fed9d18 (patch)
treeabcf996654883b68e92c02a1624e651289ba77d9
parentcff3351ada383ec96caccb70b2097df2c57fe6d4 (diff)
downloaddevice-manager-plugin-artik-bcc3c85eaa16bda6436549c82ae24e600fed9d18.tar.gz
device-manager-plugin-artik-bcc3c85eaa16bda6436549c82ae24e600fed9d18.tar.bz2
device-manager-plugin-artik-bcc3c85eaa16bda6436549c82ae24e600fed9d18.zip
Fix getting ints from sysfs
Some integers are represented in hex, without leading 0x. Change-Id: If6b950a24496eae52a34623b2fa9735390e26795 Signed-off-by: Paweł Szewczyk <p.szewczyk@samsung.com>
-rw-r--r--hw/usb_client/usb_client.c20
1 files changed, 10 insertions, 10 deletions
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) \