diff options
author | Krzysztof Opasiak <k.opasiak@samsung.com> | 2015-04-08 15:07:49 +0200 |
---|---|---|
committer | Krzysztof Opasiak <k.opasiak@samsung.com> | 2015-04-16 12:49:26 +0200 |
commit | 8202fdcc748d7a3a9036bfc2ff83b409314e66fa (patch) | |
tree | a0f47d46d88fec9466920a7e2f6c6818ec82caab | |
parent | b114fad00622687079d61429408132aebf478392 (diff) | |
download | libusbg-8202fdcc748d7a3a9036bfc2ff83b409314e66fa.tar.gz libusbg-8202fdcc748d7a3a9036bfc2ff83b409314e66fa.tar.bz2 libusbg-8202fdcc748d7a3a9036bfc2ff83b409314e66fa.zip |
libusbg: Introduce usbg_cleanup_function_attrs() function
We would like to eliminate static buffers from function
attributes. To achieve this we should ensure that there
is some function which free the memory allocated
in usbg_get_function_attrs()
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
Reviewed-by: Pawel Szewczyk <p.szewczyk@samsung.com>
Reviewed-by: Philippe De Swert <philippedeswert@gmail.com>
-rw-r--r-- | examples/show-gadgets.c | 2 | ||||
-rw-r--r-- | include/usbg/usbg.h | 10 | ||||
-rw-r--r-- | src/usbg.c | 23 | ||||
-rw-r--r-- | src/usbg_schemes_libconfig.c | 1 |
4 files changed, 36 insertions, 0 deletions
diff --git a/examples/show-gadgets.c b/examples/show-gadgets.c index 1734d7e..f8bad33 100644 --- a/examples/show-gadgets.c +++ b/examples/show-gadgets.c @@ -132,6 +132,8 @@ void show_function(usbg_function *f) default: fprintf(stdout, " UNKNOWN\n"); } + + usbg_cleanup_function_attrs(&f_attrs); } void show_config(usbg_config *c) diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h index 20e733d..40fb5cf 100644 --- a/include/usbg/usbg.h +++ b/include/usbg/usbg.h @@ -710,6 +710,16 @@ extern int usbg_lookup_function_type(const char *name); */ extern int usbg_lookup_function_attrs_type(int f_type); +/** + * @brief Cleanup content of function attributes + * @param f_attrs function attributes which should be cleaned up. + * @note This function should be called to free + * additional memory allocated by usbg_get_function_attrs(). + * @warning None of attributes in passed structure should be + * accessed after returning from this function. + */ +extern void usbg_cleanup_function_attrs(usbg_function_attrs *f_attrs); + /* USB configurations allocation and configuration */ /** @@ -2581,6 +2581,29 @@ int usbg_get_function_attrs(usbg_function *f, usbg_function_attrs *f_attrs) : USBG_ERROR_INVALID_PARAM; } +void usbg_cleanup_function_attrs(usbg_function_attrs *f_attrs) +{ + if (!f_attrs) + return; + + switch (f_attrs->header.attrs_type) { + case USBG_F_ATTRS_SERIAL: + break; + + case USBG_F_ATTRS_NET: + break; + + case USBG_F_ATTRS_PHONET: + break; + + case USBG_F_ATTRS_FFS: + break; + default: + ERROR("Unsupported attrs type\n"); + break; + } +} + int usbg_set_function_net_attrs(usbg_function *f, const usbg_f_net_attrs *attrs) { int ret = USBG_SUCCESS; diff --git a/src/usbg_schemes_libconfig.c b/src/usbg_schemes_libconfig.c index d6bc6e2..d45b14a 100644 --- a/src/usbg_schemes_libconfig.c +++ b/src/usbg_schemes_libconfig.c @@ -397,6 +397,7 @@ static int usbg_export_function_attrs(usbg_function *f, config_setting_t *root) ret = USBG_ERROR_NOT_SUPPORTED; } + usbg_cleanup_function_attrs(&f_attrs); out: return ret; } |