OSDN Git Service

usb: cdnsp: fix error handling in cdnsp_mem_init()
authorPawel Laszczak <pawell@cadence.com>
Fri, 11 Dec 2020 09:50:53 +0000 (10:50 +0100)
committerPeter Chen <peter.chen@nxp.com>
Tue, 29 Dec 2020 04:36:13 +0000 (12:36 +0800)
commite2d60f8c475a4955b8c39bda4cf6b10b09460772
tree036280afe1cbe2c80ed5183aa293d6b68507fe3f
parent88171f67a2c15461d29942b0103d539f52367844
usb: cdnsp: fix error handling in cdnsp_mem_init()

This function uses "One Function Cleans up Everything" style and that's
basically impossible to do correctly. It's cleaner to write it with
"clean up the most recent allocation".

Patch fixes two isues:
1. If pdev->dcbaa = dma_alloc_coherent() fails then that leads to a NULL
   dereference inside the cdnsp_free_priv_device() function.
2. if cdnsp_alloc_priv_device() fails that leads to a double free because
   we free pdev->out_ctx.bytes in several places.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Pawel Laszczak <pawell@cadence.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Tested-by: Pawel Laszczak <pawell@cadence.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
drivers/usb/cdns3/cdnsp-mem.c