From: Krzysztof Opasiak Date: Wed, 18 Mar 2015 11:39:24 +0000 (+0100) Subject: libusbgx: Remove static buffers from usbg_f_net_attrs X-Git-Tag: libusbgx-v0.1.0~83 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fe3fab53281310d16a631b201d2ffb1a82eb10fd;p=platform%2Fupstream%2Flibusbg.git libusbgx: Remove static buffers from usbg_f_net_attrs Signed-off-by: Krzysztof Opasiak Reviewed-by: Pawel Szewczyk Reviewed-by: Philippe De Swert --- diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h index f2b3668..e0a651e 100644 --- a/include/usbg/usbg.h +++ b/include/usbg/usbg.h @@ -49,6 +49,8 @@ extern "C" { #define USBG_MAX_NAME_LENGTH 40 /* Dev name for ffs is a part of function name, we subtracs 4 char for "ffs." */ #define USBG_MAX_DEV_LENGTH (USBG_MAX_NAME_LENGTH - 4) +/* ConfigFS just like SysFS uses page size as max size of file content */ +#define USBG_MAX_FILE_SIZE 4096 /** * @brief Additional option for usbg_rm_* functions. @@ -196,7 +198,7 @@ typedef struct { typedef struct { struct ether_addr dev_addr; struct ether_addr host_addr; - char ifname[USBG_MAX_STR_LENGTH]; + char *ifname; int qmult; } usbg_f_net_attrs; diff --git a/src/usbg.c b/src/usbg.c index b3c4c24..20cae9f 100644 --- a/src/usbg.c +++ b/src/usbg.c @@ -444,6 +444,28 @@ static int usbg_read_string(const char *path, const char *name, return ret; } +static int usbg_read_string_alloc(const char *path, const char *name, + const char *file, char **dest) +{ + char buf[USBG_MAX_FILE_SIZE]; + char *new_buf = NULL; + int ret = USBG_SUCCESS; + + ret = usbg_read_string(path, name, file, buf); + if (ret != USBG_SUCCESS) + goto out; + + new_buf = strdup(buf); + if (!new_buf) { + ret = USBG_ERROR_NO_MEM; + goto out; + } + + *dest = new_buf; +out: + return ret; +} + static int usbg_write_buf(const char *path, const char *name, const char *file, const char *buf) { @@ -821,12 +843,12 @@ static int usbg_parse_function_net_attrs(usbg_function *f, goto out; } - ret = usbg_read_string(f->path, f->name, "ifname", f_net_attrs->ifname); + ret = usbg_read_dec(f->path, f->name, "qmult", &(f_net_attrs->qmult)); if (ret != USBG_SUCCESS) goto out; - ret = usbg_read_dec(f->path, f->name, "qmult", &(f_net_attrs->qmult)); - + ret = usbg_read_string_alloc(f->path, f->name, "ifname", + &(f_net_attrs->ifname)); out: return ret; } @@ -2591,6 +2613,8 @@ void usbg_cleanup_function_attrs(usbg_function_attrs *f_attrs) break; case USBG_F_ATTRS_NET: + free(f_attrs->attrs.net.ifname); + f_attrs->attrs.net.ifname = NULL; break; case USBG_F_ATTRS_PHONET: @@ -2611,7 +2635,7 @@ int usbg_set_function_net_attrs(usbg_function *f, const usbg_f_net_attrs *attrs) char *addr; /* ifname is read only so we accept only empty string for this param */ - if (attrs->ifname[0]) { + if (attrs->ifname && attrs->ifname[0]) { ret = USBG_ERROR_INVALID_PARAM; goto out; }