From 0fe5d515c6acb3f04b18b2236b53c53339d7cfae Mon Sep 17 00:00:00 2001 From: mglocker Date: Fri, 14 Jun 2024 13:38:15 +0000 Subject: [PATCH] Improve return value handling of functions. no objections from deraadt@ --- sys/dev/ic/ufshci.c | 81 ++++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 41 deletions(-) diff --git a/sys/dev/ic/ufshci.c b/sys/dev/ic/ufshci.c index 75415458d94..cdd3494cea4 100644 --- a/sys/dev/ic/ufshci.c +++ b/sys/dev/ic/ufshci.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ufshci.c,v 1.35 2024/06/09 03:21:54 jsg Exp $ */ +/* $OpenBSD: ufshci.c,v 1.36 2024/06/14 13:38:15 mglocker Exp $ */ /* * Copyright (c) 2022 Marcus Glocker @@ -68,7 +68,7 @@ void ufshci_dmamem_free(struct ufshci_softc *, struct ufshci_dmamem *); int ufshci_alloc(struct ufshci_softc *); int ufshci_init(struct ufshci_softc *); -int ufshci_disable(struct ufshci_softc *); +void ufshci_disable(struct ufshci_softc *); int ufshci_doorbell_read(struct ufshci_softc *); void ufshci_doorbell_write(struct ufshci_softc *, int); int ufshci_doorbell_poll(struct ufshci_softc *, int, @@ -88,7 +88,7 @@ int ufshci_utr_cmd_io(struct ufshci_softc *, int ufshci_utr_cmd_sync(struct ufshci_softc *, struct ufshci_ccb *, struct scsi_xfer *, uint32_t, uint16_t); -int ufshci_xfer_complete(struct ufshci_softc *); +void ufshci_xfer_complete(struct ufshci_softc *); /* SCSI */ int ufshci_ccb_alloc(struct ufshci_softc *, int); @@ -177,7 +177,8 @@ ufshci_attach(struct ufshci_softc *sc) SIMPLEQ_INIT(&sc->sc_ccb_list); scsi_iopool_init(&sc->sc_iopool, sc, ufshci_ccb_get, ufshci_ccb_put); - ufshci_reset(sc); + if (ufshci_reset(sc)) + return 1; sc->sc_ver = UFSHCI_READ_4(sc, UFSHCI_REG_VER); printf(", UFSHCI %d.%d%d\n", @@ -240,8 +241,10 @@ ufshci_attach(struct ufshci_softc *sc) sc->sc_flags |= UFSHCI_FLAGS_AGGR_INTR; /* Enable intr. aggregation */ #endif /* Allocate the DMA buffers and initialize the controller. */ - ufshci_alloc(sc); - ufshci_init(sc); + if (ufshci_alloc(sc)) + return 1; + if (ufshci_init(sc)) + return 1; if (ufshci_ccb_alloc(sc, sc->sc_nutrs) != 0) { printf("%s: %s: Can't allocate CCBs\n", @@ -294,7 +297,7 @@ ufshci_reset(struct ufshci_softc *sc) if (i == retry) { printf("%s: Enabling Host Controller failed!\n", sc->sc_dev.dv_xname); - return -1; + return 1; } DPRINTF(2, "\n%s: Host Controller enabled (i=%d)\n", __func__, i); @@ -318,7 +321,7 @@ ufshci_is_poll(struct ufshci_softc *sc, uint32_t type) } if (i == retry) { printf("%s: %s: timeout\n", sc->sc_dev.dv_xname, __func__); - return -1; + return 1; } DPRINTF(3, "%s: completed after %d retries\n", __func__, i); @@ -394,7 +397,7 @@ ufshci_alloc(struct ufshci_softc *sc) if (sc->sc_dmamem_utmrd == NULL) { printf("%s: Can't allocate DMA memory for UTMRD\n", sc->sc_dev.dv_xname); - return -1; + return 1; } /* 7.1.1 Host Controller Initialization: 15) */ @@ -403,7 +406,7 @@ ufshci_alloc(struct ufshci_softc *sc) if (sc->sc_dmamem_utrd == NULL) { printf("%s: Can't allocate DMA memory for UTRD\n", sc->sc_dev.dv_xname); - return -1; + return 1; } /* Allocate UCDs. */ @@ -412,7 +415,7 @@ ufshci_alloc(struct ufshci_softc *sc) if (sc->sc_dmamem_ucd == NULL) { printf("%s: Can't allocate DMA memory for UCD\n", sc->sc_dev.dv_xname); - return -1; + return 1; } return 0; @@ -442,8 +445,8 @@ ufshci_init(struct ufshci_softc *sc) /* 7.1.1 Host Controller Initialization: 6) */ UFSHCI_WRITE_4(sc, UFSHCI_REG_UICCMD, UFSHCI_REG_UICCMD_CMDOP_DME_LINKSTARTUP); - if (ufshci_is_poll(sc, UFSHCI_REG_IS_UCCS) != 0) - return -1; + if (ufshci_is_poll(sc, UFSHCI_REG_IS_UCCS)) + return 1; /* * 7.1.1 Host Controller Initialization: 7), 8), 9) @@ -503,7 +506,7 @@ ufshci_init(struct ufshci_softc *sc) return 0; } -int +void ufshci_disable(struct ufshci_softc *sc) { /* Stop run queues. */ @@ -512,8 +515,6 @@ ufshci_disable(struct ufshci_softc *sc) /* Disable interrupts. */ UFSHCI_WRITE_4(sc, UFSHCI_REG_IE, 0); - - return 0; } int @@ -553,7 +554,7 @@ ufshci_doorbell_poll(struct ufshci_softc *sc, int slot, uint32_t timeout_ms) } if (timeout_us == 0) { printf("%s: %s: timeout\n", sc->sc_dev.dv_xname, __func__); - return -1; + return 1; } return 0; @@ -636,7 +637,7 @@ ufshci_utr_cmd_nop(struct ufshci_softc *sc, struct ufshci_ccb *ccb, if (UFSHCI_READ_4(sc, UFSHCI_REG_UTRLRSR) != 1) { printf("%s: %s: UTRLRSR not set\n", sc->sc_dev.dv_xname, __func__); - return -1; + return 1; } bus_dmamap_sync(sc->sc_dmat, UFSHCI_DMA_MAP(sc->sc_dmamem_utrd), @@ -746,7 +747,7 @@ ufshci_utr_cmd_lun(struct ufshci_softc *sc, struct ufshci_ccb *ccb, if (UFSHCI_READ_4(sc, UFSHCI_REG_UTRLRSR) != 1) { printf("%s: %s: UTRLRSR not set\n", sc->sc_dev.dv_xname, __func__); - return -1; + return 1; } bus_dmamap_sync(sc->sc_dmat, UFSHCI_DMA_MAP(sc->sc_dmamem_utrd), @@ -854,7 +855,7 @@ ufshci_utr_cmd_inquiry(struct ufshci_softc *sc, struct ufshci_ccb *ccb, if (UFSHCI_READ_4(sc, UFSHCI_REG_UTRLRSR) != 1) { printf("%s: %s: UTRLRSR not set\n", sc->sc_dev.dv_xname, __func__); - return -1; + return 1; } bus_dmamap_sync(sc->sc_dmat, UFSHCI_DMA_MAP(sc->sc_dmamem_utrd), @@ -866,7 +867,7 @@ ufshci_utr_cmd_inquiry(struct ufshci_softc *sc, struct ufshci_ccb *ccb, ccb->ccb_status = CCB_STATUS_INPROGRESS; ufshci_doorbell_write(sc, slot); - return slot; + return 0; } int @@ -966,7 +967,7 @@ ufshci_utr_cmd_capacity16(struct ufshci_softc *sc, struct ufshci_ccb *ccb, if (UFSHCI_READ_4(sc, UFSHCI_REG_UTRLRSR) != 1) { printf("%s: %s: UTRLRSR not set\n", sc->sc_dev.dv_xname, __func__); - return -1; + return 1; } bus_dmamap_sync(sc->sc_dmat, UFSHCI_DMA_MAP(sc->sc_dmamem_utrd), @@ -978,7 +979,7 @@ ufshci_utr_cmd_capacity16(struct ufshci_softc *sc, struct ufshci_ccb *ccb, ccb->ccb_status = CCB_STATUS_INPROGRESS; ufshci_doorbell_write(sc, slot); - return slot; + return 0; } int @@ -1077,7 +1078,7 @@ ufshci_utr_cmd_capacity(struct ufshci_softc *sc, struct ufshci_ccb *ccb, if (UFSHCI_READ_4(sc, UFSHCI_REG_UTRLRSR) != 1) { printf("%s: %s: UTRLRSR not set\n", sc->sc_dev.dv_xname, __func__); - return -1; + return 1; } bus_dmamap_sync(sc->sc_dmat, UFSHCI_DMA_MAP(sc->sc_dmamem_utrd), @@ -1089,7 +1090,7 @@ ufshci_utr_cmd_capacity(struct ufshci_softc *sc, struct ufshci_ccb *ccb, ccb->ccb_status = CCB_STATUS_INPROGRESS; ufshci_doorbell_write(sc, slot); - return slot; + return 0; } int @@ -1200,7 +1201,7 @@ ufshci_utr_cmd_io(struct ufshci_softc *sc, struct ufshci_ccb *ccb, if (UFSHCI_READ_4(sc, UFSHCI_REG_UTRLRSR) != 1) { printf("%s: %s: UTRLRSR not set\n", sc->sc_dev.dv_xname, __func__); - return -1; + return 1; } bus_dmamap_sync(sc->sc_dmat, UFSHCI_DMA_MAP(sc->sc_dmamem_utrd), @@ -1212,7 +1213,7 @@ ufshci_utr_cmd_io(struct ufshci_softc *sc, struct ufshci_ccb *ccb, ccb->ccb_status = CCB_STATUS_INPROGRESS; ufshci_doorbell_write(sc, slot); - return slot; + return 0; } int @@ -1302,7 +1303,7 @@ ufshci_utr_cmd_sync(struct ufshci_softc *sc, struct ufshci_ccb *ccb, if (UFSHCI_READ_4(sc, UFSHCI_REG_UTRLRSR) != 1) { printf("%s: %s: UTRLRSR not set\n", sc->sc_dev.dv_xname, __func__); - return -1; + return 1; } bus_dmamap_sync(sc->sc_dmat, UFSHCI_DMA_MAP(sc->sc_dmamem_utrd), @@ -1314,10 +1315,10 @@ ufshci_utr_cmd_sync(struct ufshci_softc *sc, struct ufshci_ccb *ccb, ccb->ccb_status = CCB_STATUS_INPROGRESS; ufshci_doorbell_write(sc, slot); - return slot; + return 0; } -int +void ufshci_xfer_complete(struct ufshci_softc *sc) { struct ufshci_ccb *ccb; @@ -1374,8 +1375,6 @@ ufshci_xfer_complete(struct ufshci_softc *sc) if (ccb->ccb_status == CCB_STATUS_READY2FREE) ccb->ccb_done(sc, ccb); } - - return 0; } int @@ -1589,7 +1588,7 @@ ufshci_scsi_inquiry(struct scsi_xfer *xs) error = bus_dmamap_load(sc->sc_dmat, dmap, xs->data, xs->datalen, NULL, ISSET(xs->flags, SCSI_NOSLEEP) ? BUS_DMA_NOWAIT : BUS_DMA_WAITOK); - if (error != 0) { + if (error) { printf("%s: bus_dmamap_load error=%d\n", __func__, error); goto error1; } @@ -1602,7 +1601,7 @@ ufshci_scsi_inquiry(struct scsi_xfer *xs) /* Response length should be UPIU_SCSI_RSP_INQUIRY_SIZE. */ error = ufshci_utr_cmd_inquiry(sc, ccb, xs); - if (error == -1) + if (error) goto error2; if (ISSET(xs->flags, SCSI_POLL)) { @@ -1644,7 +1643,7 @@ ufshci_scsi_capacity16(struct scsi_xfer *xs) error = bus_dmamap_load(sc->sc_dmat, dmap, xs->data, xs->datalen, NULL, ISSET(xs->flags, SCSI_NOSLEEP) ? BUS_DMA_NOWAIT : BUS_DMA_WAITOK); - if (error != 0) { + if (error) { printf("%s: bus_dmamap_load error=%d\n", __func__, error); goto error1; } @@ -1657,7 +1656,7 @@ ufshci_scsi_capacity16(struct scsi_xfer *xs) /* Response length should be UPIU_SCSI_RSP_CAPACITY16_SIZE. */ error = ufshci_utr_cmd_capacity16(sc, ccb, xs); - if (error == -1) + if (error) goto error2; if (ISSET(xs->flags, SCSI_POLL)) { @@ -1699,7 +1698,7 @@ ufshci_scsi_capacity(struct scsi_xfer *xs) error = bus_dmamap_load(sc->sc_dmat, dmap, xs->data, xs->datalen, NULL, ISSET(xs->flags, SCSI_NOSLEEP) ? BUS_DMA_NOWAIT : BUS_DMA_WAITOK); - if (error != 0) { + if (error) { printf("%s: bus_dmamap_load error=%d\n", __func__, error); goto error1; } @@ -1712,7 +1711,7 @@ ufshci_scsi_capacity(struct scsi_xfer *xs) /* Response length should be UPIU_SCSI_RSP_CAPACITY_SIZE */ error = ufshci_utr_cmd_capacity(sc, ccb, xs); - if (error == -1) + if (error) goto error2; if (ISSET(xs->flags, SCSI_POLL)) { @@ -1757,7 +1756,7 @@ ufshci_scsi_sync(struct scsi_xfer *xs) error = ufshci_utr_cmd_sync(sc, ccb, xs, (uint32_t)lba, (uint16_t)blocks); - if (error == -1) + if (error) goto error; if (ISSET(xs->flags, SCSI_POLL)) { @@ -1797,7 +1796,7 @@ ufshci_scsi_io(struct scsi_xfer *xs, int dir) error = bus_dmamap_load(sc->sc_dmat, dmap, xs->data, xs->datalen, NULL, ISSET(xs->flags, SCSI_NOSLEEP) ? BUS_DMA_NOWAIT : BUS_DMA_WAITOK); - if (error != 0) { + if (error) { printf("%s: bus_dmamap_load error=%d\n", __func__, error); goto error1; } @@ -1813,7 +1812,7 @@ ufshci_scsi_io(struct scsi_xfer *xs, int dir) error = ufshci_utr_cmd_io(sc, ccb, xs, SCSI_DATA_IN); else error = ufshci_utr_cmd_io(sc, ccb, xs, SCSI_DATA_OUT); - if (error == -1) + if (error) goto error2; if (ISSET(xs->flags, SCSI_POLL)) { -- 2.20.1