Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753497AbdHJWq1 (ORCPT ); Thu, 10 Aug 2017 18:46:27 -0400 Received: from a2nlsmtp01-02.prod.iad2.secureserver.net ([198.71.225.36]:49916 "EHLO a2nlsmtp01-02.prod.iad2.secureserver.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753455AbdHJWqT (ORCPT ); Thu, 10 Aug 2017 18:46:19 -0400 x-originating-ip: 107.180.71.197 From: kys@exchange.microsoft.com To: gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, devel@linuxdriverproject.org, olaf@aepfle.de, apw@canonical.com, vkuznets@redhat.com, jasowang@redhat.com, leann.ogasawara@canonical.com, marcelo.cerri@canonical.com, sthemmin@microsoft.com Cc: "K. Y. Srinivasan" Subject: [PATCH 2/2] Tools: hv: update buffer handling in hv_fcopy_daemon Date: Thu, 10 Aug 2017 15:45:16 -0700 Message-Id: <1502405116-18599-2-git-send-email-kys@exchange.microsoft.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1502405089-18551-1-git-send-email-kys@exchange.microsoft.com> References: <1502405089-18551-1-git-send-email-kys@exchange.microsoft.com> Reply-To: kys@microsoft.com X-CMAE-Envelope: MS4wfFWJFiIMEPj1A/fXm/03BpzRK/FwLs/v5X9ILIuCnBmHcDOt4AG5vXxhdfFql7XzcqU5OQk53D5Fjbcd1MOkhg1KGJrxc1g2lO45vpcN6fRweNDHaVf5 TpqxHKx7YRcIrvsSmSMk/yPIqmWe5dWhCpXPfO6qT78yc68RQbEfr6pl/I0fDOflrUAaITgLbhoj7WkjEn0HdeHxorJ7pwiUxnRNtuQiSLZnaxZLfcuFWXTQ 6gwR60ChFX0Y9Cp3OUmf25LzknMKHvPwicdV+VbtL/cMoXttdSl8WRl40pw5ohtMkEdtd8YTO/KMwXcR/hIhQ6cXa2779XFL/nffA+2IOm30lUbPAmYCdm71 uVtSU7aOCkLfuBjsneq/FXiaKK7B30R4KGcYGZNDi+j9wnQmGgAgBXDPeU6fhEqazXwMsg8gd+Cfr9W/Zx4ufKxGOy4zEDAdBRawxZASFa98C2cBgx915DV+ db60KbHG6ytjRyElrMDgCKqKoKKb7TSFsgS2iGUVUMtmFqFChv+pmE/9oq56Wsn7X/KT/KFuDBBX9fPk Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2765 Lines: 96 From: Olaf Hering 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 Signed-off-by: K. Y. Srinivasan --- 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 26ae609..457a152 100644 --- a/tools/hv/hv_fcopy_daemon.c +++ b/tools/hv/hv_fcopy_daemon.c @@ -138,14 +138,17 @@ void print_usage(char *argv[]) int main(int argc, char *argv[]) { - int fcopy_fd, len; + int fcopy_fd; int error; int daemonize = 1, long_index = 0, opt; int version = FCOPY_CURRENT_VERSION; - char *buffer[4096 * 2]; - struct hv_fcopy_hdr *in_msg; + union { + struct hv_fcopy_hdr hdr; + struct hv_start_fcopy start; + struct hv_do_fcopy copy; + __u32 kernel_modver; + } buffer = { }; int in_handshake = 1; - __u32 kernel_modver; static struct option long_options[] = { {"help", no_argument, 0, 'h' }, @@ -195,32 +198,31 @@ int main(int argc, char *argv[]) * In this loop we process fcopy messages after the * handshake is complete. */ - len = pread(fcopy_fd, buffer, (4096 * 2), 0); + ssize_t len; + + len = pread(fcopy_fd, &buffer, sizeof(buffer), 0); if (len < 0) { syslog(LOG_ERR, "pread failed: %s", strerror(errno)); exit(EXIT_FAILURE); } if (in_handshake) { - if (len != sizeof(kernel_modver)) { + if (len != sizeof(buffer.kernel_modver)) { syslog(LOG_ERR, "invalid version negotiation"); exit(EXIT_FAILURE); } - kernel_modver = *(__u32 *)buffer; in_handshake = 0; - syslog(LOG_INFO, "kernel module version: %d", - kernel_modver); + syslog(LOG_INFO, "kernel module version: %u", + buffer.kernel_modver); continue; } - in_msg = (struct hv_fcopy_hdr *)buffer; - - switch (in_msg->operation) { + switch (buffer.hdr.operation) { case START_FILE_COPY: - error = hv_start_fcopy((struct hv_start_fcopy *)in_msg); + error = hv_start_fcopy(&buffer.start); break; case WRITE_TO_FILE: - error = hv_copy_data((struct hv_do_fcopy *)in_msg); + error = hv_copy_data(&buffer.copy); break; case COMPLETE_FCOPY: error = hv_copy_finished(); @@ -231,7 +233,7 @@ int main(int argc, char *argv[]) default: syslog(LOG_ERR, "Unknown operation: %d", - in_msg->operation); + buffer.hdr.operation); } -- 1.7.1