Merge pull request #1 from kopasiak/master

Merging the following series:

libusbg: clean up and error handling
libusbg: Cleanup, bug fix and refactoring
libusbg: Bug fixes, feature enhancements and API
libusbg: Add error code propagation and attributes refreshing
libusbg: Fix missing read of bcdDevice.

Value of bcdDevice has been never read from Config FS
and this field was leaved uninitialized. Change
usbg_parse_gadget_attrs() to read also from this file.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
libusbg: Fix wrong malloc sizes in allocate functions.

Functions usbg_allocate_function() and usbg_allocate_binding()
had allocated sizeof(usbg_config) instead of usbg_function
and usbg_binding.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
libusbg: Add checking for legal function type.

Function type provided by user to functions should
be checked before usage to avoid errors.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
libusbg: Replace usage of function name with type and instance.

User of library should not use directly function name but
only type of the function and name of instance. Using this
will separate user for naming convention on Config FS.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
libusbg: Use config ID and label instead of config name.

Naming convention of Config FS should not be exposed
to user of library. All API functions should use
configuration ID (configuration number) as unique
identificator and configuration label as human
readable description.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
Merge pull request #2 from kopasiak/devel

Small bug fixes and rework of API.
libusbg: Fix readlink/buffer overrun issue. CID#56130, CID#56129

Readlink() can return the total length of the buffer (here 4096/USBG_MAX_PATH_LENGTH),
so we do not want to dereference target[4096] as that would give an off by one error.

Signed-off-by: Philippe De Swert <philippe.deswert@jollamobile.com>
libusbg: Fix buffer overrun issue. CID#56128

Avoid calling usbg_read_string() with a 40 byte long buffer, which in turn is filled in
by usbg_read_buf() which uses a maximum of 256 bytes (USBG_MAX_STR_LENGTH). This adjusts
the buffer to be the right size.

Signed-off-by: Philippe De Swert <philippe.deswert@jollamobile.com>
libusbg: Do not try to dereference func when it is NULL. CID#56127

We check if func is NULL, so if the allocation function failed we should
not dereference or handle it anymore, so we jump straight to the end.

Signed-off-by: Philippe De Swert <philippe.deswert@jollamobile.com>
libusbg: Do not dereference usb config attributes when they are NULL. CID#56126

We probably need to check if we get valid attributes passed. Otherwise we will
try to dereference a NULL-pointer as the usb_config_attr will not be valid.

Signed-off-by: Philippe De Swert <philippe.deswert@jollamobile.com>
libusbg: Add remove binding functionality.

Add function which allow to remove binding between function
and configuration. This functions also remove binding from
internal library structures wht means that after this
operation all pointers to removed binding are invalid.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
libusbg: Add remove gadget/config strings functionality.

Add functions which allow to remove strings in gadget
and configuration.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
libusbg: Add remove configuration functionality.

Add function which allow to remove configuration.
This functions also remove binding from internal
library structures what means that after this
operation all pointers to removed config are invalid.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
libusbg: Add remove function functionality.

Add function which allow to remove USB function.
This functions also remove function from internal
library structures what means that after this
operation all pointers to removed function are invalid.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
libusbg: Add remove gadget functionality.

Add function which allow to remove USB gadget.
This functions also remove gadget from internal
library structures what means that after this
operation all pointers to removed gadget are invalid.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
libusbg: Update examples to new API functionality.

Removing gadget/config/function/binding functionality
has been added to API so add example of how to use it.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
libusbg: Fix potential memory leak in usbg_init()

Memory allocated with asprintf() for variable path
could be not free() in some cases. Fix this issue by
doing some small refactoring.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
libusbg: Add support for functionFS.

Recent kernel versions supports creation of functionFS based
functions using configFS, so this library also should support this.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
libusbg: Update show gadget example support ffs functions.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>