Skip to content

Commit 7509678

Browse files
superm1gregkh
authored andcommitted
drm/amd/display: Add scoped mutexes for amdgpu_dm_dhcp
[ Upstream commit 6b675ab ] [Why] Guards automatically release mutex when it goes out of scope making code easier to follow. [How] Replace all use of mutex_lock()/mutex_unlock() with guard(mutex). Reviewed-by: Alex Hung <[email protected]> Signed-off-by: Mario Limonciello <[email protected]> Signed-off-by: Tom Chung <[email protected]> Tested-by: Daniel Wheeler <[email protected]> Signed-off-by: Alex Deucher <[email protected]> Stable-dep-of: be593d9 ("drm/amd/display: Fix slab-use-after-free in hdcp") Signed-off-by: Sasha Levin <[email protected]>
1 parent e1eea69 commit 7509678

File tree

1 file changed

+10
-27
lines changed

1 file changed

+10
-27
lines changed

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_hdcp.c

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ void hdcp_update_display(struct hdcp_workqueue *hdcp_work,
172172
struct mod_hdcp_display_adjustment display_adjust;
173173
unsigned int conn_index = aconnector->base.index;
174174

175-
mutex_lock(&hdcp_w->mutex);
175+
guard(mutex)(&hdcp_w->mutex);
176176
hdcp_w->aconnector[conn_index] = aconnector;
177177

178178
memset(&link_adjust, 0, sizeof(link_adjust));
@@ -209,7 +209,6 @@ void hdcp_update_display(struct hdcp_workqueue *hdcp_work,
209209
mod_hdcp_update_display(&hdcp_w->hdcp, conn_index, &link_adjust, &display_adjust, &hdcp_w->output);
210210

211211
process_output(hdcp_w);
212-
mutex_unlock(&hdcp_w->mutex);
213212
}
214213

215214
static void hdcp_remove_display(struct hdcp_workqueue *hdcp_work,
@@ -220,7 +219,7 @@ static void hdcp_remove_display(struct hdcp_workqueue *hdcp_work,
220219
struct drm_connector_state *conn_state = aconnector->base.state;
221220
unsigned int conn_index = aconnector->base.index;
222221

223-
mutex_lock(&hdcp_w->mutex);
222+
guard(mutex)(&hdcp_w->mutex);
224223
hdcp_w->aconnector[conn_index] = aconnector;
225224

226225
/* the removal of display will invoke auth reset -> hdcp destroy and
@@ -239,15 +238,14 @@ static void hdcp_remove_display(struct hdcp_workqueue *hdcp_work,
239238
mod_hdcp_remove_display(&hdcp_w->hdcp, aconnector->base.index, &hdcp_w->output);
240239

241240
process_output(hdcp_w);
242-
mutex_unlock(&hdcp_w->mutex);
243241
}
244242

245243
void hdcp_reset_display(struct hdcp_workqueue *hdcp_work, unsigned int link_index)
246244
{
247245
struct hdcp_workqueue *hdcp_w = &hdcp_work[link_index];
248246
unsigned int conn_index;
249247

250-
mutex_lock(&hdcp_w->mutex);
248+
guard(mutex)(&hdcp_w->mutex);
251249

252250
mod_hdcp_reset_connection(&hdcp_w->hdcp, &hdcp_w->output);
253251

@@ -259,8 +257,6 @@ void hdcp_reset_display(struct hdcp_workqueue *hdcp_work, unsigned int link_inde
259257
}
260258

261259
process_output(hdcp_w);
262-
263-
mutex_unlock(&hdcp_w->mutex);
264260
}
265261

266262
void hdcp_handle_cpirq(struct hdcp_workqueue *hdcp_work, unsigned int link_index)
@@ -277,16 +273,14 @@ static void event_callback(struct work_struct *work)
277273
hdcp_work = container_of(to_delayed_work(work), struct hdcp_workqueue,
278274
callback_dwork);
279275

280-
mutex_lock(&hdcp_work->mutex);
276+
guard(mutex)(&hdcp_work->mutex);
281277

282278
cancel_delayed_work(&hdcp_work->callback_dwork);
283279

284280
mod_hdcp_process_event(&hdcp_work->hdcp, MOD_HDCP_EVENT_CALLBACK,
285281
&hdcp_work->output);
286282

287283
process_output(hdcp_work);
288-
289-
mutex_unlock(&hdcp_work->mutex);
290284
}
291285

292286
static void event_property_update(struct work_struct *work)
@@ -323,7 +317,7 @@ static void event_property_update(struct work_struct *work)
323317
continue;
324318

325319
drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
326-
mutex_lock(&hdcp_work->mutex);
320+
guard(mutex)(&hdcp_work->mutex);
327321

328322
if (conn_state->commit) {
329323
ret = wait_for_completion_interruptible_timeout(&conn_state->commit->hw_done,
@@ -355,7 +349,6 @@ static void event_property_update(struct work_struct *work)
355349
drm_hdcp_update_content_protection(connector,
356350
DRM_MODE_CONTENT_PROTECTION_DESIRED);
357351
}
358-
mutex_unlock(&hdcp_work->mutex);
359352
drm_modeset_unlock(&dev->mode_config.connection_mutex);
360353
}
361354
}
@@ -368,7 +361,7 @@ static void event_property_validate(struct work_struct *work)
368361
struct amdgpu_dm_connector *aconnector;
369362
unsigned int conn_index;
370363

371-
mutex_lock(&hdcp_work->mutex);
364+
guard(mutex)(&hdcp_work->mutex);
372365

373366
for (conn_index = 0; conn_index < AMDGPU_DM_MAX_DISPLAY_INDEX;
374367
conn_index++) {
@@ -408,8 +401,6 @@ static void event_property_validate(struct work_struct *work)
408401
schedule_work(&hdcp_work->property_update_work);
409402
}
410403
}
411-
412-
mutex_unlock(&hdcp_work->mutex);
413404
}
414405

415406
static void event_watchdog_timer(struct work_struct *work)
@@ -420,7 +411,7 @@ static void event_watchdog_timer(struct work_struct *work)
420411
struct hdcp_workqueue,
421412
watchdog_timer_dwork);
422413

423-
mutex_lock(&hdcp_work->mutex);
414+
guard(mutex)(&hdcp_work->mutex);
424415

425416
cancel_delayed_work(&hdcp_work->watchdog_timer_dwork);
426417

@@ -429,8 +420,6 @@ static void event_watchdog_timer(struct work_struct *work)
429420
&hdcp_work->output);
430421

431422
process_output(hdcp_work);
432-
433-
mutex_unlock(&hdcp_work->mutex);
434423
}
435424

436425
static void event_cpirq(struct work_struct *work)
@@ -439,13 +428,11 @@ static void event_cpirq(struct work_struct *work)
439428

440429
hdcp_work = container_of(work, struct hdcp_workqueue, cpirq_work);
441430

442-
mutex_lock(&hdcp_work->mutex);
431+
guard(mutex)(&hdcp_work->mutex);
443432

444433
mod_hdcp_process_event(&hdcp_work->hdcp, MOD_HDCP_EVENT_CPIRQ, &hdcp_work->output);
445434

446435
process_output(hdcp_work);
447-
448-
mutex_unlock(&hdcp_work->mutex);
449436
}
450437

451438
void hdcp_destroy(struct kobject *kobj, struct hdcp_workqueue *hdcp_work)
@@ -479,7 +466,7 @@ static bool enable_assr(void *handle, struct dc_link *link)
479466

480467
dtm_cmd = (struct ta_dtm_shared_memory *)psp->dtm_context.context.mem_context.shared_buf;
481468

482-
mutex_lock(&psp->dtm_context.mutex);
469+
guard(mutex)(&psp->dtm_context.mutex);
483470
memset(dtm_cmd, 0, sizeof(struct ta_dtm_shared_memory));
484471

485472
dtm_cmd->cmd_id = TA_DTM_COMMAND__TOPOLOGY_ASSR_ENABLE;
@@ -494,8 +481,6 @@ static bool enable_assr(void *handle, struct dc_link *link)
494481
res = false;
495482
}
496483

497-
mutex_unlock(&psp->dtm_context.mutex);
498-
499484
return res;
500485
}
501486

@@ -557,13 +542,11 @@ static void update_config(void *handle, struct cp_psp_stream_config *config)
557542
(!!aconnector->base.state) ?
558543
aconnector->base.state->hdcp_content_type : -1);
559544

560-
mutex_lock(&hdcp_w->mutex);
545+
guard(mutex)(&hdcp_w->mutex);
561546

562547
mod_hdcp_add_display(&hdcp_w->hdcp, link, display, &hdcp_w->output);
563548

564549
process_output(hdcp_w);
565-
mutex_unlock(&hdcp_w->mutex);
566-
567550
}
568551

569552
/**

0 commit comments

Comments
 (0)