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

(cherry picked from commit 6bfb7306ef)
This commit is contained in:
Mark Johnston 2023-12-25 20:38:12 -05:00
parent f9946e9ae7
commit 8adca661c2

View file

@ -544,6 +544,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++;
@ -559,6 +560,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;
@ -573,12 +575,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;