[PATCH v6 3/4] libusbg: Move mkdir functions

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

 



Call mkdir() function after successful memory allocation
and gadget function creation.

Signed-off-by: Stanislaw Wadas <s.wadas@xxxxxxxxxxx>
---
 src/usbg.c |   36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/src/usbg.c b/src/usbg.c
index c673be9..babe067 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -492,12 +492,6 @@ struct gadget *usbg_create_gadget(struct state *s, char *name,
 
 	sprintf(gpath, "%s/%s", s->path, name);
 
-	ret = mkdir(gpath, S_IRWXU|S_IRWXG|S_IRWXO);
-	if (ret < 0) {
-		ERRORNO("%s\n", gpath);
-		return NULL;
-	}
-
 	g = malloc(sizeof(struct gadget));
 	if (!g) {
 		ERRORNO("allocating gadget\n");
@@ -515,6 +509,12 @@ struct gadget *usbg_create_gadget(struct state *s, char *name,
 	usbg_write_hex16(s->path, name, "idVendor", vendor);
 	usbg_write_hex16(s->path, name, "idProduct", product);
 
+	ret = mkdir(gpath, S_IRWXU|S_IRWXG|S_IRWXO);
+	if (ret < 0) {
+		ERRORNO("%s\n", gpath);
+		return NULL;
+	}
+
 	/* Insert in string order */
 	if (TAILQ_EMPTY(&s->gadgets) ||
 	    (strcmp(name, TAILQ_FIRST(&s->gadgets)->name) < 0))
@@ -628,12 +628,6 @@ struct function *usbg_create_function(struct gadget *g, enum function_type type,
 
 	sprintf(fpath, "%s/%s/functions/%s", g->path, g->name, name);
 
-	ret = mkdir(fpath, S_IRWXU|S_IRWXG|S_IRWXO);
-	if (ret < 0) {
-		ERRORNO("%s\n", fpath);
-		return NULL;
-	}
-
 	f = malloc(sizeof(struct function));
 	if (!f) {
 		ERRORNO("allocating function\n");
@@ -646,6 +640,12 @@ struct function *usbg_create_function(struct gadget *g, enum function_type type,
 
 	usbg_parse_function_attrs(f);
 
+	ret = mkdir(fpath, S_IRWXU|S_IRWXG|S_IRWXO);
+	if (ret < 0) {
+		ERRORNO("%s\n", fpath);
+		return NULL;
+	}
+
 	/* Insert in string order */
 	if (TAILQ_EMPTY(&g->functions) ||
 	    (strcmp(name, TAILQ_FIRST(&g->functions)->name) < 0))
@@ -682,12 +682,6 @@ struct config *usbg_create_config(struct gadget *g, char *name)
 
 	sprintf(cpath, "%s/%s/configs/%s", g->path, g->name, name);
 
-	ret = mkdir(cpath, S_IRWXU|S_IRWXG|S_IRWXO);
-	if (ret < 0) {
-		ERRORNO("%s\n", cpath);
-		return NULL;
-	}
-
 	c = malloc(sizeof(struct config));
 	if (!c) {
 		ERRORNO("allocating configuration\n");
@@ -698,6 +692,12 @@ struct config *usbg_create_config(struct gadget *g, char *name)
 	strcpy(c->name, name);
 	sprintf(c->path, "%s/%s/%s/%s", g->path, g->name, "configs", name);
 
+	ret = mkdir(cpath, S_IRWXU|S_IRWXG|S_IRWXO);
+	if (ret < 0) {
+		ERRORNO("%s\n", cpath);
+		return NULL;
+	}
+
 	/* Insert in string order */
 	if (TAILQ_EMPTY(&g->configs) ||
 	    (strcmp(name, TAILQ_FIRST(&g->configs)->name) < 0))
-- 
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