On Wed, Jan 22, 2014 at 02:56:20PM +0100, Stanislaw Wadas wrote: > Replace hard coded value of 256 by two constant > defines, MAX_LENGTH and MAX_PATH_LENGTH > > Signed-off-by: Stanislaw Wadas <s.wadas@xxxxxxxxxxx> > --- > include/usbg/usbg.h | 27 +++++++++++++++------------ > src/usbg.c | 46 +++++++++++++++++++++++----------------------- > 2 files changed, 38 insertions(+), 35 deletions(-) > > diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h > index 5f00068..abb9bc2 100644 > --- a/include/usbg/usbg.h > +++ b/include/usbg/usbg.h > @@ -33,13 +33,16 @@ > #define DEFAULT_UDC NULL > #define LANG_US_ENG 0x0409 > > +#define MAX_LENGTH 256 This should be MAX_STR_LENGTH to clarify the use as mentioned before. > +#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]; and MAX_STR_LENGTH here and throughout > 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/usbg.c b/src/usbg.c > index 20447db..cb7f172 100644 > --- a/src/usbg.c > +++ b/src/usbg.c > @@ -82,7 +82,7 @@ static int file_select(const struct dirent *dent) > > static char *usbg_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 *usbg_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 usbg_read_int(char *path, char *name, char *file, int base) > { > - char buf[256]; > + char buf[MAX_LENGTH]; > > if (usbg_read_buf(path, name, file, buf)) > return strtol(buf, NULL, base); > @@ -125,7 +125,7 @@ static void usbg_read_string(char *path, char *name, char *file, char *buf) > > static void usbg_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 usbg_write_buf(char *path, char *name, char *file, char *buf) > > static void usbg_write_int(char *path, char *name, char *file, int value, char *str) > { > - char buf[256]; > + char buf[MAX_LENGTH]; > > sprintf(buf, str, value); > usbg_write_buf(path, name, file, buf); > @@ -196,7 +196,7 @@ static int usbg_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 usbg_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 usbg_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 usbg_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 *usbg_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 *usbg_get_link_binding(struct config *c, struct function *f) > struct gadget *usbg_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 usbg_set_gadget_device_bcd_usb(struct gadget *g, int bcdusb) > > void usbg_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 usbg_set_gadget_serial_number(struct gadget *g, int lang, char *serno) > > void usbg_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 usbg_set_gadget_manufacturer(struct gadget *g, int lang, char *mnf) > > void usbg_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 usbg_set_gadget_product(struct gadget *g, int lang, char *prd) > > struct function *usbg_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 *usbg_create_function(struct gadget *g, enum function_type type, > > struct config *usbg_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 usbg_set_config_bm_attrs(struct config *c, int bmattrs) > > void usbg_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 usbg_set_config_string(struct config *c, int lang, char *str) > > int usbg_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 usbg_get_udcs(struct dirent ***udc_list) > > void usbg_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