mirror of
https://github.com/opnsense/src.git
synced 2026-06-07 15:52:40 -04:00
mpi3mr: Check for copyin errors in mpi3mr_map_data_buffer_dma()
A failed copyin will cause the driver to use the contents of uninitialized buffers instead, which is unlikely to be the behaviour that we want. Check for errors. This is in preparation for annotating copyin() and related functions with __result_use_check. Reviewed by: imp MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D43098
This commit is contained in:
parent
b2caed2f8d
commit
6bfb7306ef
1 changed files with 10 additions and 1 deletions
|
|
@ -543,6 +543,7 @@ static int mpi3mr_map_data_buffer_dma(struct mpi3mr_softc *sc,
|
|||
{
|
||||
U16 i, needed_desc = (dma_buffers->kern_buf_len / MPI3MR_IOCTL_SGE_SIZE);
|
||||
U32 buf_len = dma_buffers->kern_buf_len, copied_len = 0;
|
||||
int error;
|
||||
|
||||
if (dma_buffers->kern_buf_len % MPI3MR_IOCTL_SGE_SIZE)
|
||||
needed_desc++;
|
||||
|
|
@ -558,6 +559,7 @@ static int mpi3mr_map_data_buffer_dma(struct mpi3mr_softc *sc,
|
|||
if (!dma_buffers->dma_desc)
|
||||
return -1;
|
||||
|
||||
error = 0;
|
||||
for (i = 0; i < needed_desc; i++, desc_count++) {
|
||||
|
||||
dma_buffers->dma_desc[i].addr = sc->ioctl_sge[desc_count].addr;
|
||||
|
|
@ -572,12 +574,19 @@ static int mpi3mr_map_data_buffer_dma(struct mpi3mr_softc *sc,
|
|||
memset(dma_buffers->dma_desc[i].addr, 0, sc->ioctl_sge[desc_count].size);
|
||||
|
||||
if (dma_buffers->data_dir == MPI3MR_APP_DDO) {
|
||||
copyin(((U8 *)dma_buffers->user_buf + copied_len),
|
||||
error = copyin(((U8 *)dma_buffers->user_buf + copied_len),
|
||||
dma_buffers->dma_desc[i].addr,
|
||||
dma_buffers->dma_desc[i].size);
|
||||
if (error != 0)
|
||||
break;
|
||||
copied_len += dma_buffers->dma_desc[i].size;
|
||||
}
|
||||
}
|
||||
if (error != 0) {
|
||||
printf("%s: DMA copyin error %d\n", __func__, error);
|
||||
free(dma_buffers->dma_desc, M_MPI3MR);
|
||||
return -1;
|
||||
}
|
||||
|
||||
dma_buffers->num_dma_desc = needed_desc;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue