habanalabs: Avoid double free in error flow
authorTomer Tayar <ttayar@habana.ai>
Thu, 1 Aug 2019 13:57:36 +0000 (13:57 +0000)
committerOded Gabbay <oded.gabbay@gmail.com>
Mon, 12 Aug 2019 06:00:34 +0000 (09:00 +0300)
commit508c5849c62d009e03f37ad0f556071fac5112f0
treecf830b1f50c6ace76ea924efd2e4b02fd48870eb
parentd45331b00ddb179e291766617259261c112db872
habanalabs: Avoid double free in error flow

In case kernel context init fails during device initialization, both
hl_ctx_put() and kfree() are called, ending with a double free of the
kernel context.
Calling kfree() is needed only when a failure happens between the
allocation of the kernel context and its initialization, so move it to
there and remove it from the error flow.

Signed-off-by: Tomer Tayar <ttayar@habana.ai>
Reviewed-by: Oded Gabbay <oded.gabbay@gmail.com>
Signed-off-by: Oded Gabbay <oded.gabbay@gmail.com>
drivers/misc/habanalabs/device.c