usb: gadget: Fix switching out from multi configuration compositions
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 <900226c7e840b807cfff21860d06d6d4dfc40c7a@codeaurora.org>

TeamVee-Kanas/android_kernel_samsung_kanas,TeamVee-Kanas/android_kernel_samsung_kanas,TeamVee-Kanas/android_kernel_samsung_kanas,TeamVee-Kanas/android_kernel_samsung_kanas,TeamVee-Kanas/android_kernel_samsung_kanas