staging: unisys: visorchannel_read(): Use memcpy_fromio() directly

Note, this changes the behavior of visorchannel_read(). The old code
would return the channel header, if the offset argument was 0, and the
caller tried to read beyond the size of the visorchannel. Note this
only worked for offset == 0, but not for
(offset > 0) && (offset < header_size), which was inconsistent.

The new implementation returns an error if someone tries to read
beyond the visorchannel size.

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Signed-off-by: Benjamin Romer <benjamin.romer@unisys.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Jes Sorensen 2015-05-05 18:36:55 -04:00 committed by Greg Kroah-Hartman
parent ad44088f08
commit 36203e71a0

View File

@ -200,13 +200,12 @@ int
visorchannel_read(struct visorchannel *channel, ulong offset, visorchannel_read(struct visorchannel *channel, ulong offset,
void *local, ulong nbytes) void *local, ulong nbytes)
{ {
int rc; if (offset + nbytes > channel->memregion.nbytes)
size_t size = sizeof(struct channel_header); return -EIO;
rc = visor_memregion_read(&channel->memregion, offset, local, nbytes); memcpy_fromio(local, channel->memregion.mapped + offset, nbytes);
if (rc && !offset && (nbytes >= size))
memcpy(&channel->chan_hdr, local, size); return 0;
return rc;
} }
EXPORT_SYMBOL_GPL(visorchannel_read); EXPORT_SYMBOL_GPL(visorchannel_read);