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>
Merge pull request #3 from kopasiak/devel_remove

Add remove gadget functionality
Merge pull request #4 from philippedeswert/master

libusbg: Fix issues found with coverity
Merge pull request #6 from kopasiak/devel_ffs

Add support for functionFS based usb functions
Merge pull request #7 from kopasiak/devel_fixes

Small fixes and clean up
Merge pull request #8 from kopasiak/devel_schemes

Add import from/export to file functionality
libusbg: Fix out-of-tree builds

The include flag should point to the source directory, not the build
directory.

Signed-off-by: Koen Kooi <koen@dominion.thruhere.net>
Signed-off-by: Matt Porter <mporter@linaro.org>
[Fixed conflicts and updated patch description]
libusbg: Fix usbg_disable_gadget to actually clear the UDC

Currently usbg_disable_gadget() does not actually write anything
to UDC to clear it and the configured UDC name stays there.

Signed-off-by: Tony Lindgren <tony@atomide.com>
Reviewed-by: Krzysztof Opasiak <k.opasiak@samsung.com>
Signed-off-by: Matt Porter <mporter@linaro.org>
libusbg: Return USBG_ERROR_PATH_TOO_LONG error when it happens

Signed-off-by: Philippe De Swert <philippe.deswert@jollamobile.com>
Acked-by: Krzysztof Opasiak <k.opasiak@samsung.com>
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>

Update commit message.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
libusbg: fix: reverse comparsion to fix error

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
libusbg: doc: Fix typos in doxygen documentation

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
libusbg: Fix off-by-one error.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
libusbg: fix: Remove unused variables

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
libusbg: Always add '\0' at end of string

strncpy() may not append trailing '\0' so let's append
it always at end of string to avoid getting into troubles.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
libusbg: Simplify getting names form library structures

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

Changes since v1:
Fix show-gadgets example: get attributes before dereferencing them

Reported-by: Philippe De Swert <philippe.deswert@jollamobile.com>
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
libusbg: Allow to set all gadget attrs using one function.

Having specialized functions for each attribute may be
sometime inconvenient to use. Provide also function
whihc allows to set attribute selected by parameter.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
libusbg: Return suitable error codes instead of -1

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