From nobody Thu Jan 04 13:48:04 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 4T5Sb84BChz56Qtk; Thu, 4 Jan 2024 13:48:04 +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 4T5Sb825Zwz45WQ; Thu, 4 Jan 2024 13:48:04 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1704376084; 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=CAj6zI3RZIuWkJ0TdyjXGszBRJIUSm+KBBobcd9MOuU=; b=ooSq+GDR8rntyh+e8GC3qGl+SGHgWcY7pgGmy/epG84DSQISGmrAAGLrq0e382GkCNAG2X SvCCWdz3kCBsOZyw4HYIFok4P3IZ8X837t7vk4swV1Bpcp/r6oEgTXC9wShbd1pnprL2NG SbSXgSiFvRS0Grbw3pEupN0UWpjxVbXcboh8ULU/tkq6r0nmXwSCXMiCzVCAlwrfMOYkVu C0xTvOM7q8JQjCpG4jTYtbG01fGeXrwJIrAiar1ZLK/jaNvhLqdq28oethEeoMCv4XxYyb nWesba3ICGRTA/IjhWFNGLulUTtPw2nFOknRS4JkGh8f+xyHl8tPYbCiwNE+Ig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1704376084; 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=CAj6zI3RZIuWkJ0TdyjXGszBRJIUSm+KBBobcd9MOuU=; b=NcrxCP2/tA8n/+5ly2HY/bZej2V6geRIrO9rwoA54WElA74B6UKal54+vHicJ5jXRPTLgz bwYume1ITyAr7X/qbH0YcOeSkLFrYVShZHAGwtbX8kqlT/47cRHCuStWvd8dtiOGnuE2VP Ak/E4ZMUEHAZHLoaIgqVlKGjVD4ui6E8G40jefI+N9WU6hh3hwhaVpx6kQe6OSvwQafX7X F2DuqfIzgGpLakLQM1BlmTk1WC0a2le65tiUfnNGIeOrd+T8eVlUgEdBKG70Ql5JeAW4Nu r9JTl4UEd5nGBVpy29JxHK0ryxHUQN8a69G70dZ1SA0uomZd50+J8c8AJmHu3Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1704376084; a=rsa-sha256; cv=none; b=vrhIgcTJVcWzXSi1ukBIiGHAKyDtSND6rV+S27ZgUjsiWJ+9G3T6gznzEeNP65kr3lDeNb QjXE/O0u+SncADwWLxtgWntC4u8d5z7QSdDavhmpeRtp1SyP0o2kGpcwVqMII0yqZnAMjp vPjDGZr45yp2BprSPZPVX8O5ZKk4lwwOurt8wB5iTy7yCUzvgZVSviF12vrFoFXbBz1jv1 1Rc/GAMDHAHT+i4U+vMP2xxg/giU5NADUG2BV3hzfzl9y+J1SgSXKSIUWtNGDzfx+a+HzO sq48m45l/IlfRUjPJk8TAJ0rjTaAGvvUeLwwLAB9fZRyB56VIGChDTKtqxYntw== 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 4T5Sb80z5RzFhT; Thu, 4 Jan 2024 13:48:04 +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 404Dm47R049785; Thu, 4 Jan 2024 13:48:04 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 404Dm42L049782; Thu, 4 Jan 2024 13:48:04 GMT (envelope-from git) Date: Thu, 4 Jan 2024 13:48:04 GMT Message-Id: <202401041348.404Dm42L049782@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: 9fcacb1e6869 - stable/14 - tdfx: 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: 9fcacb1e6869eec4b8de67e072c64036d074249b Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=9fcacb1e6869eec4b8de67e072c64036d074249b commit 9fcacb1e6869eec4b8de67e072c64036d074249b Author: Mark Johnston AuthorDate: 2023-12-26 23:59:21 +0000 Commit: Mark Johnston CommitDate: 2024-01-04 13:42:13 +0000 tdfx: 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 2873d841f81cdc205135370875d3d71a3402e90a) --- sys/dev/tdfx/tdfx_linux.c | 5 +++-- sys/dev/tdfx/tdfx_pci.c | 48 +++++++++++++++++++++++------------------------ 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/sys/dev/tdfx/tdfx_linux.c b/sys/dev/tdfx/tdfx_linux.c index 56d52753e950..2a51ab6d1cc6 100644 --- a/sys/dev/tdfx/tdfx_linux.c +++ b/sys/dev/tdfx/tdfx_linux.c @@ -59,8 +59,9 @@ linux_ioctl_tdfx(struct thread *td, struct linux_ioctl_args* args) if (error != 0) return (error); /* We simply copy the data and send it right to ioctl */ - copyin((caddr_t)args->arg, &d_pio, sizeof(d_pio)); - error = fo_ioctl(fp, cmd, (caddr_t)&d_pio, td->td_ucred, td); + error = copyin((caddr_t)args->arg, &d_pio, sizeof(d_pio)); + if (error == 0) + error = fo_ioctl(fp, cmd, (caddr_t)&d_pio, td->td_ucred, td); fdrop(fp, td); return error; } diff --git a/sys/dev/tdfx/tdfx_pci.c b/sys/dev/tdfx/tdfx_pci.c index 5aa0d9785e27..d73ec841f333 100644 --- a/sys/dev/tdfx/tdfx_pci.c +++ b/sys/dev/tdfx/tdfx_pci.c @@ -511,20 +511,16 @@ tdfx_query_fetch(u_int cmd, struct tdfx_pio_data *piod) switch(piod->port) { case PCI_VENDOR_ID_FREEBSD: if(piod->size != 2) return -EINVAL; - copyout(&tdfx_info->vendor, piod->value, piod->size); - return 0; + return -copyout(&tdfx_info->vendor, piod->value, piod->size); case PCI_DEVICE_ID_FREEBSD: if(piod->size != 2) return -EINVAL; - copyout(&tdfx_info->type, piod->value, piod->size); - return 0; + return -copyout(&tdfx_info->type, piod->value, piod->size); case PCI_BASE_ADDRESS_0_FREEBSD: if(piod->size != 4) return -EINVAL; - copyout(&tdfx_info->addr0, piod->value, piod->size); - return 0; + return -copyout(&tdfx_info->addr0, piod->value, piod->size); case PCI_BASE_ADDRESS_1_FREEBSD: if(piod->size != 4) return -EINVAL; - copyout(&tdfx_info->addr1, piod->value, piod->size); - return 0; + return -copyout(&tdfx_info->addr1, piod->value, piod->size); case PCI_PRIBUS_FREEBSD: if(piod->size != 1) return -EINVAL; break; @@ -552,22 +548,18 @@ tdfx_query_fetch(u_int cmd, struct tdfx_pio_data *piod) case 1: ret_byte = pci_read_config(tdfx_info[piod->device].dev, piod->port, 1); - copyout(&ret_byte, piod->value, 1); - break; + return -copyout(&ret_byte, piod->value, 1); case 2: ret_word = pci_read_config(tdfx_info[piod->device].dev, piod->port, 2); - copyout(&ret_word, piod->value, 2); - break; + return -copyout(&ret_word, piod->value, 2); case 4: ret_dword = pci_read_config(tdfx_info[piod->device].dev, piod->port, 4); - copyout(&ret_dword, piod->value, 4); - break; + return -copyout(&ret_dword, piod->value, 4); default: return -EINVAL; } - return 0; } static int @@ -578,6 +570,7 @@ tdfx_query_update(u_int cmd, struct tdfx_pio_data *piod) u_int8_t ret_byte; u_int16_t ret_word; u_int32_t ret_dword; + int error; /* Port vals, mask */ u_int32_t retval, preval, mask; @@ -627,17 +620,23 @@ tdfx_query_update(u_int cmd, struct tdfx_pio_data *piod) * at once to the ports */ switch (piod->size) { case 1: - copyin(piod->value, &ret_byte, 1); + error = copyin(piod->value, &ret_byte, 1); + if (error != 0) + return -error; preval = ret_byte << (8 * (piod->port & 0x3)); mask = 0xff << (8 * (piod->port & 0x3)); break; case 2: - copyin(piod->value, &ret_word, 2); + error = copyin(piod->value, &ret_word, 2); + if (error != 0) + return -error; preval = ret_word << (8 * (piod->port & 0x3)); mask = 0xffff << (8 * (piod->port & 0x3)); break; case 4: - copyin(piod->value, &ret_dword, 4); + error = copyin(piod->value, &ret_dword, 4); + if (error != 0) + return -error; preval = ret_dword; mask = ~0; break; @@ -678,8 +677,7 @@ tdfx_do_pio_rd(struct tdfx_pio_data *piod) /* Write the data to the intended port */ workport = piod->port; ret_byte = inb(workport); - copyout(&ret_byte, piod->value, sizeof(u_int8_t)); - return 0; + return copyout(&ret_byte, piod->value, sizeof(u_int8_t)); } static int @@ -703,10 +701,12 @@ tdfx_do_pio_wt(struct tdfx_pio_data *piod) } /* Write the data to the intended port */ - copyin(piod->value, &ret_byte, sizeof(u_int8_t)); - workport = piod->port; - outb(workport, ret_byte); - return 0; + int error = -copyin(piod->value, &ret_byte, sizeof(u_int8_t)); + if (error == 0) { + workport = piod->port; + outb(workport, ret_byte); + } + return error; } static int