functionfs: fix cport helper debug message printf conversions

%ld is used where %zu should have been used for the cport
read/write helpers debug output that handles size_t value.
Fix that.

Signed-off-by: Matt Porter <mporter@linaro.org>
functionfs: give up and free memory if cport_read() fails

Currently we try repeatedly if a read of the cport fifo fails. Adjust
this behavior to simply free buffer memory and kill the thread.

Signed-off-by: Matt Porter <mporter@linaro.org>
main: cleanup: fix ordering by tearing down the gadget, then functionfs

When we exit gbsim, we currently tear down the functionfs pipes before
disabling the gadget. This is very bad as the gadget is still enabled
with no backing i/o. Correct this by tearing down the gadget first so
it disables and cause a disconnect on the host side.

Signed-off-by: Matt Porter <mporter@linaro.org>