[PATCH 18/23] libusbg: Return error code instead of NULL pointer.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Change usbg_get_gadget_strs() and usbg_get_gadget_attrs()
to return usbg_error instead of NULL pointer.

Signed-off-by: Krzysztof Opasiak <k.opasiak@xxxxxxxxxxx>

Conflicts:

	src/usbg.c
---
 include/usbg/usbg.h |   10 ++++------
 src/usbg.c          |   43 ++++++++++++++++++++++---------------------
 2 files changed, 26 insertions(+), 27 deletions(-)

diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index 3ad98b6..6855833 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -291,10 +291,9 @@ extern int usbg_set_gadget_attrs(usbg_gadget *g,
  * @brief Get the USB gadget strings
  * @param g Pointer to gadget
  * @param g_attrs Structure to be filled
- * @retur Pointer to filled structure or NULL if error occurred.
+ * @return 0 on success usbg_error if error occurred
  */
-extern usbg_gadget_attrs *usbg_get_gadget_attrs(usbg_gadget *g,
-		usbg_gadget_attrs *g_attrs);
+extern int usbg_get_gadget_attrs(usbg_gadget *g, usbg_gadget_attrs *g_attrs);
 
 /**
  * @brief Get gadget name length
@@ -386,10 +385,9 @@ extern int usbg_set_gadget_device_bcd_usb(usbg_gadget *g, uint16_t bcdUSB);
  * @param g Pointer to gadget
  * @param lang Language of strings
  * @param g_sttrs Structure to be filled
- * @retur Pointer to filled structure or NULL if error occurred or
- * if no strings for given language.
+ * @return 0 on success usbg_error if error occurred
  */
-extern usbg_gadget_strs *usbg_get_gadget_strs(usbg_gadget *g, int lang,
+extern int usbg_get_gadget_strs(usbg_gadget *g, int lang,
 		usbg_gadget_strs *g_strs);
 
 /**
diff --git a/src/usbg.c b/src/usbg.c
index 55c9c8e..9747069 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -616,9 +616,10 @@ out:
 	return ret;
 }
 
-static usbg_gadget_strs *usbg_parse_strings(char *path, char *name, int lang,
+static int usbg_parse_gadget_strs(char *path, char *name, int lang,
 		usbg_gadget_strs *g_strs)
 {
+	int ret;
 	DIR *dir;
 	char spath[USBG_MAX_PATH_LENGTH];
 
@@ -628,14 +629,23 @@ static usbg_gadget_strs *usbg_parse_strings(char *path, char *name, int lang,
 	dir = opendir(spath);
 	if (dir) {
 		closedir(dir);
-		usbg_read_string(spath, "", "serialnumber", g_strs->str_ser);
-		usbg_read_string(spath, "", "manufacturer", g_strs->str_mnf);
-		usbg_read_string(spath, "", "product", g_strs->str_prd);
+		ret = usbg_read_string(spath, "", "serialnumber", g_strs->str_ser);
+		if (ret != USBG_SUCCESS)
+			goto out;
+
+		ret = usbg_read_string(spath, "", "manufacturer", g_strs->str_mnf);
+		if (ret != USBG_SUCCESS)
+			goto out;
+
+		ret = usbg_read_string(spath, "", "product", g_strs->str_prd);
+		if (ret != USBG_SUCCESS)
+			goto out;
 	} else {
-		g_strs = NULL;
+		ret = usbg_translate_error(errno);
 	}
 
-	return g_strs;
+out:
+	return ret;
 }
 
 static inline int usbg_parse_gadget(char *path, char *name, usbg_state *parent,
@@ -927,15 +937,10 @@ int usbg_create_gadget(usbg_state *s, char *name,
 	return ret;
 }
 
-usbg_gadget_attrs *usbg_get_gadget_attrs(usbg_gadget *g,
-		usbg_gadget_attrs *g_attrs)
+int usbg_get_gadget_attrs(usbg_gadget *g, usbg_gadget_attrs *g_attrs)
 {
-	if (g && g_attrs)
-		usbg_parse_gadget_attrs(g->path, g->name, g_attrs);
-	else
-		g_attrs = NULL;
-
-	return g_attrs;
+	return g && g_attrs ? usbg_parse_gadget_attrs(g->path, g->name, g_attrs)
+			: USBG_ERROR_INVALID_PARAM;
 }
 
 size_t usbg_get_gadget_name_len(usbg_gadget *g)
@@ -1065,15 +1070,11 @@ int usbg_set_gadget_device_bcd_usb(usbg_gadget *g, uint16_t bcdUSB)
 			: USBG_ERROR_INVALID_PARAM;
 }
 
-usbg_gadget_strs *usbg_get_gadget_strs(usbg_gadget *g, int lang,
+int usbg_get_gadget_strs(usbg_gadget *g, int lang,
 		usbg_gadget_strs *g_strs)
 {
-	if (g && g_strs)
-		g_strs = usbg_parse_strings(g->path, g->name, lang, g_strs);
-	else
-		g_strs = NULL;
-
-	return g_strs;
+	return g && g_strs ? usbg_parse_gadget_strs(g->path, g->name, lang,
+			g_strs)	: USBG_ERROR_INVALID_PARAM;
 }
 
 static int usbg_check_dir(char *path)
-- 
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




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux