usb: gadget: Fix switching out from multi configuration compositions

Fix a crash issue in the USB stack when there is a dynamic composition
switch from a multi configuration composition, e.g., (ECM:RNDIS:MBIM) to
another composition. The crash occurs because this composition has three
configuration, which are all using BAM to BAM connections. Therefore,
when we switch out from this composition, the same bam2bam_data_ports[]
array entry is free 3 times - once for each configuration during its
unbind function. When the MBIM configuration is unbound, it tries to
access this array entry which has already been freed, and a crash occurs.
The solutions used to fix this issue is to use a reference count for this
array entry, and free it only when the reference count gets to zero.
Additionally, a NULL pointer check is used before accessing this array.

Change-Id: I94b3af367da8cd344bacb6b84e84aed0f5f66655
CRs-Fixed: 545448
Signed-off-by: Danny Segal <dsegal@codeaurora.org>
USB: android: Handle error conditions if usb_add_config fails

When bind_config() of any function driver fails, we go ahead and do a
usb_gadget_connect() due to which remove_config is called during
next disconnect process and a crash is observed as we delete the
config->list once again.

So if the bind_config of any function driver fails, don't call
usb_gadget_connect(), instead handle the possible error conditions.

CRs-Fixed: 488052
Change-Id: I974e2838ef5c36e586f49ae783e8608150770883
Signed-off-by: Vijayavardhan Vennapusa <vvreddy@codeaurora.org>
Merge "usb: gadget: Fix switching out from multi configuration compositions"
Merge "USB: android: Handle error conditions if usb_add_config fails"