USB: omap_udc: fix crashes on probe error and module removal
authorAaro Koskinen <aaro.koskinen@iki.fi>
Sat, 24 Nov 2018 22:17:05 +0000 (00:17 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 17 Dec 2018 09:07:10 +0000 (10:07 +0100)
commit3737d8b658159dca7fc48f542f3eda8c0a3145be
treea43295eb8272bfb4d97b4c6a8bb37c6ec2aedef4
parent9ea692784b84a0e03ace94b6a20cc6496930b84a
USB: omap_udc: fix crashes on probe error and module removal

[ Upstream commit 99f700366fcea1aa2fa3c49c99f371670c3c62f8 ]

We currently crash if usb_add_gadget_udc_release() fails, since the
udc->done is not initialized until in the remove function.
Furthermore, on module removal the udc data is accessed although
the release function is already triggered by usb_del_gadget_udc()
early in the function.

Fix by rewriting the release and remove functions, basically moving
all the cleanup into the release function, and doing the completion
only in the module removal case.

The patch fixes omap_udc module probe with a failing gadged, and also
allows the removal of omap_udc. Tested by running "modprobe omap_udc;
modprobe -r omap_udc" in a loop.

Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/usb/gadget/udc/omap_udc.c