diff options
| author | Olaf Hering <olaf@aepfle.de> | 2017-08-10 18:45:16 -0400 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2017-08-16 12:16:29 -0400 |
| commit | 3f2baa8a7d2efaa836f1dc4b8ee8c3ca4ba9e101 (patch) | |
| tree | 6cd6821ba8f7de289eaea3b5951dbee1fcf57d78 /tools/hv | |
| parent | 3619350cf0d630d83dedd9c0d7d297da211f5ff0 (diff) | |
Tools: hv: update buffer handling in hv_fcopy_daemon
Currently this warning is triggered when compiling hv_fcopy_daemon:
hv_fcopy_daemon.c:216:4: warning: dereferencing type-punned pointer will break
strict-aliasing rules [-Wstrict-aliasing]
kernel_modver = *(__u32 *)buffer;
Convert the send/receive buffer to a union and pass individual members as
needed. This also gives the correct size for the buffer.
Signed-off-by: Olaf Hering <olaf@aepfle.de>
Signed-off-by: K. Y. Srinivasan <kys@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'tools/hv')
| -rw-r--r-- | tools/hv/hv_fcopy_daemon.c | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/tools/hv/hv_fcopy_daemon.c b/tools/hv/hv_fcopy_daemon.c index 26ae609a9448..457a1521f32f 100644 --- a/tools/hv/hv_fcopy_daemon.c +++ b/tools/hv/hv_fcopy_daemon.c | |||
| @@ -138,14 +138,17 @@ void print_usage(char *argv[]) | |||
| 138 | 138 | ||
| 139 | int main(int argc, char *argv[]) | 139 | int main(int argc, char *argv[]) |
| 140 | { | 140 | { |
| 141 | int fcopy_fd, len; | 141 | int fcopy_fd; |
| 142 | int error; | 142 | int error; |
| 143 | int daemonize = 1, long_index = 0, opt; | 143 | int daemonize = 1, long_index = 0, opt; |
| 144 | int version = FCOPY_CURRENT_VERSION; | 144 | int version = FCOPY_CURRENT_VERSION; |
| 145 | char *buffer[4096 * 2]; | 145 | union { |
| 146 | struct hv_fcopy_hdr *in_msg; | 146 | struct hv_fcopy_hdr hdr; |
| 147 | struct hv_start_fcopy start; | ||
| 148 | struct hv_do_fcopy copy; | ||
| 149 | __u32 kernel_modver; | ||
| 150 | } buffer = { }; | ||
| 147 | int in_handshake = 1; | 151 | int in_handshake = 1; |
| 148 | __u32 kernel_modver; | ||
| 149 | 152 | ||
| 150 | static struct option long_options[] = { | 153 | static struct option long_options[] = { |
| 151 | {"help", no_argument, 0, 'h' }, | 154 | {"help", no_argument, 0, 'h' }, |
| @@ -195,32 +198,31 @@ int main(int argc, char *argv[]) | |||
| 195 | * In this loop we process fcopy messages after the | 198 | * In this loop we process fcopy messages after the |
| 196 | * handshake is complete. | 199 | * handshake is complete. |
| 197 | */ | 200 | */ |
| 198 | len = pread(fcopy_fd, buffer, (4096 * 2), 0); | 201 | ssize_t len; |
| 202 | |||
| 203 | len = pread(fcopy_fd, &buffer, sizeof(buffer), 0); | ||
| 199 | if (len < 0) { | 204 | if (len < 0) { |
| 200 | syslog(LOG_ERR, "pread failed: %s", strerror(errno)); | 205 | syslog(LOG_ERR, "pread failed: %s", strerror(errno)); |
| 201 | exit(EXIT_FAILURE); | 206 | exit(EXIT_FAILURE); |
| 202 | } | 207 | } |
| 203 | 208 | ||
| 204 | if (in_handshake) { | 209 | if (in_handshake) { |
| 205 | if (len != sizeof(kernel_modver)) { | 210 | if (len != sizeof(buffer.kernel_modver)) { |
| 206 | syslog(LOG_ERR, "invalid version negotiation"); | 211 | syslog(LOG_ERR, "invalid version negotiation"); |
| 207 | exit(EXIT_FAILURE); | 212 | exit(EXIT_FAILURE); |
| 208 | } | 213 | } |
| 209 | kernel_modver = *(__u32 *)buffer; | ||
| 210 | in_handshake = 0; | 214 | in_handshake = 0; |
| 211 | syslog(LOG_INFO, "kernel module version: %d", | 215 | syslog(LOG_INFO, "kernel module version: %u", |
| 212 | kernel_modver); | 216 | buffer.kernel_modver); |
| 213 | continue; | 217 | continue; |
| 214 | } | 218 | } |
| 215 | 219 | ||
| 216 | in_msg = (struct hv_fcopy_hdr *)buffer; | 220 | switch (buffer.hdr.operation) { |
| 217 | |||
| 218 | switch (in_msg->operation) { | ||
| 219 | case START_FILE_COPY: | 221 | case START_FILE_COPY: |
| 220 | error = hv_start_fcopy((struct hv_start_fcopy *)in_msg); | 222 | error = hv_start_fcopy(&buffer.start); |
| 221 | break; | 223 | break; |
| 222 | case WRITE_TO_FILE: | 224 | case WRITE_TO_FILE: |
| 223 | error = hv_copy_data((struct hv_do_fcopy *)in_msg); | 225 | error = hv_copy_data(&buffer.copy); |
| 224 | break; | 226 | break; |
| 225 | case COMPLETE_FCOPY: | 227 | case COMPLETE_FCOPY: |
| 226 | error = hv_copy_finished(); | 228 | error = hv_copy_finished(); |
| @@ -231,7 +233,7 @@ int main(int argc, char *argv[]) | |||
| 231 | 233 | ||
| 232 | default: | 234 | default: |
| 233 | syslog(LOG_ERR, "Unknown operation: %d", | 235 | syslog(LOG_ERR, "Unknown operation: %d", |
| 234 | in_msg->operation); | 236 | buffer.hdr.operation); |
| 235 | 237 | ||
| 236 | } | 238 | } |
| 237 | 239 | ||
