mirror of
https://github.com/freebsd/freebsd-src
synced 2024-07-22 10:48:02 +00:00
ti: 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:
parent
10b84b88f0
commit
916273680b
|
@ -502,11 +502,13 @@ ti_copy_mem(struct ti_softc *sc, uint32_t tigon_addr, uint32_t len,
|
||||||
int segptr, segsize, cnt;
|
int segptr, segsize, cnt;
|
||||||
caddr_t ptr;
|
caddr_t ptr;
|
||||||
uint32_t origwin;
|
uint32_t origwin;
|
||||||
int resid, segresid;
|
int error, resid, segresid;
|
||||||
int first_pass;
|
int first_pass;
|
||||||
|
|
||||||
TI_LOCK_ASSERT(sc);
|
TI_LOCK_ASSERT(sc);
|
||||||
|
|
||||||
|
error = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* At the moment, we don't handle non-aligned cases, we just bail.
|
* At the moment, we don't handle non-aligned cases, we just bail.
|
||||||
* If this proves to be a problem, it will be fixed.
|
* If this proves to be a problem, it will be fixed.
|
||||||
|
@ -548,7 +550,7 @@ ti_copy_mem(struct ti_softc *sc, uint32_t tigon_addr, uint32_t len,
|
||||||
*/
|
*/
|
||||||
origwin = CSR_READ_4(sc, TI_WINBASE);
|
origwin = CSR_READ_4(sc, TI_WINBASE);
|
||||||
|
|
||||||
while (cnt) {
|
while (cnt != 0 && error == 0) {
|
||||||
bus_size_t ti_offset;
|
bus_size_t ti_offset;
|
||||||
|
|
||||||
if (cnt < TI_WINLEN)
|
if (cnt < TI_WINLEN)
|
||||||
|
@ -573,11 +575,13 @@ ti_copy_mem(struct ti_softc *sc, uint32_t tigon_addr, uint32_t len,
|
||||||
|
|
||||||
TI_UNLOCK(sc);
|
TI_UNLOCK(sc);
|
||||||
if (first_pass) {
|
if (first_pass) {
|
||||||
copyout(&sc->ti_membuf2[segresid], ptr,
|
error = copyout(
|
||||||
|
&sc->ti_membuf2[segresid], ptr,
|
||||||
segsize - segresid);
|
segsize - segresid);
|
||||||
first_pass = 0;
|
first_pass = 0;
|
||||||
} else
|
} else
|
||||||
copyout(sc->ti_membuf2, ptr, segsize);
|
error = copyout(sc->ti_membuf2, ptr,
|
||||||
|
segsize);
|
||||||
TI_LOCK(sc);
|
TI_LOCK(sc);
|
||||||
} else {
|
} else {
|
||||||
if (first_pass) {
|
if (first_pass) {
|
||||||
|
@ -597,7 +601,7 @@ ti_copy_mem(struct ti_softc *sc, uint32_t tigon_addr, uint32_t len,
|
||||||
} else {
|
} else {
|
||||||
if (useraddr) {
|
if (useraddr) {
|
||||||
TI_UNLOCK(sc);
|
TI_UNLOCK(sc);
|
||||||
copyin(ptr, sc->ti_membuf2, segsize);
|
error = copyin(ptr, sc->ti_membuf2, segsize);
|
||||||
TI_LOCK(sc);
|
TI_LOCK(sc);
|
||||||
ti_bcopy_swap(sc->ti_membuf2, sc->ti_membuf,
|
ti_bcopy_swap(sc->ti_membuf2, sc->ti_membuf,
|
||||||
segsize, TI_SWAP_HTON);
|
segsize, TI_SWAP_HTON);
|
||||||
|
@ -605,8 +609,11 @@ ti_copy_mem(struct ti_softc *sc, uint32_t tigon_addr, uint32_t len,
|
||||||
ti_bcopy_swap(ptr, sc->ti_membuf, segsize,
|
ti_bcopy_swap(ptr, sc->ti_membuf, segsize,
|
||||||
TI_SWAP_HTON);
|
TI_SWAP_HTON);
|
||||||
|
|
||||||
bus_space_write_region_4(sc->ti_btag, sc->ti_bhandle,
|
if (error == 0) {
|
||||||
ti_offset, (uint32_t *)sc->ti_membuf, segsize >> 2);
|
bus_space_write_region_4(sc->ti_btag,
|
||||||
|
sc->ti_bhandle, ti_offset,
|
||||||
|
(uint32_t *)sc->ti_membuf, segsize >> 2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
segptr += segsize;
|
segptr += segsize;
|
||||||
ptr += segsize;
|
ptr += segsize;
|
||||||
|
@ -616,7 +623,7 @@ ti_copy_mem(struct ti_softc *sc, uint32_t tigon_addr, uint32_t len,
|
||||||
/*
|
/*
|
||||||
* Handle leftover, non-word-aligned bytes.
|
* Handle leftover, non-word-aligned bytes.
|
||||||
*/
|
*/
|
||||||
if (resid != 0) {
|
if (resid != 0 && error == 0) {
|
||||||
uint32_t tmpval, tmpval2;
|
uint32_t tmpval, tmpval2;
|
||||||
bus_size_t ti_offset;
|
bus_size_t ti_offset;
|
||||||
|
|
||||||
|
@ -649,7 +656,7 @@ ti_copy_mem(struct ti_softc *sc, uint32_t tigon_addr, uint32_t len,
|
||||||
*/
|
*/
|
||||||
if (useraddr) {
|
if (useraddr) {
|
||||||
TI_UNLOCK(sc);
|
TI_UNLOCK(sc);
|
||||||
copyout(&tmpval2, ptr, resid);
|
error = copyout(&tmpval2, ptr, resid);
|
||||||
TI_LOCK(sc);
|
TI_LOCK(sc);
|
||||||
} else
|
} else
|
||||||
bcopy(&tmpval2, ptr, resid);
|
bcopy(&tmpval2, ptr, resid);
|
||||||
|
@ -667,21 +674,22 @@ ti_copy_mem(struct ti_softc *sc, uint32_t tigon_addr, uint32_t len,
|
||||||
*/
|
*/
|
||||||
if (useraddr) {
|
if (useraddr) {
|
||||||
TI_UNLOCK(sc);
|
TI_UNLOCK(sc);
|
||||||
copyin(ptr, &tmpval2, resid);
|
error = copyin(ptr, &tmpval2, resid);
|
||||||
TI_LOCK(sc);
|
TI_LOCK(sc);
|
||||||
} else
|
} else
|
||||||
bcopy(ptr, &tmpval2, resid);
|
bcopy(ptr, &tmpval2, resid);
|
||||||
|
|
||||||
tmpval = htonl(tmpval2);
|
if (error == 0) {
|
||||||
|
tmpval = htonl(tmpval2);
|
||||||
bus_space_write_region_4(sc->ti_btag, sc->ti_bhandle,
|
bus_space_write_region_4(sc->ti_btag,
|
||||||
ti_offset, &tmpval, 1);
|
sc->ti_bhandle, ti_offset, &tmpval, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CSR_WRITE_4(sc, TI_WINBASE, origwin);
|
CSR_WRITE_4(sc, TI_WINBASE, origwin);
|
||||||
|
|
||||||
return (0);
|
return (error);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -689,7 +697,7 @@ ti_copy_scratch(struct ti_softc *sc, uint32_t tigon_addr, uint32_t len,
|
||||||
caddr_t buf, int useraddr, int readdata, int cpu)
|
caddr_t buf, int useraddr, int readdata, int cpu)
|
||||||
{
|
{
|
||||||
uint32_t segptr;
|
uint32_t segptr;
|
||||||
int cnt;
|
int cnt, error;
|
||||||
uint32_t tmpval, tmpval2;
|
uint32_t tmpval, tmpval2;
|
||||||
caddr_t ptr;
|
caddr_t ptr;
|
||||||
|
|
||||||
|
@ -715,7 +723,7 @@ ti_copy_scratch(struct ti_softc *sc, uint32_t tigon_addr, uint32_t len,
|
||||||
cnt = len;
|
cnt = len;
|
||||||
ptr = buf;
|
ptr = buf;
|
||||||
|
|
||||||
while (cnt) {
|
while (cnt && error == 0) {
|
||||||
CSR_WRITE_4(sc, CPU_REG(TI_SRAM_ADDR, cpu), segptr);
|
CSR_WRITE_4(sc, CPU_REG(TI_SRAM_ADDR, cpu), segptr);
|
||||||
|
|
||||||
if (readdata) {
|
if (readdata) {
|
||||||
|
@ -756,18 +764,20 @@ ti_copy_scratch(struct ti_softc *sc, uint32_t tigon_addr, uint32_t len,
|
||||||
"%#x (tmpval)\n", segptr);
|
"%#x (tmpval)\n", segptr);
|
||||||
|
|
||||||
if (useraddr)
|
if (useraddr)
|
||||||
copyout(&tmpval, ptr, 4);
|
error = copyout(&tmpval, ptr, 4);
|
||||||
else
|
else
|
||||||
bcopy(&tmpval, ptr, 4);
|
bcopy(&tmpval, ptr, 4);
|
||||||
} else {
|
} else {
|
||||||
if (useraddr)
|
if (useraddr)
|
||||||
copyin(ptr, &tmpval2, 4);
|
error = copyin(ptr, &tmpval2, 4);
|
||||||
else
|
else
|
||||||
bcopy(ptr, &tmpval2, 4);
|
bcopy(ptr, &tmpval2, 4);
|
||||||
|
|
||||||
tmpval = htonl(tmpval2);
|
if (error == 0) {
|
||||||
|
tmpval = htonl(tmpval2);
|
||||||
CSR_WRITE_4(sc, CPU_REG(TI_SRAM_DATA, cpu), tmpval);
|
CSR_WRITE_4(sc, CPU_REG(TI_SRAM_DATA, cpu),
|
||||||
|
tmpval);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cnt -= 4;
|
cnt -= 4;
|
||||||
|
@ -775,7 +785,7 @@ ti_copy_scratch(struct ti_softc *sc, uint32_t tigon_addr, uint32_t len,
|
||||||
ptr += 4;
|
ptr += 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (0);
|
return (error);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
Loading…
Reference in a new issue