From: tobhe Date: Sun, 6 Aug 2023 14:30:08 +0000 (+0000) Subject: Add acpi_softc == NULL checks and return ENXIO instead of crashing on X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=a3c01fdf739ad84fa95a0f8881d1f4a239b75653;p=openbsd Add acpi_softc == NULL checks and return ENXIO instead of crashing on non-acpi x86 machines. This was lost in refactoring when moving /dev/apm code from acpi.c to acpi_apm.c. Found by Anton Lindqvist after report from xavier.s at mailoo dot org ok kettenis@ --- diff --git a/sys/dev/acpi/acpi_apm.c b/sys/dev/acpi/acpi_apm.c index dc222cec166..c10e9d8607f 100644 --- a/sys/dev/acpi/acpi_apm.c +++ b/sys/dev/acpi/acpi_apm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: acpi_apm.c,v 1.2 2023/07/08 14:44:43 tobhe Exp $ */ +/* $OpenBSD: acpi_apm.c,v 1.3 2023/08/06 14:30:08 tobhe Exp $ */ /* * Copyright (c) 2005 Thorsten Lockert * Copyright (c) 2005 Jordan Hargrave @@ -47,6 +47,9 @@ acpiopen(dev_t dev, int flag, int mode, struct proc *p) struct acpi_softc *sc = acpi_softc; int s; + if (sc == NULL) + return (ENXIO); + s = splbio(); switch (APMDEV(dev)) { case APMDEV_CTL: @@ -82,6 +85,9 @@ acpiclose(dev_t dev, int flag, int mode, struct proc *p) struct acpi_softc *sc = acpi_softc; int s; + if (sc == NULL) + return (ENXIO); + s = splbio(); switch (APMDEV(dev)) { case APMDEV_CTL: @@ -106,6 +112,9 @@ acpiioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p) struct apm_power_info *pi = (struct apm_power_info *)data; int s; + if (sc == NULL) + return (ENXIO); + s = splbio(); /* fake APM */ switch (cmd) { @@ -168,6 +177,9 @@ acpikqfilter(dev_t dev, struct knote *kn) struct acpi_softc *sc = acpi_softc; int s; + if (sc == NULL) + return (ENXIO); + switch (kn->kn_filter) { case EVFILT_READ: kn->kn_fop = &acpiread_filtops;