DF-5745 / fix.diff
--- a/sys/gnu/dev/misc/apple_gmux/apple-gmux.c +++ b/sys/gnu/dev/misc/apple_gmux/apple-gmux.c @@ -508,6 +508,10 @@ static int gmux_switchto(enum vga_switcheroo_client_id id) { + if (apple_gmux_softc_data == NULL) { + pr_err("no gmux softc in switchto\n"); + return (-ENODEV); + } apple_gmux_softc_data->switch_state_ddc = id; apple_gmux_softc_data->switch_state_display = id; apple_gmux_softc_data->switch_state_external = id; @@ -520,6 +524,10 @@ static int gmux_switch_ddc(enum vga_switcheroo_client_id id) { + if (apple_gmux_softc_data == NULL) { + pr_err("no gmux softc in switch_ddc\n"); + return (-ENODEV); + } enum vga_switcheroo_client_id old_ddc_owner = apple_gmux_softc_data->switch_state_ddc; @@ -575,6 +583,8 @@ gmux_set_power_state(enum vga_switcheroo_client_id id, enum vga_switcheroo_state state) { + if (apple_gmux_softc_data == NULL) + return (-ENODEV); if (id == VGA_SWITCHEROO_IGD) return 0; @@ -864,7 +890,8 @@ sc->gpe = -1; } - apple_gmux_softc_data = sc; + if (apple_gmux_softc_data == NULL) + apple_gmux_softc_data = sc; init_completion(&sc->powerchange_done); gmux_enable_interrupts(sc); gmux_read_switch_state(sc); @@ -891,7 +918,8 @@ err_register_handler: gmux_disable_interrupts(sc); - apple_gmux_softc_data = NULL; + if (apple_gmux_softc_data == sc) + apple_gmux_softc_data = NULL; if (sc->gpe >= 0) AcpiDisableGpe(NULL, sc->gpe); err_enable_gpe: @@ -922,7 +950,8 @@ gmux_notify_handler); } - apple_gmux_softc_data = NULL; + if (apple_gmux_softc_data == sc) + apple_gmux_softc_data = NULL; #if 0 /* collides with i915*/ drm_fini_pdev(&sc->pdev); #endif |