X86 platform drivers
 help / color / mirror / Atom feed
* [PATCH 0/2] Use guard(mutex) for amd platform drivers
@ 2024-12-17 19:39 Mario Limonciello
  2024-12-17 19:39 ` [PATCH 1/2] platform/x86/amd: pmc: Use guard(mutex) Mario Limonciello
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Mario Limonciello @ 2024-12-17 19:39 UTC (permalink / raw)
  To: mario.limonciello, hdegoede, ilpo.jarvinen, Shyam-sundar.S-k
  Cc: platform-driver-x86

From: Mario Limonciello <mario.limonciello@amd.com>

Update the PMF and PMC drivers to use guard(mutex) instead of
mutex_lock/mutex_unlock.

Mario Limonciello (2):
  platform/x86/amd: pmc: Use guard(mutex)
  platform/x86/amd: pmf: Switch to guard(mutex)

 drivers/platform/x86/amd/pmc/pmc.c  | 14 ++++++--------
 drivers/platform/x86/amd/pmf/acpi.c |  6 ++----
 drivers/platform/x86/amd/pmf/core.c | 18 ++++++++----------
 3 files changed, 16 insertions(+), 22 deletions(-)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] platform/x86/amd: pmc: Use guard(mutex)
  2024-12-17 19:39 [PATCH 0/2] Use guard(mutex) for amd platform drivers Mario Limonciello
@ 2024-12-17 19:39 ` Mario Limonciello
  2024-12-17 19:39 ` [PATCH 2/2] platform/x86/amd: pmf: Switch to guard(mutex) Mario Limonciello
  2024-12-19 14:35 ` [PATCH 0/2] Use guard(mutex) for amd platform drivers Ilpo Järvinen
  2 siblings, 0 replies; 4+ messages in thread
From: Mario Limonciello @ 2024-12-17 19:39 UTC (permalink / raw)
  To: mario.limonciello, Shyam-sundar.S-k, hdegoede, ilpo.jarvinen
  Cc: platform-driver-x86

From: Mario Limonciello <mario.limonciello@amd.com>

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>
---
 drivers/platform/x86/amd/pmc/pmc.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/platform/x86/amd/pmc/pmc.c b/drivers/platform/x86/amd/pmc/pmc.c
index 26b878ee51918..ef105ca6de24a 100644
--- a/drivers/platform/x86/amd/pmc/pmc.c
+++ b/drivers/platform/x86/amd/pmc/pmc.c
@@ -688,7 +688,7 @@ static int amd_pmc_send_cmd(struct amd_pmc_dev *dev, u32 arg, u32 *data, u8 msg,
 	int rc;
 	u32 val, message, argument, response;
 
-	mutex_lock(&dev->lock);
+	guard(mutex)(&dev->lock);
 
 	if (dev->msg_port) {
 		message = AMD_S2D_REGISTER_MESSAGE;
@@ -706,7 +706,7 @@ static int amd_pmc_send_cmd(struct amd_pmc_dev *dev, u32 arg, u32 *data, u8 msg,
 				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 */
@@ -724,7 +724,7 @@ static int amd_pmc_send_cmd(struct amd_pmc_dev *dev, u32 arg, u32 *data, u8 msg,
 				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) {
@@ -738,21 +738,19 @@ static int amd_pmc_send_cmd(struct amd_pmc_dev *dev, u32 arg, u32 *data, u8 msg,
 	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;
 }
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] platform/x86/amd: pmf: Switch to guard(mutex)
  2024-12-17 19:39 [PATCH 0/2] Use guard(mutex) for amd platform drivers Mario Limonciello
  2024-12-17 19:39 ` [PATCH 1/2] platform/x86/amd: pmc: Use guard(mutex) Mario Limonciello
@ 2024-12-17 19:39 ` Mario Limonciello
  2024-12-19 14:35 ` [PATCH 0/2] Use guard(mutex) for amd platform drivers Ilpo Järvinen
  2 siblings, 0 replies; 4+ messages in thread
From: Mario Limonciello @ 2024-12-17 19:39 UTC (permalink / raw)
  To: mario.limonciello, Shyam-sundar.S-k, hdegoede, ilpo.jarvinen
  Cc: platform-driver-x86

From: Mario Limonciello <mario.limonciello@amd.com>

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>
---
 drivers/platform/x86/amd/pmf/acpi.c |  6 ++----
 drivers/platform/x86/amd/pmf/core.c | 18 ++++++++----------
 2 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/drivers/platform/x86/amd/pmf/acpi.c b/drivers/platform/x86/amd/pmf/acpi.c
index 1b9c7acf0ddf5..debd0e4ef9670 100644
--- a/drivers/platform/x86/amd/pmf/acpi.c
+++ b/drivers/platform/x86/amd/pmf/acpi.c
@@ -327,11 +327,11 @@ static void apmf_event_handler(acpi_handle handle, u32 event, void *data)
 	struct apmf_sbios_req req;
 	int ret;
 
-	mutex_lock(&pmf_dev->update_mutex);
+	guard(mutex)(&pmf_dev->update_mutex);
 	ret = apmf_get_sbios_requests(pmf_dev, &req);
 	if (ret) {
 		dev_err(pmf_dev->dev, "Failed to get SBIOS requests:%d\n", ret);
-		goto out;
+		return;
 	}
 
 	if (req.pending_req & BIT(APMF_AMT_NOTIFICATION)) {
@@ -353,8 +353,6 @@ static void apmf_event_handler(acpi_handle handle, u32 event, void *data)
 		if (pmf_dev->amt_enabled)
 			amd_pmf_update_2_cql(pmf_dev, req.cql_event);
 	}
-out:
-	mutex_unlock(&pmf_dev->update_mutex);
 }
 
 static int apmf_if_verify_interface(struct amd_pmf_dev *pdev)
diff --git a/drivers/platform/x86/amd/pmf/core.c b/drivers/platform/x86/amd/pmf/core.c
index 01eb9ee1eccd9..57ee95a327be5 100644
--- a/drivers/platform/x86/amd/pmf/core.c
+++ b/drivers/platform/x86/amd/pmf/core.c
@@ -127,7 +127,8 @@ static void amd_pmf_get_metrics(struct work_struct *work)
 	ktime_t time_elapsed_ms;
 	int socket_power;
 
-	mutex_lock(&dev->update_mutex);
+	guard(mutex)(&dev->update_mutex);
+
 	/* Transfer table contents */
 	memset(dev->buf, 0, sizeof(dev->m_table));
 	amd_pmf_send_cmd(dev, SET_TRANSFER_TABLE, 0, 7, NULL);
@@ -149,7 +150,6 @@ static void amd_pmf_get_metrics(struct work_struct *work)
 
 	dev->start_time = ktime_to_ms(ktime_get());
 	schedule_delayed_work(&dev->work_buffer, msecs_to_jiffies(metrics_table_loop_ms));
-	mutex_unlock(&dev->update_mutex);
 }
 
 static inline u32 amd_pmf_reg_read(struct amd_pmf_dev *dev, int reg_offset)
@@ -181,7 +181,7 @@ int amd_pmf_send_cmd(struct amd_pmf_dev *dev, u8 message, bool get, u32 arg, u32
 	int rc;
 	u32 val;
 
-	mutex_lock(&dev->lock);
+	guard(mutex)(&dev->lock);
 
 	/* Wait until we get a valid response */
 	rc = readx_poll_timeout(ioread32, dev->regbase + AMD_PMF_REGISTER_RESPONSE,
@@ -189,7 +189,7 @@ int amd_pmf_send_cmd(struct amd_pmf_dev *dev, u8 message, bool get, u32 arg, u32
 				PMF_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 */
@@ -207,7 +207,7 @@ int amd_pmf_send_cmd(struct amd_pmf_dev *dev, u8 message, bool get, u32 arg, u32
 				PMF_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) {
@@ -221,21 +221,19 @@ int amd_pmf_send_cmd(struct amd_pmf_dev *dev, u8 message, bool get, u32 arg, u32
 	case AMD_PMF_RESULT_CMD_REJECT_BUSY:
 		dev_err(dev->dev, "SMU not ready. err: 0x%x\n", val);
 		rc = -EBUSY;
-		goto out_unlock;
+		break;
 	case AMD_PMF_RESULT_CMD_UNKNOWN:
 		dev_err(dev->dev, "SMU cmd unknown. err: 0x%x\n", val);
 		rc = -EINVAL;
-		goto out_unlock;
+		break;
 	case AMD_PMF_RESULT_CMD_REJECT_PREREQ:
 	case AMD_PMF_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_pmf_dump_registers(dev);
 	return rc;
 }
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] Use guard(mutex) for amd platform drivers
  2024-12-17 19:39 [PATCH 0/2] Use guard(mutex) for amd platform drivers Mario Limonciello
  2024-12-17 19:39 ` [PATCH 1/2] platform/x86/amd: pmc: Use guard(mutex) Mario Limonciello
  2024-12-17 19:39 ` [PATCH 2/2] platform/x86/amd: pmf: Switch to guard(mutex) Mario Limonciello
@ 2024-12-19 14:35 ` Ilpo Järvinen
  2 siblings, 0 replies; 4+ messages in thread
From: Ilpo Järvinen @ 2024-12-19 14:35 UTC (permalink / raw)
  To: mario.limonciello, hdegoede, Shyam-sundar.S-k, Mario Limonciello
  Cc: platform-driver-x86

On Tue, 17 Dec 2024 13:39:50 -0600, Mario Limonciello wrote:

> Update the PMF and PMC drivers to use guard(mutex) instead of
> mutex_lock/mutex_unlock.
> 
> Mario Limonciello (2):
>   platform/x86/amd: pmc: Use guard(mutex)
>   platform/x86/amd: pmf: Switch to guard(mutex)
> 
> [...]


Thank you for your contribution, it has been applied to my local
review-ilpo-next branch. Note it will show up in the public
platform-drivers-x86/review-ilpo-next branch only once I've pushed my
local branch there, which might take a while.

The list of commits applied:
[1/2] platform/x86/amd: pmc: Use guard(mutex)
      commit: f947ea8dd657ed70c0c02b35ac485a24366201d3
[2/2] platform/x86/amd: pmf: Switch to guard(mutex)
      commit: 03f8e0e05510dad6377cd5ef029594d30e6c096d

--
 i.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-12-19 14:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-17 19:39 [PATCH 0/2] Use guard(mutex) for amd platform drivers Mario Limonciello
2024-12-17 19:39 ` [PATCH 1/2] platform/x86/amd: pmc: Use guard(mutex) Mario Limonciello
2024-12-17 19:39 ` [PATCH 2/2] platform/x86/amd: pmf: Switch to guard(mutex) Mario Limonciello
2024-12-19 14:35 ` [PATCH 0/2] Use guard(mutex) for amd platform drivers Ilpo Järvinen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox