1
0
Fork 0
mirror of https://github.com/linux-usb-gadgets/libusbgx.git synced 2025-07-25 00:45:05 +03:00

libusbgx: 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>
This commit is contained in:
Krzysztof Opasiak 2015-04-08 15:07:49 +02:00
parent 752e9ee578
commit cee215c1df
4 changed files with 36 additions and 0 deletions

View file

@ -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)

View file

@ -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 */
/**

View file

@ -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;

View file

@ -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;
}