From nobody Wed Dec 27 00:06:15 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 4T0Bkb2Syzz54bkJ; Wed, 27 Dec 2023 00:06:15 +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 4T0Bkb1nRsz4K0Z; Wed, 27 Dec 2023 00:06:15 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1703635575; 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=Lu0Yh02Fm+CJpZoPn2iL+2IxVelgCRGQjki1yHtPJ9I=; b=B4io0GJDQ5QcHKAF9hynOhJQS1llxsRHJS2irc2lq/CHMdxyTnkt+ouNNthTAJ/WqUXh7+ 5zc4SttI13ZumM8M8D+CvNBHAOvAA6NQdgB5B6H+LaKPqzK9jO2Cfb63XLu3Q4OOJVmgbg FH7Xcbd36NnRgVHvRcsgI5PxRglQOdin9cyccxLJR4QCHlNgmk/AZjlZERhmzo8unWX8vW 4KGznkFg9N+9j3MhNI6Nrv3j4CZtBeRYMK3RQMyQllsFb4D4hEM+Su34sfOCpezm3JG9J8 DwRbEMqsO90INYP/hT1LiA9p8NsKqCfDdwUTWgI0Pua5Bojxh6Krn4eyK+NPuw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1703635575; a=rsa-sha256; cv=none; b=HKP/lhfHF5LG9LnbeMt9TUD4ZIa4W7yPGEDA46hBd60NUVhz2/h0DLI1PzqYf4z+j5rbTY ynUyGgcqXw7zGm7mg6UCKqwta7bnbCYcKHGtK6ZrTvOoEKguYQ6odRhSuvq/5cXQDTZrz4 39a2NIibP163J+wA9zu0sXAKBS/3A8z0fO+l3xU51kwuRN9xo/xSJCgfsrUt4HqxUVM2eV oZYXbSAHWSpa3AfRIcdwt5UVddY5lkMv30DtWUNXf58m4kMMpB6dYtIIFs/CKwCahjMfLT qbY0QP8sMBD6cFPFB/zJCTObi8Aspnv8kmImRKW0kbcJILisl0yB48jOPZvdaw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1703635575; 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=Lu0Yh02Fm+CJpZoPn2iL+2IxVelgCRGQjki1yHtPJ9I=; b=WovPIjAjIaDSlUGN2HiW1SiRnRjTzHPAT5f5xaVU2YPUhJ+TzepU2pHQGnlMS/n1DQUjyM n+YyH6FT0j/a7KMnMDryhIaovzTD/3jVsmb61JdEVh42uFN+midUvIXsz07SYOWrJTCHzZ CXrN0RChh7n03z6CaHgco4mHyDozqrkhQ04C9CVmiVwj+QKEzhRdaWPBZsNOLUTSETgBZv Hbaj33/OXFwGmixenRq1iD44nJjkdDE4S1mOZx4NY0ErqvioFOm8TKjP95FoN4Fe/jqjKb BzQXhKyWCop740c5bC/IKnq/1Ziw+MsaOCnwe+i/ZB1AUWgFtlj+POXjS39Wkw== 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 4T0Bkb0sg0z1Y6; Wed, 27 Dec 2023 00:06:15 +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 3BR06Fcw018795; Wed, 27 Dec 2023 00:06:15 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3BR06FFp018792; Wed, 27 Dec 2023 00:06:15 GMT (envelope-from git) Date: Wed, 27 Dec 2023 00:06:15 GMT Message-Id: <202312270006.3BR06FFp018792@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 2873d841f81c - main - 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/main X-Git-Reftype: branch X-Git-Commit: 2873d841f81cdc205135370875d3d71a3402e90a Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=2873d841f81cdc205135370875d3d71a3402e90a commit 2873d841f81cdc205135370875d3d71a3402e90a Author: Mark Johnston AuthorDate: 2023-12-26 23:59:21 +0000 Commit: Mark Johnston CommitDate: 2023-12-27 00:00:53 +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 --- 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 3a2b1b3e3922..f3410106bad2 100644 --- a/sys/dev/tdfx/tdfx_linux.c +++ b/sys/dev/tdfx/tdfx_linux.c @@ -58,8 +58,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