[2/2] pmu: be more strict about locking

Submitted by Karol Herbst on March 1, 2016, 10:10 a.m.

Details

Message ID 1456827019-3209-3-git-send-email-nouveau@karolherbst.de
State New
Headers show
Series "PMU communications improvements" ( rev: 1 ) in Nouveau

Not browsing as part of any series.

Commit Message

Karol Herbst March 1, 2016, 10:10 a.m.
when we start communicating with the pmu a bit more, the current code is a real
issue. I encountered a dead lock here, while testing my dynamic reclocking code

Signed-off-by: Karol Herbst <nouveau@karolherbst.de>
---
 drm/nouveau/nvkm/subdev/pmu/base.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/drm/nouveau/nvkm/subdev/pmu/base.c b/drm/nouveau/nvkm/subdev/pmu/base.c
index fa3cc5b..67d319d 100644
--- a/drm/nouveau/nvkm/subdev/pmu/base.c
+++ b/drm/nouveau/nvkm/subdev/pmu/base.c
@@ -71,21 +71,23 @@  nvkm_pmu_send(struct nvkm_pmu *pmu, u32 reply[2],
 	u32 addr;
 	int ret = 0;
 
+	mutex_lock(&subdev->mutex);
 	/* wait for a free slot in the fifo */
 	addr  = nvkm_rd32(device, 0x10a4a0);
 	if (nvkm_msec(device, 2000,
 		u32 tmp = nvkm_rd32(device, 0x10a4b0);
 		if (tmp != (addr ^ 8))
 			break;
-	) < 0)
+	) < 0) {
+		mutex_unlock(&subdev->mutex);
 		return -EBUSY;
+	}
 
 	/* we currently only support a single process at a time waiting
 	 * on a synchronous reply, take the PMU mutex and tell the
 	 * receive handler what we're waiting for
 	 */
 	if (reply) {
-		mutex_lock(&subdev->mutex);
 		pmu->recv.message = message;
 		pmu->recv.process = process;
 	}
@@ -114,9 +116,9 @@  nvkm_pmu_send(struct nvkm_pmu *pmu, u32 reply[2],
 			reply[0] = 0;
 			reply[1] = 0;
 		}
-		mutex_unlock(&subdev->mutex);
 	}
 
+	mutex_unlock(&subdev->mutex);
 	return ret;
 }