Simple sleeps for 100ms that currently use a timeval to specify
miliseconds, convert them to Hz with tvtohz(9) so they can be converted
back by timeout_add(9) - we can do better by now.

I lack appropiate hardware, but the diff is pretty safe imho.  The fact
that the argument has never been zero and will never be with this diff
makes it safe for timeout_add_msec(9) to now always sleep for at least
one tick.

Feedback? OK?

Index: sys/dev/usb/if_urtw.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/if_urtw.c,v
retrieving revision 1.67
diff -u -p -r1.67 if_urtw.c
--- sys/dev/usb/if_urtw.c       23 Jan 2018 02:53:26 -0000      1.67
+++ sys/dev/usb/if_urtw.c       13 Jun 2019 20:56:22 -0000
@@ -1835,8 +1835,6 @@ fail:
 usbd_status
 urtw_led_mode0(struct urtw_softc *sc, int mode)
 {
-       struct timeval t;
-
        switch (mode) {
        case URTW_LED_CTL_POWER_ON:
                sc->sc_gpio_ledstate = URTW_LED_POWER_ON_BLINK;
@@ -1867,10 +1865,8 @@ urtw_led_mode0(struct urtw_softc *sc, in
                sc->sc_gpio_ledinprogress = 1;
                sc->sc_gpio_blinkstate = (sc->sc_gpio_ledon != 0) ?
                        URTW_LED_OFF : URTW_LED_ON;
-               t.tv_sec = 0;
-               t.tv_usec = 100 * 1000L;
                if (!usbd_is_dying(sc->sc_udev))
-                       timeout_add(&sc->sc_led_ch, tvtohz(&t));
+                       timeout_add_msec(&sc->sc_led_ch, 100);
                break;
        case URTW_LED_POWER_ON_BLINK:
                urtw_led_on(sc, URTW_LED_GPIO);
@@ -1952,7 +1948,6 @@ urtw_led_ctl(struct urtw_softc *sc, int 
 usbd_status
 urtw_led_blink(struct urtw_softc *sc)
 {
-       struct timeval t;
        uint8_t ing = 0;
        usbd_status error;
 
@@ -1987,10 +1982,8 @@ urtw_led_blink(struct urtw_softc *sc)
 
        switch (sc->sc_gpio_ledstate) {
        case URTW_LED_BLINK_NORMAL:
-               t.tv_sec = 0;
-               t.tv_usec = 100 * 1000L;
                if (!usbd_is_dying(sc->sc_udev))
-                       timeout_add(&sc->sc_led_ch, tvtohz(&t));
+                       timeout_add_msec(&sc->sc_led_ch, 100);
                break;
        default:
                break;

Reply via email to