Skip to content

drm/apple: backlight: pair drm_modeset_acquire_init() with _fini() - #57

Merged
RyanTheTide merged 1 commit into
aurora-silicon:aurora-wipfrom
oliverlukschander:fix/dcp-backlight-acquire-fini
Oct 8, 2026
Merged

RyanTheTide merged 1 commit into
aurora-silicon:aurora-wipfrom
oliverlukschander:fix/dcp-backlight-acquire-fini

Conversation

@oliverlukschander

Copy link
Copy Markdown
Contributor

dcp_set_brightness() and drm_crtc_set_brightness() call drm_modeset_acquire_init() on a stack context but never drm_modeset_acquire_fini(), not even on the -EDEADLK/-ERESTARTSYS returns.

Under lockdep the acquire context stays on the task's held-lock stack after the function returns. The backlight core's mutex_unlock(&bd->ops_lock) then walks into the stale entry: DEBUG_LOCKS_WARN_ON(1) in __lock_acquire, followed by a NULL pointer dereference in systemd-backlight on every boot of a PROVE_LOCKING kernel. Without lockdep it is invisible, but still wrong.

The fix adds drm_modeset_acquire_fini() on every exit path (6 lines).

Found while running a lockdep kernel for #8 on j416s (M2 Pro). With the fix, the brightness restore at boot runs with lockdep active and no report. Builds with W=1; checkpatch only flags the trailer form.

🤖 Generated with Claude Code

dcp_set_brightness() and drm_crtc_set_brightness() initialize a
drm_modeset_acquire_ctx on the stack but never call
drm_modeset_acquire_fini(), including on their -EDEADLK and -ERESTARTSYS
returns.

With lockdep the acquire context is tracked as a held lock until
ww_acquire_fini(), so it stays on the task's held-lock stack after the
function returns. When the backlight core then unlocks bd->ops_lock,
lockdep walks into the stale entry:

  DEBUG_LOCKS_WARN_ON(1)
  WARNING: kernel/locking/lockdep.c:238 at __lock_acquire+0x938/0x1600
   ...
   mutex_unlock
   backlight_device_set_brightness
   brightness_store
  Unable to handle kernel NULL pointer dereference at virtual address 00000000000000c4

This happens in systemd-backlight on every boot of a PROVE_LOCKING kernel.
Call drm_modeset_acquire_fini() on every exit path.

Tested on j416s (M2 Pro) with PROVE_LOCKING: the brightness restore at
boot runs without a lockdep report.

Fixes: c7f8e49 ("drm/apple: Relax locking for back light updates")
Signed-off-by: Oliver Lukschander <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@RyanTheTide
RyanTheTide merged commit f74df43 into aurora-silicon:aurora-wip Oct 8, 2026
DjDeveloperr pushed a commit that referenced this pull request Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants