i2c: amd: Switch to guard(mutex)

Instead of using the 'goto label; mutex_unlock()' pattern use
'guard(mutex)' which will release the mutex when it goes out of scope.

Co-developed-by: Sanket Goswami <Sanket.Goswami@amd.com>
Signed-off-by: Sanket Goswami <Sanket.Goswami@amd.com>
Signed-off-by: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Andi Shyti <andi.shyti@kernel.org>
Link: https://lore.kernel.org/r/20250217124709.3121848-1-Shyam-sundar.S-k@amd.com
pull/1193/head
Shyam Sundar S K 2025-02-17 18:17:08 +05:30 committed by Andi Shyti
parent be7113d2e2
commit 8f95d1da03
1 changed files with 9 additions and 17 deletions

View File

@ -151,19 +151,16 @@ static void release_bus(void)
static void psp_release_i2c_bus_deferred(struct work_struct *work) static void psp_release_i2c_bus_deferred(struct work_struct *work)
{ {
mutex_lock(&psp_i2c_access_mutex); guard(mutex)(&psp_i2c_access_mutex);
/* /*
* If there is any pending transaction, cannot release the bus here. * If there is any pending transaction, cannot release the bus here.
* psp_release_i2c_bus() will take care of this later. * psp_release_i2c_bus() will take care of this later.
*/ */
if (psp_i2c_access_count) if (psp_i2c_access_count)
goto cleanup; return;
release_bus(); release_bus();
cleanup:
mutex_unlock(&psp_i2c_access_mutex);
} }
static DECLARE_DELAYED_WORK(release_queue, psp_release_i2c_bus_deferred); static DECLARE_DELAYED_WORK(release_queue, psp_release_i2c_bus_deferred);
@ -171,11 +168,11 @@ static int psp_acquire_i2c_bus(void)
{ {
int status; int status;
mutex_lock(&psp_i2c_access_mutex); guard(mutex)(&psp_i2c_access_mutex);
/* Return early if mailbox malfunctioned */ /* Return early if mailbox malfunctioned */
if (psp_i2c_mbox_fail) if (psp_i2c_mbox_fail)
goto cleanup; return 0;
psp_i2c_access_count++; psp_i2c_access_count++;
@ -184,11 +181,11 @@ static int psp_acquire_i2c_bus(void)
* reservation period. * reservation period.
*/ */
if (psp_i2c_sem_acquired) if (psp_i2c_sem_acquired)
goto cleanup; return 0;
status = psp_send_i2c_req(PSP_I2C_REQ_ACQUIRE); status = psp_send_i2c_req(PSP_I2C_REQ_ACQUIRE);
if (status) if (status)
goto cleanup; return 0;
psp_i2c_sem_acquired = jiffies; psp_i2c_sem_acquired = jiffies;
@ -201,18 +198,16 @@ static int psp_acquire_i2c_bus(void)
* communication with PSP. At any case i2c bus is granted to the caller, * communication with PSP. At any case i2c bus is granted to the caller,
* thus always return success. * thus always return success.
*/ */
cleanup:
mutex_unlock(&psp_i2c_access_mutex);
return 0; return 0;
} }
static void psp_release_i2c_bus(void) static void psp_release_i2c_bus(void)
{ {
mutex_lock(&psp_i2c_access_mutex); guard(mutex)(&psp_i2c_access_mutex);
/* Return early if mailbox was malfunctioned */ /* Return early if mailbox was malfunctioned */
if (psp_i2c_mbox_fail) if (psp_i2c_mbox_fail)
goto cleanup; return;
/* /*
* If we are last owner of PSP semaphore, need to release arbitration * If we are last owner of PSP semaphore, need to release arbitration
@ -220,7 +215,7 @@ static void psp_release_i2c_bus(void)
*/ */
psp_i2c_access_count--; psp_i2c_access_count--;
if (psp_i2c_access_count) if (psp_i2c_access_count)
goto cleanup; return;
/* /*
* Send a release command to PSP if the semaphore reservation timeout * Send a release command to PSP if the semaphore reservation timeout
@ -228,9 +223,6 @@ static void psp_release_i2c_bus(void)
*/ */
if (!delayed_work_pending(&release_queue)) if (!delayed_work_pending(&release_queue))
release_bus(); release_bus();
cleanup:
mutex_unlock(&psp_i2c_access_mutex);
} }
/* /*