-/* $OpenBSD: sdmmc_scsi.c,v 1.39 2017/04/06 03:15:29 deraadt Exp $ */
+/* $OpenBSD: sdmmc_scsi.c,v 1.40 2017/04/06 17:00:53 deraadt Exp $ */
/*
* Copyright (c) 2006 Uwe Stuehler <uwe@openbsd.org>
struct sdmmc_scsi_target *sc_tgt;
int sc_ntargets;
struct sdmmc_ccb *sc_ccbs; /* allocated ccbs */
+ int sc_nccbs;
struct sdmmc_ccb_list sc_ccb_freeq; /* free ccbs */
struct sdmmc_ccb_list sc_ccb_runq; /* queued ccbs */
struct mutex sc_ccb_mtx;
scbus = malloc(sizeof *scbus, M_DEVBUF, M_WAITOK | M_ZERO);
- scbus->sc_tgt = malloc(sizeof(*scbus->sc_tgt) *
+ scbus->sc_tgt = mallocarray(sizeof(*scbus->sc_tgt),
(SDMMC_SCSIID_MAX+1), M_DEVBUF, M_WAITOK | M_ZERO);
/*
sc->sc_scsibus = NULL;
sdmmc_free_ccbs(scbus);
free_sctgt:
- free(scbus->sc_tgt, M_DEVBUF, 0);
+ free(scbus->sc_tgt, M_DEVBUF,
+ sizeof(*scbus->sc_tgt) * (SDMMC_SCSIID_MAX+1));
free(scbus, M_DEVBUF, sizeof *scbus);
}
config_detach(scbus->sc_child, DETACH_FORCE);
if (scbus->sc_tgt != NULL)
- free(scbus->sc_tgt, M_DEVBUF, 0);
+ free(scbus->sc_tgt, M_DEVBUF,
+ sizeof(*scbus->sc_tgt) * (SDMMC_SCSIID_MAX+1));
sdmmc_free_ccbs(scbus);
free(scbus, M_DEVBUF, sizeof *scbus);
M_DEVBUF, M_NOWAIT);
if (scbus->sc_ccbs == NULL)
return 1;
+ scbus->sc_nccbs = nccbs;
TAILQ_INIT(&scbus->sc_ccb_freeq);
TAILQ_INIT(&scbus->sc_ccb_runq);
sdmmc_free_ccbs(struct sdmmc_scsi_softc *scbus)
{
if (scbus->sc_ccbs != NULL) {
- free(scbus->sc_ccbs, M_DEVBUF, 0);
+ free(scbus->sc_ccbs, M_DEVBUF,
+ scbus->sc_nccbs * sizeof(struct sdmmc_ccb));
scbus->sc_ccbs = NULL;
}
}