ANDROID: usb: gadget: configfs: Support multiple android instances 69/252669/1
authorAjay Agarwal <ajaya@codeaurora.org>
Tue, 30 May 2017 04:57:23 +0000 (10:27 +0530)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Mon, 1 Feb 2021 08:30:15 +0000 (17:30 +0900)
commit9216188d4f89f842c0ac7d24e4dfdfec1fc67c3b
treef81b0fce3b2fcd34ce847f85967304b8442aefd1
parentf37333761b9b9cbef022ec51deeea747ad32ae4a
ANDROID: usb: gadget: configfs: Support multiple android instances

Some platforms may choose to create more than one gadget ConfigFS
instance, often due to the hardware having multiple USB gadget
controllers which can be used simultaneously. Currently
android_device_create() assumes only one gadget instance is ever
created and creates a single "android0" device under the "android_usb"
class, resulting in a crash if a second gadget is registered since the
global android_device pointer gets overwritten with -EEXIST.

Fix this by properly supporting multiple instances and naming the
devices "android0", "android1", etc. when each instance is created
(via mkdir). For now keep the global singleton android_device pointing
to android0 for ease of use since f_midi and f_audio_source currently
use create_function_device() without any context as to which gadget
they will be bound to.

Bug: 120441124
Fixes: 429213f5d9eb ("ANDROID: usb: gadget: configfs: Add function devices to the parent")
Signed-off-by: Ajay Agarwal <ajaya@codeaurora.org>
[jackp@codeaurora.org: reworded commit text]
Signed-off-by: Jack Pham <jackp@codeaurora.org>
[sw0312.kim: backport from android common kernel commit 852619242c94 to support multiple udc]
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Change-Id: Iade5973db69a2a4a1800c8218b9f5fba6b59a1c8
drivers/usb/gadget/configfs.c