[spigen] Make "data" part of spigen_transfer optional
Make st_data part of spigen_transfer optional by letting pass zero length and NULL pointer. SPI controller drivers handle this case fine. MFC after: 1 week
This commit is contained in:
parent
f570a0d884
commit
26936f9a7c
@ -204,7 +204,7 @@ spigen_transfer(struct cdev *cdev, struct spigen_transfer *st)
|
|||||||
int error = 0;
|
int error = 0;
|
||||||
|
|
||||||
mtx_lock(&sc->sc_mtx);
|
mtx_lock(&sc->sc_mtx);
|
||||||
if (st->st_command.iov_len == 0 || st->st_data.iov_len == 0)
|
if (st->st_command.iov_len == 0)
|
||||||
error = EINVAL;
|
error = EINVAL;
|
||||||
else if (st->st_command.iov_len > sc->sc_command_length_max ||
|
else if (st->st_command.iov_len > sc->sc_command_length_max ||
|
||||||
st->st_data.iov_len > sc->sc_data_length_max)
|
st->st_data.iov_len > sc->sc_data_length_max)
|
||||||
@ -221,16 +221,20 @@ spigen_transfer(struct cdev *cdev, struct spigen_transfer *st)
|
|||||||
M_DEVBUF, M_WAITOK);
|
M_DEVBUF, M_WAITOK);
|
||||||
if (transfer.tx_cmd == NULL)
|
if (transfer.tx_cmd == NULL)
|
||||||
return (ENOMEM);
|
return (ENOMEM);
|
||||||
transfer.tx_data = transfer.rx_data = malloc(st->st_data.iov_len,
|
if (st->st_data.iov_len > 0) {
|
||||||
M_DEVBUF, M_WAITOK);
|
transfer.tx_data = transfer.rx_data = malloc(st->st_data.iov_len,
|
||||||
if (transfer.tx_data == NULL) {
|
M_DEVBUF, M_WAITOK);
|
||||||
free(transfer.tx_cmd, M_DEVBUF);
|
if (transfer.tx_data == NULL) {
|
||||||
return (ENOMEM);
|
free(transfer.tx_cmd, M_DEVBUF);
|
||||||
|
return (ENOMEM);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
transfer.tx_data = transfer.rx_data = NULL;
|
||||||
|
|
||||||
error = copyin(st->st_command.iov_base, transfer.tx_cmd,
|
error = copyin(st->st_command.iov_base, transfer.tx_cmd,
|
||||||
transfer.tx_cmd_sz = transfer.rx_cmd_sz = st->st_command.iov_len);
|
transfer.tx_cmd_sz = transfer.rx_cmd_sz = st->st_command.iov_len);
|
||||||
if (error == 0)
|
if ((error == 0) && (st->st_data.iov_len > 0))
|
||||||
error = copyin(st->st_data.iov_base, transfer.tx_data,
|
error = copyin(st->st_data.iov_base, transfer.tx_data,
|
||||||
transfer.tx_data_sz = transfer.rx_data_sz =
|
transfer.tx_data_sz = transfer.rx_data_sz =
|
||||||
st->st_data.iov_len);
|
st->st_data.iov_len);
|
||||||
@ -239,7 +243,7 @@ spigen_transfer(struct cdev *cdev, struct spigen_transfer *st)
|
|||||||
if (error == 0) {
|
if (error == 0) {
|
||||||
error = copyout(transfer.rx_cmd, st->st_command.iov_base,
|
error = copyout(transfer.rx_cmd, st->st_command.iov_base,
|
||||||
transfer.rx_cmd_sz);
|
transfer.rx_cmd_sz);
|
||||||
if (error == 0)
|
if ((error == 0) && (st->st_data.iov_len > 0))
|
||||||
error = copyout(transfer.rx_data, st->st_data.iov_base,
|
error = copyout(transfer.rx_data, st->st_data.iov_base,
|
||||||
transfer.rx_data_sz);
|
transfer.rx_data_sz);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user