]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
platform/x86/amd: pmc: Use guard(mutex)
authorMario Limonciello <mario.limonciello@amd.com>
Tue, 17 Dec 2024 19:39:51 +0000 (13:39 -0600)
committerIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Thu, 19 Dec 2024 14:15:32 +0000 (16:15 +0200)
Instead of using the `goto label; mutex_unlock()` pattern use
`guard(mutex)` which will release the mutex when it goes out of scope.

Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Link: https://lore.kernel.org/r/20241217194027.1189038-2-superm1@kernel.org
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
drivers/platform/x86/amd/pmc/pmc.c

index bfdf63ecfc80796a055f385d8fcd035b872ed2f5..60a22fb65eee3b9f7bd08798a0eef11eb306b16b 100644 (file)
@@ -521,7 +521,7 @@ int amd_pmc_send_cmd(struct amd_pmc_dev *dev, u32 arg, u32 *data, u8 msg, bool r
        int rc;
        u32 val, message, argument, response;
 
-       mutex_lock(&dev->lock);
+       guard(mutex)(&dev->lock);
 
        if (dev->msg_port == MSG_PORT_S2D) {
                message = dev->stb_arg.msg;
@@ -539,7 +539,7 @@ int amd_pmc_send_cmd(struct amd_pmc_dev *dev, u32 arg, u32 *data, u8 msg, bool r
                                PMC_MSG_DELAY_MIN_US * RESPONSE_REGISTER_LOOP_MAX);
        if (rc) {
                dev_err(dev->dev, "failed to talk to SMU\n");
-               goto out_unlock;
+               return rc;
        }
 
        /* Write zero to response register */
@@ -557,7 +557,7 @@ int amd_pmc_send_cmd(struct amd_pmc_dev *dev, u32 arg, u32 *data, u8 msg, bool r
                                PMC_MSG_DELAY_MIN_US * RESPONSE_REGISTER_LOOP_MAX);
        if (rc) {
                dev_err(dev->dev, "SMU response timed out\n");
-               goto out_unlock;
+               return rc;
        }
 
        switch (val) {
@@ -571,21 +571,19 @@ int amd_pmc_send_cmd(struct amd_pmc_dev *dev, u32 arg, u32 *data, u8 msg, bool r
        case AMD_PMC_RESULT_CMD_REJECT_BUSY:
                dev_err(dev->dev, "SMU not ready. err: 0x%x\n", val);
                rc = -EBUSY;
-               goto out_unlock;
+               break;
        case AMD_PMC_RESULT_CMD_UNKNOWN:
                dev_err(dev->dev, "SMU cmd unknown. err: 0x%x\n", val);
                rc = -EINVAL;
-               goto out_unlock;
+               break;
        case AMD_PMC_RESULT_CMD_REJECT_PREREQ:
        case AMD_PMC_RESULT_FAILED:
        default:
                dev_err(dev->dev, "SMU cmd failed. err: 0x%x\n", val);
                rc = -EIO;
-               goto out_unlock;
+               break;
        }
 
-out_unlock:
-       mutex_unlock(&dev->lock);
        amd_pmc_dump_registers(dev);
        return rc;
 }