[PATCH v4 1/4] libusbg: Path length replaced with MAX_LENGTH & MAX_PATH_LENGTH

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

 



256 hard coded value has been replaced by two defined
constants MAX_LENGTH and MAX_PATH_LENGTH

Signed-off-by: Stanislaw Wadas <s.wadas@xxxxxxxxxxx>
---
Changes since v1:
        - fixed typos in MAX_LENGTH throughout

 include/gadget/gadget.h |   27 +++++++++++++++------------
 src/gadget.c            |   46 +++++++++++++++++++++++-----------------------
 2 files changed, 38 insertions(+), 35 deletions(-)

diff --git a/include/gadget/gadget.h b/include/gadget/gadget.h
index 6a32c39..9bca97e 100644
--- a/include/gadget/gadget.h
+++ b/include/gadget/gadget.h
@@ -33,13 +33,16 @@
 #define DEFAULT_UDC		NULL
 #define LANG_US_ENG		0x0409
 
+#define MAX_LENGTH 256
+#define MAX_PATH_LENGTH 256
+
 /**
  * @struct state
  * @brief State of the gadget devices in the system
  */
 struct state
 {
-	char path[256];
+	char path[MAX_PATH_LENGTH];
 
 	TAILQ_HEAD(ghead, gadget) gadgets;
 };
@@ -51,8 +54,8 @@ struct state
 struct gadget
 {
 	char name[40];
-	char path[256];
-	char udc[256];
+	char path[MAX_PATH_LENGTH];
+	char udc[MAX_LENGTH];
 	int dclass;
 	int dsubclass;
 	int dproto;
@@ -61,9 +64,9 @@ struct gadget
 	int bcdusb;
 	int product;
 	int vendor;
-	char str_ser[256];
-	char str_mnf[256];
-	char str_prd[256];
+	char str_ser[MAX_LENGTH];
+	char str_mnf[MAX_LENGTH];
+	char str_prd[MAX_LENGTH];
 	TAILQ_ENTRY(gadget) gnode;
 	TAILQ_HEAD(chead, config) configs;
 	TAILQ_HEAD(fhead, function) functions;
@@ -81,10 +84,10 @@ struct config
 	struct gadget *parent;
 
 	char name[40];
-	char path[256];
+	char path[MAX_PATH_LENGTH];
 	int maxpower;
 	int bmattrs;
-	char str_cfg[256];
+	char str_cfg[MAX_LENGTH];
 };
 
 /**
@@ -136,7 +139,7 @@ struct serial_attrs {
 struct net_attrs {
 	struct ether_addr dev_addr;
 	struct ether_addr host_addr;
-	char ifname[256];
+	char ifname[MAX_LENGTH];
 	int qmult;
 };
 
@@ -145,7 +148,7 @@ struct net_attrs {
  * @brief Attributes for the phonet USB function
  */
 struct phonet_attrs {
-	char ifname[256];
+	char ifname[MAX_LENGTH];
 };
 
 /**
@@ -168,7 +171,7 @@ struct function
 	struct gadget *parent;
 
 	char name[40];
-	char path[256];
+	char path[MAX_PATH_LENGTH];
 
 	enum function_type type;
 	union attrs attr;
@@ -187,7 +190,7 @@ struct binding
 	struct function *target;
 
 	char name[40];
-	char path[256];
+	char path[MAX_PATH_LENGTH];
 };
 
 /* Library init and cleanup */
diff --git a/src/gadget.c b/src/gadget.c
index 83b8b62..fb86e7e 100644
--- a/src/gadget.c
+++ b/src/gadget.c
@@ -82,7 +82,7 @@ static int file_select(const struct dirent *dent)
 
 static char *gadget_read_buf(char *path, char *name, char *file, char *buf)
 {
-	char p[256];
+	char p[MAX_LENGTH];
 	FILE *fp;
 	char *ret = NULL;
 
@@ -92,7 +92,7 @@ static char *gadget_read_buf(char *path, char *name, char *file, char *buf)
 	if (!fp)
 		goto out;
 
-	ret = fgets(buf, 256, fp);
+	ret = fgets(buf, MAX_LENGTH, fp);
 
 	fclose(fp);
 
@@ -102,7 +102,7 @@ out:
 
 static int gadget_read_int(char *path, char *name, char *file, int base)
 {
-	char buf[256];
+	char buf[MAX_LENGTH];
 
 	if (gadget_read_buf(path, name, file, buf))
 		return strtol(buf, NULL, base);
@@ -125,7 +125,7 @@ static void gadget_read_string(char *path, char *name, char *file, char *buf)
 
 static void gadget_write_buf(char *path, char *name, char *file, char *buf)
 {
-	char p[256];
+	char p[MAX_LENGTH];
 	FILE *fp;
 
 	sprintf(p, "%s/%s/%s", path, name, file);
@@ -143,7 +143,7 @@ static void gadget_write_buf(char *path, char *name, char *file, char *buf)
 
 static void gadget_write_int(char *path, char *name, char *file, int value, char *str)
 {
-	char buf[256];
+	char buf[MAX_LENGTH];
 
 	sprintf(buf, str, value);
 	gadget_write_buf(path, name, file, buf);
@@ -196,7 +196,7 @@ static int gadget_parse_functions(char *path, struct gadget *g)
 	struct function *f;
 	int i, n;
 	struct dirent **dent;
-	char fpath[256];
+	char fpath[MAX_PATH_LENGTH];
 
 	sprintf(fpath, "%s/%s/functions", path, g->name);
 
@@ -227,7 +227,7 @@ static void gadget_parse_config_bindings(struct config *c)
 {
 	int i, n;
 	struct dirent **dent;
-	char bpath[256];
+	char bpath[MAX_PATH_LENGTH];
 	struct gadget *g = c->parent;
 	struct binding *b;
 	struct function *f;
@@ -240,12 +240,12 @@ static void gadget_parse_config_bindings(struct config *c)
 	for (i=0; i < n; i++) {
 		TAILQ_FOREACH(f, &g->functions, fnode) {
 			int n;
-			char contents[256];
-			char cpath[256];
+			char contents[MAX_LENGTH];
+			char cpath[MAX_PATH_LENGTH];
 			char fname[40];
 
 			sprintf(cpath, "%s/%s", bpath, dent[i]->d_name);
-			n = readlink(cpath, contents, 256);
+			n = readlink(cpath, contents, MAX_PATH_LENGTH);
 			if (n<0)
 				ERRORNO("bytes %d contents %s\n", n, contents);
 			strcpy(fname, f->name);
@@ -268,7 +268,7 @@ static int gadget_parse_configs(char *path, struct gadget *g)
 	struct config *c;
 	int i, n;
 	struct dirent **dent;
-	char cpath[256];
+	char cpath[MAX_PATH_LENGTH];
 
 	sprintf(cpath, "%s/%s/configs", path, g->name);
 
@@ -354,7 +354,7 @@ struct state *gadget_init(char *configfs_path)
 {
 	int ret;
 	struct stat sts;
-	char path[256];
+	char path[MAX_PATH_LENGTH];
 	struct state *s = NULL;
 
 	strcpy(path, configfs_path);
@@ -468,7 +468,7 @@ struct binding *gadget_get_link_binding(struct config *c, struct function *f)
 struct gadget *gadget_create_gadget(struct state *s, char *name,
 				    int vendor, int product)
 {
-	char gpath[256];
+	char gpath[MAX_PATH_LENGTH];
 	struct gadget *g, *cur;
 	int ret;
 
@@ -560,7 +560,7 @@ void gadget_set_gadget_device_bcd_usb(struct gadget *g, int bcdusb)
 
 void gadget_set_gadget_serial_number(struct gadget *g, int lang, char *serno)
 {
-	char path[256];
+	char path[MAX_PATH_LENGTH];
 
 	sprintf(path, "%s/%s/%s/0x%x", g->path, g->name, "strings", lang);
 
@@ -573,7 +573,7 @@ void gadget_set_gadget_serial_number(struct gadget *g, int lang, char *serno)
 
 void gadget_set_gadget_manufacturer(struct gadget *g, int lang, char *mnf)
 {
-	char path[256];
+	char path[MAX_PATH_LENGTH];
 
 	sprintf(path, "%s/%s/%s/0x%x", g->path, g->name, "strings", lang);
 
@@ -586,7 +586,7 @@ void gadget_set_gadget_manufacturer(struct gadget *g, int lang, char *mnf)
 
 void gadget_set_gadget_product(struct gadget *g, int lang, char *prd)
 {
-	char path[256];
+	char path[MAX_PATH_LENGTH];
 
 	sprintf(path, "%s/%s/%s/0x%x", g->path, g->name, "strings", lang);
 
@@ -599,8 +599,8 @@ void gadget_set_gadget_product(struct gadget *g, int lang, char *prd)
 
 struct function *gadget_create_function(struct gadget *g, enum function_type type, char *instance)
 {
-	char fpath[256];
-	char name[256];
+	char fpath[MAX_PATH_LENGTH];
+	char name[MAX_LENGTH];
 	struct function *f, *cur;
 	int ret;
 
@@ -655,7 +655,7 @@ struct function *gadget_create_function(struct gadget *g, enum function_type typ
 
 struct config *gadget_create_config(struct gadget *g, char *name)
 {
-	char cpath[256];
+	char cpath[MAX_PATH_LENGTH];
 	struct config *c, *cur;
 	int ret;
 
@@ -719,7 +719,7 @@ void gadget_set_config_bm_attrs(struct config *c, int bmattrs)
 
 void gadget_set_config_string(struct config *c, int lang, char *str)
 {
-	char path[256];
+	char path[MAX_PATH_LENGTH];
 
 	sprintf(path, "%s/%s/0x%x", c->path, "strings", lang);
 
@@ -732,8 +732,8 @@ void gadget_set_config_string(struct config *c, int lang, char *str)
 
 int gadget_add_config_function(struct config *c, char *name, struct function *f)
 {
-	char bpath[256];
-	char fpath[256];
+	char bpath[MAX_PATH_LENGTH];
+	char fpath[MAX_PATH_LENGTH];
 	struct binding *b;
 	struct binding *cur;
 	int ret = -1;
@@ -795,7 +795,7 @@ int gadget_get_udcs(struct dirent ***udc_list)
 
 void gadget_enable_gadget(struct gadget *g, char *udc)
 {
-	char gudc[256];
+	char gudc[MAX_LENGTH];
 	struct dirent **udc_list;
 	int n;
 
-- 
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