From nobody Tue Mar 07 16:55:42 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4PWM5W0Q4Cz3wMk4; Tue, 7 Mar 2023 16:55:43 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4PWM5V74fyz4KBX; Tue, 7 Mar 2023 16:55:42 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1678208143; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=BN0OU25KqWaZpvshgZFKwOxFxZJdF4i4F65Jt/Tfsv4=; b=XGL3rmxzXea3kUXaPZRpUbWxMWLP1GLLfGCxqOHcOVGKamoPzkI0S4SyBDlP/NLNOnNn4V g5ws1aR2Uk0+dtTb7crZI3ptijx8KRCeYma8EcFZFLtznifICVSthtwQ4RDXuv1QutoPdB anyTe/RTFmox24DeaI8/d4A4f/vCOJY+jysKCoxd+S5ZfzEaNwiGMb/is+K4zNSbuNXQLp I0Pt+iEXqJc3pdXVp5MjaDsPVaHXLPYIGQzURKgGev00tc1wIEToGFlVBaxNf65Bt9APXj +ljGRSIizml95CeBLAFFN3rHGlVG0F2ZeJADKf4XjwPe3txrdQ4z2QNkwX+1ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1678208143; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=BN0OU25KqWaZpvshgZFKwOxFxZJdF4i4F65Jt/Tfsv4=; b=JwVZueP4UAuSJJ8fjLMYU/9hCz1y8yBBqU/dzylf+YXKBx7DLc9N4N/rcKQayUfF+x+Rha V6AHYdeKdX0I6RcDVlTG/aK3VfJ2CC/CibJqEuPElSAgpUvSE4wPE1gk5JBcqv3ULdSBrs XkZmEH1RWFm/AzoNbKhxJNs1AoYFgv/Qy4+PYP/0NNgLeDvAWUxO1tm6fUpSVQYu8mdmIx xQI/411xyPocTqItUKP50kLV/m33VTUw4yXBHhEyQX57498i1/BnUPeJis9cLprU7HPTxY sqpZlD1cNUMkp8BveH+l+n+EXnKfa1tmjGNDNp6a+PYb4nKjUoX0c3CnKzV7ag== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1678208143; a=rsa-sha256; cv=none; b=HI7I15KJL8/POm52vqpgktjfsruo9ijoUHWZKXI1GHhMePRujMGmS35akv/ywFMKYy3RqH 8UsOfiuf3/fDEGDWAGAAjwucQm8eknVI/Kd1F1hID8cc/gJVrJwDO3KQwyyT9CzHQppdop LRwKncx4br0FjXAgNrVvXxxWR3TMci8R3gEhGXXm+vT43XVPnuNt2I0PgUr56v6M8dOUzz Hbq+ioAwe2GAxWMRHv2cuS31tBdpYFg0S4AujorIyAAnO3XxkmCWvwjH2Exl4lf2Rtu09r Se2Oh8So4qGoEHv32my4nIx7YlFpEwZPPD0iN3k47hYvvgoGmusnCoDvIHd+pA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4PWM5V5rBSzrMK; Tue, 7 Mar 2023 16:55:42 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 327GtguK022910; Tue, 7 Mar 2023 16:55:42 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 327GtgZ9022909; Tue, 7 Mar 2023 16:55:42 GMT (envelope-from git) Date: Tue, 7 Mar 2023 16:55:42 GMT Message-Id: <202303071655.327GtgZ9022909@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mitchell Horne Subject: git: aa399ad3e554 - stable/13 - bcm_dma: don't dereference NULL softc List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mhorne X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: aa399ad3e554223b8bf741c3933c38dec92eaf20 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=aa399ad3e554223b8bf741c3933c38dec92eaf20 commit aa399ad3e554223b8bf741c3933c38dec92eaf20 Author: Mitchell Horne AuthorDate: 2023-02-24 17:19:54 +0000 Commit: Mitchell Horne 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);