staging: unisys: visorchannel_write(): Handle partial channel_header writes
authorJes Sorensen <Jes.Sorensen@redhat.com>
Tue, 5 May 2015 22:36:56 +0000 (18:36 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 8 May 2015 13:27:29 +0000 (15:27 +0200)
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>
drivers/staging/unisys/visorbus/visorchannel.c

index cae62fedab791eeb4aa0e572f97168390812398a..da7bd9c362f7965cf806bdfdf842e5df7ae8b420 100644 (file)
@@ -213,13 +213,16 @@ int
 visorchannel_write(struct visorchannel *channel, ulong offset,
                   void *local, ulong nbytes)
 {
-       size_t size = sizeof(struct channel_header);
+       size_t chdr_size = sizeof(struct channel_header);
+       size_t copy_size;
 
        if (offset + nbytes > channel->memregion.nbytes)
                return -EIO;
 
-       if (!offset && nbytes >= size)
-               memcpy(&channel->chan_hdr, local, size);
+       if (offset < chdr_size) {
+               copy_size = min(chdr_size, nbytes) - offset;
+               memcpy(&channel->chan_hdr + offset, local, copy_size);
+       }
 
        memcpy_toio(channel->memregion.mapped + offset, local, nbytes);