Skip to content

Commit 942ecb9

Browse files
superm1gregkh
authored andcommitted
drm/amd/display: Add scoped mutexes for amdgpu_dm_dhcp
[ Upstream commit 6b675ab8efbf2bcee25be29e865455c56e246401 ] [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: be593d9d91c5 ("drm/amd/display: Fix slab-use-after-free in hdcp") Signed-off-by: Sasha Levin <[email protected]>
1 parent e07ed98 commit 942ecb9

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)
@@ -326,7 +320,7 @@ static void event_property_update(struct work_struct *work)
326320
continue;
327321

328322
drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
329-
mutex_lock(&hdcp_work->mutex);
323+
guard(mutex)(&hdcp_work->mutex);
330324

331325
if (conn_state->commit) {
332326
ret = wait_for_completion_interruptible_timeout(&conn_state->commit->hw_done,
@@ -358,7 +352,6 @@ static void event_property_update(struct work_struct *work)
358352
drm_hdcp_update_content_protection(connector,
359353
DRM_MODE_CONTENT_PROTECTION_DESIRED);
360354
}
361-
mutex_unlock(&hdcp_work->mutex);
362355
drm_modeset_unlock(&dev->mode_config.connection_mutex);
363356
}
364357
}
@@ -371,7 +364,7 @@ static void event_property_validate(struct work_struct *work)
371364
struct amdgpu_dm_connector *aconnector;
372365
unsigned int conn_index;
373366

374-
mutex_lock(&hdcp_work->mutex);
367+
guard(mutex)(&hdcp_work->mutex);
375368

376369
for (conn_index = 0; conn_index < AMDGPU_DM_MAX_DISPLAY_INDEX;
377370
conn_index++) {
@@ -415,8 +408,6 @@ static void event_property_validate(struct work_struct *work)
415408
schedule_work(&hdcp_work->property_update_work);
416409
}
417410
}
418-
419-
mutex_unlock(&hdcp_work->mutex);
420411
}
421412

422413
static void event_watchdog_timer(struct work_struct *work)
@@ -427,7 +418,7 @@ static void event_watchdog_timer(struct work_struct *work)
427418
struct hdcp_workqueue,
428419
watchdog_timer_dwork);
429420

430-
mutex_lock(&hdcp_work->mutex);
421+
guard(mutex)(&hdcp_work->mutex);
431422

432423
cancel_delayed_work(&hdcp_work->watchdog_timer_dwork);
433424

@@ -436,8 +427,6 @@ static void event_watchdog_timer(struct work_struct *work)
436427
&hdcp_work->output);
437428

438429
process_output(hdcp_work);
439-
440-
mutex_unlock(&hdcp_work->mutex);
441430
}
442431

443432
static void event_cpirq(struct work_struct *work)
@@ -446,13 +435,11 @@ static void event_cpirq(struct work_struct *work)
446435

447436
hdcp_work = container_of(work, struct hdcp_workqueue, cpirq_work);
448437

449-
mutex_lock(&hdcp_work->mutex);
438+
guard(mutex)(&hdcp_work->mutex);
450439

451440
mod_hdcp_process_event(&hdcp_work->hdcp, MOD_HDCP_EVENT_CPIRQ, &hdcp_work->output);
452441

453442
process_output(hdcp_work);
454-
455-
mutex_unlock(&hdcp_work->mutex);
456443
}
457444

458445
void hdcp_destroy(struct kobject *kobj, struct hdcp_workqueue *hdcp_work)
@@ -486,7 +473,7 @@ static bool enable_assr(void *handle, struct dc_link *link)
486473

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

489-
mutex_lock(&psp->dtm_context.mutex);
476+
guard(mutex)(&psp->dtm_context.mutex);
490477
memset(dtm_cmd, 0, sizeof(struct ta_dtm_shared_memory));
491478

492479
dtm_cmd->cmd_id = TA_DTM_COMMAND__TOPOLOGY_ASSR_ENABLE;
@@ -501,8 +488,6 @@ static bool enable_assr(void *handle, struct dc_link *link)
501488
res = false;
502489
}
503490

504-
mutex_unlock(&psp->dtm_context.mutex);
505-
506491
return res;
507492
}
508493

@@ -563,13 +548,11 @@ static void update_config(void *handle, struct cp_psp_stream_config *config)
563548
(!!aconnector->base.state) ?
564549
aconnector->base.state->hdcp_content_type : -1);
565550

566-
mutex_lock(&hdcp_w->mutex);
551+
guard(mutex)(&hdcp_w->mutex);
567552

568553
mod_hdcp_add_display(&hdcp_w->hdcp, link, display, &hdcp_w->output);
569554

570555
process_output(hdcp_w);
571-
mutex_unlock(&hdcp_w->mutex);
572-
573556
}
574557

575558
/**

0 commit comments

Comments
 (0)