Am Sat, Aug 28, 2021 at 05:22:34PM +1200 schrieb Graeme Neilson:
> >Synopsis:      imxspi causes a kernel panic during boot on novena (armv7)
> >Category:      kernel arm
> >Environment:
>         System      : OpenBSD 6.9
>         Details     : OpenBSD 6.9 (GENERIC) #386: Tue Apr 20 04:06:48 MDT 2021
>                          
> [email protected]:/usr/src/sys/arch/armv7/compile/GENERIC
> 
>         Architecture: OpenBSD.armv7
>         Machine     : armv7
> >Description:
> On the Novena bsd.rd boots and the install is successful but bsd fails to 
> boot due to a panic caused by imxpsi.
> 
> (Note: To be able to boot I had to create u-boot-dtb.img from stock u-boot 
> source. 
> The SPL in the dtb pkg looks for u-boot-dtb.img, not u-boot.img which is 
> supplied in the u-boot pkg, and fails to load load u-boot shell.)

That apparently was my fault.  Typically we store output from
OF_getproplen in an int (signed), because OF_getproplen can
return -1, I think.  This should fix it.

Patrick

diff --git a/sys/dev/fdt/imxspi.c b/sys/dev/fdt/imxspi.c
index 05015f878ef..68bfd62dc6c 100644
--- a/sys/dev/fdt/imxspi.c
+++ b/sys/dev/fdt/imxspi.c
@@ -91,7 +91,7 @@ struct imxspi_softc {
        int                      sc_node;
 
        uint32_t                *sc_gpio;
-       size_t                   sc_gpiolen;
+       int                      sc_gpiolen;
 
        struct rwlock            sc_buslock;
        struct spi_controller    sc_tag;
@@ -178,7 +178,7 @@ imxspi_attachhook(struct device *self)
        clock_enable(sc->sc_node, NULL);
 
        sc->sc_gpiolen = OF_getproplen(sc->sc_node, "cs-gpios");
-       if (sc->sc_gpiolen) {
+       if (sc->sc_gpiolen > 0) {
                sc->sc_gpio = malloc(sc->sc_gpiolen, M_DEVBUF, M_WAITOK);
                OF_getpropintarray(sc->sc_node, "cs-gpios",
                    sc->sc_gpio, sc->sc_gpiolen);
@@ -218,7 +218,8 @@ imxspi_detach(struct device *self, int flags)
 
        HWRITE4(sc, SPI_CONREG, 0);
        bus_space_unmap(sc->sc_iot, sc->sc_ioh, sc->sc_ios);
-       free(sc->sc_gpio, M_DEVBUF, sc->sc_gpiolen);
+       if (sc->sc_gpiolen > 0)
+               free(sc->sc_gpio, M_DEVBUF, sc->sc_gpiolen);
        return 0;
 }
 

Reply via email to