git: aa399ad3e554 - stable/13 - bcm_dma: don't dereference NULL softc
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 07 Mar 2023 16:55:42 UTC
The branch stable/13 has been updated by mhorne:
URL: https://cgit.FreeBSD.org/src/commit/?id=aa399ad3e554223b8bf741c3933c38dec92eaf20
commit aa399ad3e554223b8bf741c3933c38dec92eaf20
Author: Mitchell Horne <mhorne@FreeBSD.org>
AuthorDate: 2023-02-24 17:19:54 +0000
Commit: Mitchell Horne <mhorne@FreeBSD.org>
CommitDate: 2023-03-07 16:55:01 +0000
bcm_dma: don't dereference NULL softc
This file defines a small API to be used by other drivers. If any of
these functions are called before the bcm_dma device has attached we
should handle the error gracefully. Fix a formatting quirk while here.
Reviewed by: manu
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D38756
(cherry picked from commit 07ccf71451d7377b1a6f3367f738ce7ddb1f2a24)
---
sys/arm/broadcom/bcm2835/bcm2835_dma.c | 29 ++++++++++++++++++++++-------
1 file changed, 22 insertions(+), 7 deletions(-)
diff --git a/sys/arm/broadcom/bcm2835/bcm2835_dma.c b/sys/arm/broadcom/bcm2835/bcm2835_dma.c
index af86647704f6..f596303959da 100644
--- a/sys/arm/broadcom/bcm2835/bcm2835_dma.c
+++ b/sys/arm/broadcom/bcm2835/bcm2835_dma.c
@@ -328,6 +328,9 @@ bcm_dma_allocate(int req_ch)
int ch = BCM_DMA_CH_INVALID;
int i;
+ if (sc == NULL)
+ return (BCM_DMA_CH_INVALID);
+
if (req_ch >= BCM_DMA_CH_MAX)
return (BCM_DMA_CH_INVALID);
@@ -343,13 +346,10 @@ bcm_dma_allocate(int req_ch)
break;
}
}
- }
- else {
- if (sc->sc_dma_ch[req_ch].flags & BCM_DMA_CH_FREE) {
- ch = req_ch;
- sc->sc_dma_ch[ch].flags &= ~BCM_DMA_CH_FREE;
- sc->sc_dma_ch[ch].flags |= BCM_DMA_CH_USED;
- }
+ } else if (sc->sc_dma_ch[req_ch].flags & BCM_DMA_CH_FREE) {
+ ch = req_ch;
+ sc->sc_dma_ch[ch].flags &= ~BCM_DMA_CH_FREE;
+ sc->sc_dma_ch[ch].flags |= BCM_DMA_CH_USED;
}
mtx_unlock(&sc->sc_mtx);
@@ -364,6 +364,9 @@ bcm_dma_free(int ch)
{
struct bcm_dma_softc *sc = bcm_dma_sc;
+ if (sc == NULL)
+ return (-1);
+
if (ch < 0 || ch >= BCM_DMA_CH_MAX)
return (-1);
@@ -392,6 +395,9 @@ bcm_dma_setup_intr(int ch, void (*func)(int, void *), void *arg)
struct bcm_dma_softc *sc = bcm_dma_sc;
struct bcm_dma_cb *cb;
+ if (sc == NULL)
+ return (-1);
+
if (ch < 0 || ch >= BCM_DMA_CH_MAX)
return (-1);
@@ -531,6 +537,9 @@ bcm_dma_reg_dump(int ch)
int i;
uint32_t reg;
+ if (sc == NULL)
+ return;
+
if (ch < 0 || ch >= BCM_DMA_CH_MAX)
return;
@@ -558,6 +567,9 @@ bcm_dma_start(int ch, vm_paddr_t src, vm_paddr_t dst, int len)
struct bcm_dma_softc *sc = bcm_dma_sc;
struct bcm_dma_cb *cb;
+ if (sc == NULL)
+ return (-1);
+
if (ch < 0 || ch >= BCM_DMA_CH_MAX)
return (-1);
@@ -597,6 +609,9 @@ bcm_dma_length(int ch)
struct bcm_dma_softc *sc = bcm_dma_sc;
struct bcm_dma_cb *cb;
+ if (sc == NULL)
+ return (0);
+
if (ch < 0 || ch >= BCM_DMA_CH_MAX)
return (0);