While playing with ipmi(4) attaching to acpi(4) I found out that using
an int for storing addresses isn't a good idea.  If you use it to
store large addresses, the number becomes negative and will be sign
extended when converted into a 64-bit adddress.  The appropriate type
to use here is bus_addr_t.

ok?


Index: dev/ipmivar.h
===================================================================
RCS file: /cvs/src/sys/dev/ipmivar.h,v
retrieving revision 1.31
diff -u -p -r1.31 ipmivar.h
--- dev/ipmivar.h       19 Aug 2019 18:31:02 -0000      1.31
+++ dev/ipmivar.h       18 Dec 2019 16:29:43 -0000
@@ -65,7 +65,7 @@ struct ipmi_attach_args {
        int             iaa_if_type;
        int             iaa_if_rev;
        int             iaa_if_iotype;
-       int             iaa_if_iobase;
+       bus_addr_t      iaa_if_iobase;
        int             iaa_if_iospacing;
        int             iaa_if_irq;
        int             iaa_if_irqlvl;
Index: dev/ipmi.c
===================================================================
RCS file: /cvs/src/sys/dev/ipmi.c,v
retrieving revision 1.105
diff -u -p -r1.105 ipmi.c
--- dev/ipmi.c  19 Aug 2019 18:31:02 -0000      1.105
+++ dev/ipmi.c  18 Dec 2019 16:29:43 -0000
@@ -1450,7 +1450,7 @@ ipmi_map_regs(struct ipmi_softc *sc, str
        if (bus_space_map(sc->sc_iot, ia->iaa_if_iobase,
            sc->sc_if->nregs * sc->sc_if_iospacing,
            0, &sc->sc_ioh)) {
-               printf("%s: bus_space_map(%lx %x %x 0 %p) failed\n",
+               printf("%s: bus_space_map(%lx %lx %x 0 %p) failed\n",
                    DEVNAME(sc),
                    (unsigned long)sc->sc_iot, ia->iaa_if_iobase,
                    sc->sc_if->nregs * sc->sc_if_iospacing, &sc->sc_ioh);
@@ -1540,7 +1540,7 @@ ipmi_attach_common(struct ipmi_softc *sc
        printf(": version %d.%d interface %s",
            ia->iaa_if_rev >> 4, ia->iaa_if_rev & 0xF, sc->sc_if->name);
        if (sc->sc_if->nregs > 0)
-               printf(" %sbase 0x%x/%x spacing %d",
+               printf(" %sbase 0x%lx/%x spacing %d",
                    ia->iaa_if_iotype == 'i' ? "io" : "mem", ia->iaa_if_iobase,
                    ia->iaa_if_iospacing * sc->sc_if->nregs,
                    ia->iaa_if_iospacing);

Reply via email to