From nobody Thu Jan 04 13:48:05 2024 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 4T5Sb941YLz56R9x; Thu, 4 Jan 2024 13:48:05 +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 4T5Sb92fS0z45lY; Thu, 4 Jan 2024 13:48:05 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1704376085; 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=tESDQLtLeuq7s9RJWm9PGPMnRvxS2h54XYaKwGY/zFE=; b=oGqjkSz/LXk51IDhuU700vSqJvHCxTp0i6T/V3R03SoQJ4GrFClyU0bLF1VQurfdaU69/A z6iUOqcs5m7RP/qSjQBlqrKRmPLSoUlartW3nI7Ah42c0nl+Tq6EReh2Btz35WkAvU3l// PK5Jj97lBD+pDZVuNHciWGJ9hnL0yZokWO8YBtm3kFCLQUnC4bat1uMNWSMZJDcmQ9VJIP s9+lsbp8ovbSxxuDpRw61GlRv+O0clj7iEQvYO44LVEL3UnedfB4M9SrvkKPo+/qv9yq6+ TvKE60iEj0KYb6HVRf5vyXXQLfDgXJbQzmqoUs3ZCZvU0scDC6l4jPtryTWnxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1704376085; 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=tESDQLtLeuq7s9RJWm9PGPMnRvxS2h54XYaKwGY/zFE=; b=xLhIe3PL3hzDpk4y5hJ/0G7RjPjLgHdanqM4gfu5z5d0CRwtQ9S3pXB1joq++z815GbNB/ a7MRvwRF+RqWvAdeNX7PyNsD65Z2MT7iogjYIlsnn7EY7xfEY9frMETFIk5XegDjQlQ3cA Bg1eYvSMwPJCJ6VnQeDXirsi/Px1vnWqagy2tUjf8sF6FKC7FFOznmfGnMSUQ1Td1KX5BH qcHFTltaSk8Ei3R3fqukCRKKdEU9eAw9jB555H3EV8PmxDz+F78IB5G7zxAwTgKAq9Sha5 MMzy6TgCrfUeZHD/vB3KhJ/+mMn+LyN1ZDHHC6DDgULV/z2G9qAgKo5bvsXDyg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1704376085; a=rsa-sha256; cv=none; b=TOfNYE31NYCf5Jb3u3KByoe9MeVqZ4QydDSjFQX05fSU4pIorEX5g3xKuE581GjPlOxdG4 crTuzaZ2c2qDZ/ROGIEAERimmy4K8JAqd7A5E/fwlOXpQfZqJwhhkExeWWiryzjaKHklSN ck89KEVKMcWsFCbFojjzrUIbHNIS7pRxIxrHemNNDrR+ceVJUl95fj0KmaSe+W7p9LVOTt 3lpYV2xdC+kiaXFxMLp3srWgb5suYwriRHznV5Z0WkmOrJJ3fqIRhJyDu8xsFGtDCkpq1w iCAJVhtCK5dBJPKuxyl7iU++rBMTYtG+Mx1dvYiZPOUJQpthJb4B9AdxmK5T/w== 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 4T5Sb91ltGzGM0; Thu, 4 Jan 2024 13:48:05 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 404Dm5OP049833; Thu, 4 Jan 2024 13:48:05 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 404Dm5rD049830; Thu, 4 Jan 2024 13:48:05 GMT (envelope-from git) Date: Thu, 4 Jan 2024 13:48:05 GMT Message-Id: <202401041348.404Dm5rD049830@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 2c840bedd6bb - stable/14 - ti: Handle errors from copyin() and copyout() 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: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 2c840bedd6bbbbe679163a6a9740fd9762d4d945 Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=2c840bedd6bbbbe679163a6a9740fd9762d4d945 commit 2c840bedd6bbbbe679163a6a9740fd9762d4d945 Author: Mark Johnston AuthorDate: 2023-12-26 23:58:24 +0000 Commit: Mark Johnston CommitDate: 2024-01-04 13:42:13 +0000 ti: Handle errors from copyin() and copyout() This is in preparation for annotating copyin() and related functions with __result_use_check. MFC after: 1 week (cherry picked from commit 916273680b6d6439a117d6cf8c2d7423234bc1c0) --- sys/dev/ti/if_ti.c | 56 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/sys/dev/ti/if_ti.c b/sys/dev/ti/if_ti.c index 4d7f43f080cb..6f88862d8009 100644 --- a/sys/dev/ti/if_ti.c +++ b/sys/dev/ti/if_ti.c @@ -502,11 +502,13 @@ ti_copy_mem(struct ti_softc *sc, uint32_t tigon_addr, uint32_t len, int segptr, segsize, cnt; caddr_t ptr; uint32_t origwin; - int resid, segresid; + int error, resid, segresid; int first_pass; TI_LOCK_ASSERT(sc); + error = 0; + /* * At the moment, we don't handle non-aligned cases, we just bail. * If this proves to be a problem, it will be fixed. @@ -548,7 +550,7 @@ ti_copy_mem(struct ti_softc *sc, uint32_t tigon_addr, uint32_t len, */ origwin = CSR_READ_4(sc, TI_WINBASE); - while (cnt) { + while (cnt != 0 && error == 0) { bus_size_t ti_offset; if (cnt < TI_WINLEN) @@ -573,11 +575,13 @@ ti_copy_mem(struct ti_softc *sc, uint32_t tigon_addr, uint32_t len, TI_UNLOCK(sc); if (first_pass) { - copyout(&sc->ti_membuf2[segresid], ptr, + error = copyout( + &sc->ti_membuf2[segresid], ptr, segsize - segresid); first_pass = 0; } else - copyout(sc->ti_membuf2, ptr, segsize); + error = copyout(sc->ti_membuf2, ptr, + segsize); TI_LOCK(sc); } else { if (first_pass) { @@ -597,7 +601,7 @@ ti_copy_mem(struct ti_softc *sc, uint32_t tigon_addr, uint32_t len, } else { if (useraddr) { TI_UNLOCK(sc); - copyin(ptr, sc->ti_membuf2, segsize); + error = copyin(ptr, sc->ti_membuf2, segsize); TI_LOCK(sc); ti_bcopy_swap(sc->ti_membuf2, sc->ti_membuf, segsize, TI_SWAP_HTON); @@ -605,8 +609,11 @@ ti_copy_mem(struct ti_softc *sc, uint32_t tigon_addr, uint32_t len, ti_bcopy_swap(ptr, sc->ti_membuf, segsize, TI_SWAP_HTON); - bus_space_write_region_4(sc->ti_btag, sc->ti_bhandle, - ti_offset, (uint32_t *)sc->ti_membuf, segsize >> 2); + if (error == 0) { + bus_space_write_region_4(sc->ti_btag, + sc->ti_bhandle, ti_offset, + (uint32_t *)sc->ti_membuf, segsize >> 2); + } } segptr += segsize; ptr += segsize; @@ -616,7 +623,7 @@ ti_copy_mem(struct ti_softc *sc, uint32_t tigon_addr, uint32_t len, /* * Handle leftover, non-word-aligned bytes. */ - if (resid != 0) { + if (resid != 0 && error == 0) { uint32_t tmpval, tmpval2; bus_size_t ti_offset; @@ -649,7 +656,7 @@ ti_copy_mem(struct ti_softc *sc, uint32_t tigon_addr, uint32_t len, */ if (useraddr) { TI_UNLOCK(sc); - copyout(&tmpval2, ptr, resid); + error = copyout(&tmpval2, ptr, resid); TI_LOCK(sc); } else bcopy(&tmpval2, ptr, resid); @@ -667,21 +674,22 @@ ti_copy_mem(struct ti_softc *sc, uint32_t tigon_addr, uint32_t len, */ if (useraddr) { TI_UNLOCK(sc); - copyin(ptr, &tmpval2, resid); + error = copyin(ptr, &tmpval2, resid); TI_LOCK(sc); } else bcopy(ptr, &tmpval2, resid); - tmpval = htonl(tmpval2); - - bus_space_write_region_4(sc->ti_btag, sc->ti_bhandle, - ti_offset, &tmpval, 1); + if (error == 0) { + tmpval = htonl(tmpval2); + bus_space_write_region_4(sc->ti_btag, + sc->ti_bhandle, ti_offset, &tmpval, 1); + } } } CSR_WRITE_4(sc, TI_WINBASE, origwin); - return (0); + return (error); } static int @@ -689,7 +697,7 @@ ti_copy_scratch(struct ti_softc *sc, uint32_t tigon_addr, uint32_t len, caddr_t buf, int useraddr, int readdata, int cpu) { uint32_t segptr; - int cnt; + int cnt, error; uint32_t tmpval, tmpval2; caddr_t ptr; @@ -715,7 +723,7 @@ ti_copy_scratch(struct ti_softc *sc, uint32_t tigon_addr, uint32_t len, cnt = len; ptr = buf; - while (cnt) { + while (cnt && error == 0) { CSR_WRITE_4(sc, CPU_REG(TI_SRAM_ADDR, cpu), segptr); if (readdata) { @@ -756,18 +764,20 @@ ti_copy_scratch(struct ti_softc *sc, uint32_t tigon_addr, uint32_t len, "%#x (tmpval)\n", segptr); if (useraddr) - copyout(&tmpval, ptr, 4); + error = copyout(&tmpval, ptr, 4); else bcopy(&tmpval, ptr, 4); } else { if (useraddr) - copyin(ptr, &tmpval2, 4); + error = copyin(ptr, &tmpval2, 4); else bcopy(ptr, &tmpval2, 4); - tmpval = htonl(tmpval2); - - CSR_WRITE_4(sc, CPU_REG(TI_SRAM_DATA, cpu), tmpval); + if (error == 0) { + tmpval = htonl(tmpval2); + CSR_WRITE_4(sc, CPU_REG(TI_SRAM_DATA, cpu), + tmpval); + } } cnt -= 4; @@ -775,7 +785,7 @@ ti_copy_scratch(struct ti_softc *sc, uint32_t tigon_addr, uint32_t len, ptr += 4; } - return (0); + return (error); } static int