[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:
gonzo 2016-12-16 19:09:57 +00:00
parent f570a0d884
commit 26936f9a7c

View File

@ -204,7 +204,7 @@ spigen_transfer(struct cdev *cdev, struct spigen_transfer *st)
int error = 0;
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;
else if (st->st_command.iov_len > sc->sc_command_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);
if (transfer.tx_cmd == NULL)
return (ENOMEM);
transfer.tx_data = transfer.rx_data = malloc(st->st_data.iov_len,
M_DEVBUF, M_WAITOK);
if (transfer.tx_data == NULL) {
free(transfer.tx_cmd, M_DEVBUF);
return (ENOMEM);
if (st->st_data.iov_len > 0) {
transfer.tx_data = transfer.rx_data = malloc(st->st_data.iov_len,
M_DEVBUF, M_WAITOK);
if (transfer.tx_data == NULL) {
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,
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,
transfer.tx_data_sz = transfer.rx_data_sz =
st->st_data.iov_len);
@ -239,7 +243,7 @@ spigen_transfer(struct cdev *cdev, struct spigen_transfer *st)
if (error == 0) {
error = copyout(transfer.rx_cmd, st->st_command.iov_base,
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,
transfer.rx_data_sz);
}