Examples provided with the library should use returned error codes and provide information to user. Remove todo baceuse it has been already done. Signed-off-by: Krzysztof Opasiak <k.opasiak@xxxxxxxxxxx> --- examples/gadget-acm-ecm.c | 51 +++++++++++++++++++++++++++++++++++++++------ examples/show-gadgets.c | 40 +++++++++++++++++++++++++++++++---- src/usbg.c | 1 - 3 files changed, 81 insertions(+), 11 deletions(-) diff --git a/examples/gadget-acm-ecm.c b/examples/gadget-acm-ecm.c index cda3808..8eb4aeb 100644 --- a/examples/gadget-acm-ecm.c +++ b/examples/gadget-acm-ecm.c @@ -60,44 +60,83 @@ int main(void) usbg_ret = usbg_init("/sys/kernel/config", &s); if (usbg_ret != USBG_SUCCESS) { fprintf(stderr, "Error on USB gadget init\n"); + fprintf(stderr, "Error: %s : %s\n", usbg_error_name(usbg_ret), + usbg_strerror(usbg_ret)); goto out1; } usbg_ret = usbg_create_gadget(s, "g1", &g_attrs, &g_strs, &g); if (usbg_ret != USBG_SUCCESS) { fprintf(stderr, "Error on create gadget\n"); + fprintf(stderr, "Error: %s : %s\n", usbg_error_name(usbg_ret), + usbg_strerror(usbg_ret)); goto out2; } usbg_ret = usbg_create_function(g, F_ACM, "usb0", NULL, &f_acm0); if (usbg_ret != USBG_SUCCESS) { fprintf(stderr, "Error creating acm0 function\n"); + fprintf(stderr, "Error: %s : %s\n", usbg_error_name(usbg_ret), + usbg_strerror(usbg_ret)); goto out2; } usbg_ret = usbg_create_function(g, F_ACM, "usb1", NULL, &f_acm1); if (usbg_ret != USBG_SUCCESS) { fprintf(stderr, "Error creating acm1 function\n"); + fprintf(stderr, "Error: %s : %s\n", usbg_error_name(usbg_ret), + usbg_strerror(usbg_ret)); goto out2; } - usbg_ret = usbg_create_function(g, F_ECM, "usb0", NULL, &f_acm1); + usbg_ret = usbg_create_function(g, F_ECM, "usb0", NULL, &f_ecm); if (usbg_ret != USBG_SUCCESS) { fprintf(stderr, "Error creating ecm function\n"); + fprintf(stderr, "Error: %s : %s\n", usbg_error_name(usbg_ret), + usbg_strerror(usbg_ret)); goto out2; } - usbg_ret = usbg_create_config(g, "c.1", NULL /* use defaults */, &c_strs, &c); + usbg_ret = usbg_create_config(g, "c.1", NULL /* use defaults */, &c_strs, + &c); if (usbg_ret != USBG_SUCCESS) { fprintf(stderr, "Error creating config\n"); + fprintf(stderr, "Error: %s : %s\n", usbg_error_name(usbg_ret), + usbg_strerror(usbg_ret)); goto out2; } - usbg_add_config_function(c, "acm.GS0", f_acm0); - usbg_add_config_function(c, "acm.GS1", f_acm1); - usbg_add_config_function(c, "ecm.usb0", f_ecm); + usbg_ret = usbg_add_config_function(c, "acm.GS0", f_acm0); + if (usbg_ret != USBG_SUCCESS) { + fprintf(stderr, "Error adding acm.GS0\n"); + fprintf(stderr, "Error: %s : %s\n", usbg_error_name(usbg_ret), + usbg_strerror(usbg_ret)); + goto out2; + } + + usbg_ret = usbg_add_config_function(c, "acm.GS1", f_acm1); + if (usbg_ret != USBG_SUCCESS) { + fprintf(stderr, "Error adding acm.GS1\n"); + fprintf(stderr, "Error: %s : %s\n", usbg_error_name(usbg_ret), + usbg_strerror(usbg_ret)); + goto out2; + } - usbg_enable_gadget(g, DEFAULT_UDC); + usbg_ret = usbg_add_config_function(c, "ecm.usb0", f_ecm); + if (usbg_ret != USBG_SUCCESS) { + fprintf(stderr, "Error adding ecm.usb0\n"); + fprintf(stderr, "Error: %s : %s\n", usbg_error_name(usbg_ret), + usbg_strerror(usbg_ret)); + goto out2; + } + + usbg_ret = usbg_enable_gadget(g, DEFAULT_UDC); + if (usbg_ret != USBG_SUCCESS) { + fprintf(stderr, "Error enabling gadget\n"); + fprintf(stderr, "Error: %s : %s\n", usbg_error_name(usbg_ret), + usbg_strerror(usbg_ret)); + goto out2; + } ret = 0; diff --git a/examples/show-gadgets.c b/examples/show-gadgets.c index 4d79a09..df86cb9 100644 --- a/examples/show-gadgets.c +++ b/examples/show-gadgets.c @@ -30,11 +30,17 @@ void show_gadget(usbg_gadget *g) { char buf[USBG_MAX_STR_LENGTH]; + int usbg_ret; usbg_gadget_attrs g_attrs; usbg_gadget_strs g_strs; usbg_get_gadget_name(g, buf, USBG_MAX_STR_LENGTH); - usbg_get_gadget_attrs(g, &g_attrs); + usbg_ret = usbg_get_gadget_attrs(g, &g_attrs); + if (usbg_ret != USBG_SUCCESS) { + fprintf(stderr, "Error: %s : %s\n", usbg_error_name(usbg_ret), + usbg_strerror(usbg_ret)); + return; + } fprintf(stdout, "ID %04x:%04x '%s'\n", g_attrs.idVendor, g_attrs.idProduct, buf); @@ -52,6 +58,11 @@ void show_gadget(usbg_gadget *g) fprintf(stdout, " idProduct\t\t0x%04x\n", g_attrs.idProduct); usbg_get_gadget_strs(g, LANG_US_ENG, &g_strs); + if (usbg_ret != USBG_SUCCESS) { + fprintf(stderr, "Error: %s : %s\n", usbg_error_name(usbg_ret), + usbg_strerror(usbg_ret)); + return; + } fprintf(stdout, " Serial Number\t\t%s\n", g_strs.str_ser); fprintf(stdout, " Manufacturer\t\t%s\n", g_strs.str_mnf); fprintf(stdout, " Product\t\t%s\n", g_strs.str_prd); @@ -60,10 +71,16 @@ void show_gadget(usbg_gadget *g) void show_function(usbg_function *f) { char buf[USBG_MAX_STR_LENGTH]; + int usbg_ret; usbg_function_attrs f_attrs; usbg_get_function_name(f, buf, USBG_MAX_STR_LENGTH); - usbg_get_function_attrs(f, &f_attrs); + usbg_ret = usbg_get_function_attrs(f, &f_attrs); + if (usbg_ret != USBG_SUCCESS) { + fprintf(stderr, "Error: %s : %s\n", usbg_error_name(usbg_ret), + usbg_strerror(usbg_ret)); + return; + } fprintf(stdout, " Function '%s'\n", buf); switch (usbg_get_function_type(f)) { @@ -100,15 +117,28 @@ void show_config(usbg_config *c) char buf[USBG_MAX_STR_LENGTH], buf2[USBG_MAX_STR_LENGTH]; usbg_config_attrs c_attrs; usbg_config_strs c_strs; + int usbg_ret; usbg_get_config_name(c, buf, USBG_MAX_STR_LENGTH); fprintf(stdout, " Configuration '%s'\n", buf); - usbg_get_config_attrs(c, &c_attrs); + usbg_ret = usbg_get_config_attrs(c, &c_attrs); + if (usbg_ret != USBG_SUCCESS) { + fprintf(stderr, "Error: %s : %s\n", usbg_error_name(usbg_ret), + usbg_strerror(usbg_ret)); + return; + } + fprintf(stdout, " MaxPower\t\t%d\n", c_attrs.bMaxPower); fprintf(stdout, " bmAttributes\t0x%02x\n", c_attrs.bmAttributes); - usbg_get_config_strs(c, LANG_US_ENG, &c_strs); + usbg_ret = usbg_get_config_strs(c, LANG_US_ENG, &c_strs); + if (usbg_ret != USBG_SUCCESS) { + fprintf(stderr, "Error: %s : %s\n", usbg_error_name(usbg_ret), + usbg_strerror(usbg_ret)); + return; + } + fprintf(stdout, " configuration\t%s\n", c_strs.configuration); usbg_for_each_binding(b, c) { @@ -130,6 +160,8 @@ int main(void) usbg_ret = usbg_init("/sys/kernel/config", &s); if (usbg_ret != USBG_SUCCESS) { fprintf(stderr, "Error on USB gadget init\n"); + fprintf(stderr, "Error: %s : %s\n", usbg_error_name(usbg_ret), + usbg_strerror(usbg_ret)); return -EINVAL; } diff --git a/src/usbg.c b/src/usbg.c index 4e6da9e..42d62ed 100644 --- a/src/usbg.c +++ b/src/usbg.c @@ -33,7 +33,6 @@ /** * @file usbg.c * @todo Handle buffer overflows - * @todo Error checking and return code propagation */ struct usbg_state -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html