On Mon, Mar 16, 2020 at 10:16:34AM +0100, Patrick Wildt wrote:
> Otherwise, if we want to do that in acpivout_get_brightness(),
> I guess we can update acpivout_select_brightness() and its caller
> to remove the check for -1, since there will be no -1 anymore?
> 

Sure, I missed those. Here's a new diff with the checks
removed. Tested and works as expected on my machne.

Index: acpivout.c
===================================================================
RCS file: /cvs/src/sys/dev/acpi/acpivout.c,v
retrieving revision 1.19
diff -u -p -r1.19 acpivout.c
--- acpivout.c  8 Feb 2020 19:08:17 -0000       1.19
+++ acpivout.c  16 Mar 2020 14:42:17 -0000
@@ -227,8 +227,10 @@ acpivout_get_brightness(struct acpivout_
        aml_freevalue(&res);
        DPRINTF(("%s: BQC = %d\n", DEVNAME(sc), level));
 
-       if (level < sc->sc_bcl[0] || level > sc->sc_bcl[sc->sc_bcl_len -1])
-               level = -1;
+       if (level < sc->sc_bcl[0])
+               level = sc->sc_bcl[0];
+       else if (level > sc->sc_bcl[sc->sc_bcl_len - 1])
+               level = sc->sc_bcl[sc->sc_bcl_len - 1];
 
        return (level);
 }
@@ -239,9 +241,6 @@ acpivout_select_brightness(struct acpivo
        int nindex, level;
 
        level = sc->sc_brightness;
-       if (level == -1)
-               return level;
-
        nindex = acpivout_find_brightness(sc, nlevel);
        if (sc->sc_bcl[nindex] == level) {
                if (nlevel > level && (nindex + 1 < sc->sc_bcl_len))
@@ -375,13 +374,11 @@ acpivout_set_param(struct wsdisplay_para
                }
                if (sc != NULL && sc->sc_bcl_len != 0) {
                        nindex = acpivout_select_brightness(sc, dp->curval);
-                       if (nindex != -1) {
-                               sc->sc_brightness = sc->sc_bcl[nindex];
-                               acpi_addtask(sc->sc_acpi,
-                                   acpivout_set_brightness, sc, 0);
-                               acpi_wakeup(sc->sc_acpi);
-                               return 0;
-                       }
+                       sc->sc_brightness = sc->sc_bcl[nindex];
+                       acpi_addtask(sc->sc_acpi,
+                           acpivout_set_brightness, sc, 0);
+                       acpi_wakeup(sc->sc_acpi);
+                       return 0;
                }
                return -1;
        default:

Reply via email to