bus: mhi: core: Fix error handling in mhi_register_controller()
authorDan Carpenter <dan.carpenter@oracle.com>
Tue, 1 Dec 2020 07:02:54 +0000 (10:02 +0300)
committerManivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Tue, 1 Dec 2020 13:37:10 +0000 (19:07 +0530)
commit89828f632dec8ab1e19f23771b313c1942e102c0
tree3c647d5302586d77a5c62b7417d46e6fc4955725
parent10ea8bcda5ae5463889e15dfc98aa2a73270ea58
bus: mhi: core: Fix error handling in mhi_register_controller()

There are a few problems with the error handling in this function.  They
mostly center around the alloc_ordered_workqueue() allocation.
1) If that allocation fails or if the kcalloc() prior to it fails then
it leads to a NULL dereference when we call
destroy_workqueue(mhi_cntrl->hiprio_wq).
2) The error code is not set.
3) The "mhi_cntrl->mhi_cmd" allocation is not freed.

The error handling was slightly confusing and I re-ordered it to be in
the exact mirror/reverse order of how things were allocated.  I changed
the label names to say what the goto does instead of describing where
the goto comes from.

Fixes: 8f7039787687 ("bus: mhi: core: Move to using high priority workqueue")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Loic Poulain <loic.poulain@linaro.org>
Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
drivers/bus/mhi/core/init.c