From nobody Fri Feb 24 17:23:35 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 4PNcDl3tFnz3tkF7; Fri, 24 Feb 2023 17:23:35 +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 4PNcDl3QhTz3G7W; Fri, 24 Feb 2023 17:23:35 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1677259415; 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=euQPxlC+dey9MApnJ5Tig4RUk03itdsjZRzpOXWEKXM=; b=aMmMzK9s4idCovPWg1Un5Vhj/G4n+Lk6m62AQkSOeQw8gd9AVuc0rEuv5Ifk+/qbJV/l1m yOHYrKr/2du2S3WT04dH2hJkGtvHKnc0TllaEAY1xBGtVYTYAJIVMQdltys6oyZfj9nZOG lyvneZ7WTEIMm0HjQJwWTm7xpK3tE1ATtJHnKYXVGH6lv5nwoFcDybJvHLssxF0oaOUjj6 TAlN1DiTfGytYdXxAQV2WhvgCmcJ+pQFIVtA6xnrPaOdTKUY8iGZ6a4F6f0y5l5eb0kEyb gdVYNncu7pqRqpNXbctuB2lj75MPGL70F6jbnScAU2gMh9OqidC8PAxUi+9HXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1677259415; 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=euQPxlC+dey9MApnJ5Tig4RUk03itdsjZRzpOXWEKXM=; b=XOlQhbk43U90uleODw9cfu1qjchdPV81ySompAtZGZiU1DigBZsrCBLE3ohkKhlG4zZlo+ IRUtq0krCcC4SD7ctxNx2F4E6Nk9AvT7eebf8O6krEyZq9eU8P/+Iw1kbWf/yKH7xuezH/ SNMlvruudoEKKnOuSOT6zLvEnuBa34qodDCgaQcPhFX/4RTi1C3R03LTS41wFvZSYWIPQp xciAQfhpqfmBClx7DVHWVcvdf6FWN7Le/EVoWCrMpb4pgU8LA3Qa+/7lVlL37p0YzxAZor 59W4RpAwU2u9CPqauaJJAlw3nYSnwOgKhTz1fOqm76CW8KTn8IZI/Ht+/gZfVA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1677259415; a=rsa-sha256; cv=none; b=ym9vl7tbSj44gINBZHbS8Y5UDqB91FDWSFLf1rpszYZ+eJU665m4//F5FlGLM4RPoCBUpN mEpPVXObh8KMCdyHREjioBli1PEz5YUK+YGGg7dj4PuRpn5QAkjju5fkPhb5jPd5VE1sf0 65U2CbXfjdyk2fgBi9Kxg3Q/R/McCyMugeMyWsJUxXm4PAvLEOrgqZz7OuiLL9Tr8IyjoA 3BldpXUjNqHq76Z9+A6q58YTCEzM64qKoENUzY7Z32ZCebrZK+xb7RgfcLleOtvrCakYBd 8LJYxTYSkCAmOLkb71gPvHHBEIDK1ArD72dPUVE8YWeVmSzdRgGaOcG8GODQUw== 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 4PNcDl2ThJzX8M; Fri, 24 Feb 2023 17:23:35 +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 31OHNZWQ092677; Fri, 24 Feb 2023 17:23:35 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 31OHNZOA092676; Fri, 24 Feb 2023 17:23:35 GMT (envelope-from git) Date: Fri, 24 Feb 2023 17:23:35 GMT Message-Id: <202302241723.31OHNZOA092676@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mitchell Horne Subject: git: 07ccf71451d7 - main - 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/main X-Git-Reftype: branch X-Git-Commit: 07ccf71451d7377b1a6f3367f738ce7ddb1f2a24 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=07ccf71451d7377b1a6f3367f738ce7ddb1f2a24 commit 07ccf71451d7377b1a6f3367f738ce7ddb1f2a24 Author: Mitchell Horne AuthorDate: 2023-02-24 17:19:54 +0000 Commit: Mitchell Horne CommitDate: 2023-02-24 17:20:40 +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 --- 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 49a3938282a2..e9633674d9f6 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);