power: battery: Fix error handling in votables' creation
The error handling path for failed calls to create_votable() currently
transfers program execution control to the label destroy_votable, where
the return code of the create_votable() call is directly passed to
destroy_votable(), ostensibly for cleanup.
Upon closer inspection, it is observed that the create_votable()
function cleans up after itself in the case of errors in all of its
intermediate steps before returning an error code. The error code is
essentially a negative integer returned as a typecasted pointer which,
when directly passed to destroy_votable(), will surely cause a crash at
the list_del() step within, as that function doesn't really do thorough
input sanitization.
Fix this by overwriting the return code of calls to create_votable()
with NULL in the case of error, before invoking destroy_votable(). This
prevents a crash because there is a NULL check at the very beginning of
that function.
Change-Id: Ic923051319c4af89b22752e6bea4afbf0111d777
Signed-off-by:
Guru Das Srinagesh <gurus@codeaurora.org>
Loading
Please register or sign in to comment