diff options
author | imp <imp@FreeBSD.org> | 2008-11-15 05:22:06 +0000 |
---|---|---|
committer | imp <imp@FreeBSD.org> | 2008-11-15 05:22:06 +0000 |
commit | 862fc67526cb57f9b4ad7f24c3711a316713a135 (patch) | |
tree | 5c675bf92a0398b7367e4c987d9b427d3b9e7584 /sys/dev/cardbus/cardbus_device.c | |
parent | 9ceaef29da47a3572a10eb075ebe3ed6115f9218 (diff) | |
download | FreeBSD-src-862fc67526cb57f9b4ad7f24c3711a316713a135.zip FreeBSD-src-862fc67526cb57f9b4ad7f24c3711a316713a135.tar.gz |
First step in cleaning up CIS parsing and /dev/cardbus*.cis: remove
redundant malloc/free. Add comments about how this should really be
done. Fix an overly verbose comment about under 1MB mapping: go ahead
and set the bits, but we ignore them.
Diffstat (limited to 'sys/dev/cardbus/cardbus_device.c')
-rw-r--r-- | sys/dev/cardbus/cardbus_device.c | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/sys/dev/cardbus/cardbus_device.c b/sys/dev/cardbus/cardbus_device.c index c03a18a..a409e0f 100644 --- a/sys/dev/cardbus/cardbus_device.c +++ b/sys/dev/cardbus/cardbus_device.c @@ -96,13 +96,17 @@ cardbus_build_cis(device_t cbdev, device_t child, int id, * CISTPL_END is a special case, it has no length field. */ if (id == CISTPL_END) { - if (cis->len + 1 > sizeof(cis->buffer)) + if (cis->len + 1 > sizeof(cis->buffer)) { + cis->len = 0; return (ENOSPC); + } cis->buffer[cis->len++] = id; return (0); } - if (cis->len + 2 + len > sizeof(cis->buffer)) + if (cis->len + 2 + len > sizeof(cis->buffer)) { + cis->len = 0; return (ENOSPC); + } cis->buffer[cis->len++] = id; cis->buffer[cis->len++] = len; for (i = 0; i < len; i++) @@ -110,6 +114,18 @@ cardbus_build_cis(device_t cbdev, device_t child, int id, return (0); } +static int +cardbus_device_buffer_cis(device_t parent, device_t child) +{ + struct cardbus_softc *sc; + struct tuple_callbacks cb[] = { + {CISTPL_GENERIC, "GENERIC", cardbus_build_cis} + }; + + sc = device_get_softc(parent); + return (cardbus_parse_cis(parent, child, cb, &sc->sc_cis)); +} + static int cardbus_open(struct cdev *dev, int oflags, int devtype, struct thread *td) { @@ -117,9 +133,6 @@ cardbus_open(struct cdev *dev, int oflags, int devtype, struct thread *td) device_t *kids; int cnt, err; struct cardbus_softc *sc; - struct tuple_callbacks cb[] = { - {CISTPL_GENERIC, "GENERIC", cardbus_build_cis} - }; sc = dev->si_drv1; if (sc->sc_cis_open) @@ -128,21 +141,17 @@ cardbus_open(struct cdev *dev, int oflags, int devtype, struct thread *td) err = device_get_children(parent, &kids, &cnt); if (err) return err; + sc->sc_cis.len = 0; if (cnt == 0) { free(kids, M_TEMP); sc->sc_cis_open++; - sc->sc_cis = NULL; return (0); } child = kids[0]; free(kids, M_TEMP); - sc->sc_cis = malloc(sizeof(*sc->sc_cis), M_TEMP, M_ZERO | M_WAITOK); - err = cardbus_parse_cis(parent, child, cb, sc->sc_cis); - if (err) { - free(sc->sc_cis, M_TEMP); - sc->sc_cis = NULL; + err = cardbus_device_buffer_cis(parent, child); + if (err) return (err); - } sc->sc_cis_open++; return (0); } @@ -153,8 +162,6 @@ cardbus_close(struct cdev *dev, int fflags, int devtype, struct thread *td) struct cardbus_softc *sc; sc = dev->si_drv1; - free(sc->sc_cis, M_TEMP); - sc->sc_cis = NULL; sc->sc_cis_open = 0; return (0); } @@ -173,8 +180,8 @@ cardbus_read(struct cdev *dev, struct uio *uio, int ioflag) sc = dev->si_drv1; /* EOF */ - if (sc->sc_cis == NULL || uio->uio_offset > sc->sc_cis->len) + if (uio->uio_offset >= sc->sc_cis.len) return (0); - return (uiomove(sc->sc_cis->buffer + uio->uio_offset, - MIN(uio->uio_resid, sc->sc_cis->len - uio->uio_offset), uio)); + return (uiomove(sc->sc_cis.buffer + uio->uio_offset, + MIN(uio->uio_resid, sc->sc_cis.len - uio->uio_offset), uio)); } |