From 12952ac5dc349016fb075cccd060c44275d1bbf9 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 23 Jun 2020 22:10:27 -0700 Subject: [PATCH] Fix synchronization issue in mods kernel driver Summary: The get_reset_handle function does not release the spin_lock when it finds the handle in the list of reset handles and returns. Modify the function to ensure releasing of the lock in all cases. Change-Id: I2ead6d64199cccc7afb7876ca14ce91a110f7e6c Signed-off-by: Ellis Roberts Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvidia/+/2365950 Reviewed-by: automaticguardword Reviewed-by: Automatic_Commit_Validation_User Reviewed-by: Bharat Nihalani Reviewed-by: mobile promotions GVS: Gerrit_Virtual_Submit Tested-by: mobile promotions --- drivers/misc/mods/mods_clock.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/misc/mods/mods_clock.c b/drivers/misc/mods/mods_clock.c index 0ab43755..1e8ed32d 100644 --- a/drivers/misc/mods/mods_clock.c +++ b/drivers/misc/mods/mods_clock.c @@ -220,22 +220,23 @@ static int get_reset_handle(struct reset_data reset_data) handle = rst_entry->handle; if (strcmp(rst_entry->rst_data.name, reset_data.name) == 0) { - return handle; + goto failed; } } /* If reset not already in array, then we must add it */ rst_entry = kzalloc(sizeof(struct reset_entry), GFP_ATOMIC); if (unlikely(!rst_entry)) { - spin_unlock(&mods_clock_lock); - return -1; + handle = -1; + goto failed; } rst_entry->handle = ++handle; rst_entry->rst_data = reset_data; INIT_LIST_HEAD(&rst_entry->list); list_add_tail(&rst_entry->list, &reset_handles); - spin_unlock(&mods_clock_lock); +failed: + spin_unlock(&mods_clock_lock); return handle; }