reset: Fix crash when freeing non-existent optional resets
authorGeert Uytterhoeven <geert+renesas@glider.be>
Wed, 29 Nov 2023 16:55:33 +0000 (17:55 +0100)
committerPhilipp Zabel <p.zabel@pengutronix.de>
Thu, 30 Nov 2023 14:02:21 +0000 (15:02 +0100)
commit4a6756f56bcf8e64c87144a626ce53aea4899c0e
tree74dd42ff7e4bfe27d0f64391cd7ca350e19bcf73
parentb5ec294472794ed9ecba0cb4b8208372842e7e0d
reset: Fix crash when freeing non-existent optional resets

When obtaining one or more optional resets, non-existent resets are
stored as NULL pointers, and all related error and cleanup paths need to
take this into account.

Currently only reset_control_put() and reset_control_bulk_put()
get this right.  All of __reset_control_bulk_get(),
of_reset_control_array_get(), and reset_control_array_put() lack the
proper checking, causing NULL pointer dereferences on failure or
release.

Fix this by moving the existing check from reset_control_bulk_put() to
__reset_control_put_internal(), so it applies to all callers.
The double check in reset_control_put() doesn't hurt.

Fixes: 17c82e206d2a3cd8 ("reset: Add APIs to manage array of resets")
Fixes: 48d71395896d54ee ("reset: Add reset_control_bulk API")
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Link: https://lore.kernel.org/r/2440edae7ca8534628cdbaf559ded288f2998178.1701276806.git.geert+renesas@glider.be
Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
drivers/reset/core.c