Skip to content

Commit 4a6756f

Browse files
geertupH5
authored andcommitted
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: 17c82e2 ("reset: Add APIs to manage array of resets") Fixes: 48d7139 ("reset: Add reset_control_bulk API") Signed-off-by: Geert Uytterhoeven <[email protected]> Link: https://lore.kernel.org/r/2440edae7ca8534628cdbaf559ded288f2998178.1701276806.git.geert+renesas@glider.be Signed-off-by: Philipp Zabel <[email protected]>
1 parent b5ec294 commit 4a6756f

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/reset/core.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,9 @@ static void __reset_control_put_internal(struct reset_control *rstc)
807807
{
808808
lockdep_assert_held(&reset_list_mutex);
809809

810+
if (IS_ERR_OR_NULL(rstc))
811+
return;
812+
810813
kref_put(&rstc->refcnt, __reset_control_release);
811814
}
812815

@@ -1017,11 +1020,8 @@ EXPORT_SYMBOL_GPL(reset_control_put);
10171020
void reset_control_bulk_put(int num_rstcs, struct reset_control_bulk_data *rstcs)
10181021
{
10191022
mutex_lock(&reset_list_mutex);
1020-
while (num_rstcs--) {
1021-
if (IS_ERR_OR_NULL(rstcs[num_rstcs].rstc))
1022-
continue;
1023+
while (num_rstcs--)
10231024
__reset_control_put_internal(rstcs[num_rstcs].rstc);
1024-
}
10251025
mutex_unlock(&reset_list_mutex);
10261026
}
10271027
EXPORT_SYMBOL_GPL(reset_control_bulk_put);

0 commit comments

Comments
 (0)