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
This commit is contained in:
Mark Johnston 2023-12-26 18:59:21 -05:00
parent 916273680b
commit 2873d841f8
2 changed files with 27 additions and 26 deletions

View file

@ -58,8 +58,9 @@ linux_ioctl_tdfx(struct thread *td, struct linux_ioctl_args* args)
if (error != 0) if (error != 0)
return (error); return (error);
/* We simply copy the data and send it right to ioctl */ /* We simply copy the data and send it right to ioctl */
copyin((caddr_t)args->arg, &d_pio, sizeof(d_pio)); error = copyin((caddr_t)args->arg, &d_pio, sizeof(d_pio));
error = fo_ioctl(fp, cmd, (caddr_t)&d_pio, td->td_ucred, td); if (error == 0)
error = fo_ioctl(fp, cmd, (caddr_t)&d_pio, td->td_ucred, td);
fdrop(fp, td); fdrop(fp, td);
return error; return error;
} }

View file

@ -511,20 +511,16 @@ tdfx_query_fetch(u_int cmd, struct tdfx_pio_data *piod)
switch(piod->port) { switch(piod->port) {
case PCI_VENDOR_ID_FREEBSD: case PCI_VENDOR_ID_FREEBSD:
if(piod->size != 2) return -EINVAL; if(piod->size != 2) return -EINVAL;
copyout(&tdfx_info->vendor, piod->value, piod->size); return -copyout(&tdfx_info->vendor, piod->value, piod->size);
return 0;
case PCI_DEVICE_ID_FREEBSD: case PCI_DEVICE_ID_FREEBSD:
if(piod->size != 2) return -EINVAL; if(piod->size != 2) return -EINVAL;
copyout(&tdfx_info->type, piod->value, piod->size); return -copyout(&tdfx_info->type, piod->value, piod->size);
return 0;
case PCI_BASE_ADDRESS_0_FREEBSD: case PCI_BASE_ADDRESS_0_FREEBSD:
if(piod->size != 4) return -EINVAL; if(piod->size != 4) return -EINVAL;
copyout(&tdfx_info->addr0, piod->value, piod->size); return -copyout(&tdfx_info->addr0, piod->value, piod->size);
return 0;
case PCI_BASE_ADDRESS_1_FREEBSD: case PCI_BASE_ADDRESS_1_FREEBSD:
if(piod->size != 4) return -EINVAL; if(piod->size != 4) return -EINVAL;
copyout(&tdfx_info->addr1, piod->value, piod->size); return -copyout(&tdfx_info->addr1, piod->value, piod->size);
return 0;
case PCI_PRIBUS_FREEBSD: case PCI_PRIBUS_FREEBSD:
if(piod->size != 1) return -EINVAL; if(piod->size != 1) return -EINVAL;
break; break;
@ -552,22 +548,18 @@ tdfx_query_fetch(u_int cmd, struct tdfx_pio_data *piod)
case 1: case 1:
ret_byte = pci_read_config(tdfx_info[piod->device].dev, ret_byte = pci_read_config(tdfx_info[piod->device].dev,
piod->port, 1); piod->port, 1);
copyout(&ret_byte, piod->value, 1); return -copyout(&ret_byte, piod->value, 1);
break;
case 2: case 2:
ret_word = pci_read_config(tdfx_info[piod->device].dev, ret_word = pci_read_config(tdfx_info[piod->device].dev,
piod->port, 2); piod->port, 2);
copyout(&ret_word, piod->value, 2); return -copyout(&ret_word, piod->value, 2);
break;
case 4: case 4:
ret_dword = pci_read_config(tdfx_info[piod->device].dev, ret_dword = pci_read_config(tdfx_info[piod->device].dev,
piod->port, 4); piod->port, 4);
copyout(&ret_dword, piod->value, 4); return -copyout(&ret_dword, piod->value, 4);
break;
default: default:
return -EINVAL; return -EINVAL;
} }
return 0;
} }
static int static int
@ -578,6 +570,7 @@ tdfx_query_update(u_int cmd, struct tdfx_pio_data *piod)
u_int8_t ret_byte; u_int8_t ret_byte;
u_int16_t ret_word; u_int16_t ret_word;
u_int32_t ret_dword; u_int32_t ret_dword;
int error;
/* Port vals, mask */ /* Port vals, mask */
u_int32_t retval, preval, 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 */ * at once to the ports */
switch (piod->size) { switch (piod->size) {
case 1: 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)); preval = ret_byte << (8 * (piod->port & 0x3));
mask = 0xff << (8 * (piod->port & 0x3)); mask = 0xff << (8 * (piod->port & 0x3));
break; break;
case 2: 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)); preval = ret_word << (8 * (piod->port & 0x3));
mask = 0xffff << (8 * (piod->port & 0x3)); mask = 0xffff << (8 * (piod->port & 0x3));
break; break;
case 4: case 4:
copyin(piod->value, &ret_dword, 4); error = copyin(piod->value, &ret_dword, 4);
if (error != 0)
return -error;
preval = ret_dword; preval = ret_dword;
mask = ~0; mask = ~0;
break; break;
@ -678,8 +677,7 @@ tdfx_do_pio_rd(struct tdfx_pio_data *piod)
/* Write the data to the intended port */ /* Write the data to the intended port */
workport = piod->port; workport = piod->port;
ret_byte = inb(workport); ret_byte = inb(workport);
copyout(&ret_byte, piod->value, sizeof(u_int8_t)); return copyout(&ret_byte, piod->value, sizeof(u_int8_t));
return 0;
} }
static int static int
@ -703,10 +701,12 @@ tdfx_do_pio_wt(struct tdfx_pio_data *piod)
} }
/* Write the data to the intended port */ /* Write the data to the intended port */
copyin(piod->value, &ret_byte, sizeof(u_int8_t)); int error = -copyin(piod->value, &ret_byte, sizeof(u_int8_t));
workport = piod->port; if (error == 0) {
outb(workport, ret_byte); workport = piod->port;
return 0; outb(workport, ret_byte);
}
return error;
} }
static int static int