From patchwork Tue Sep 27 16:49:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Felipe Franciosi X-Patchwork-Id: 9352345 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8318960757 for ; Tue, 27 Sep 2016 16:50:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 73D0F29282 for ; Tue, 27 Sep 2016 16:50:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 671712929C; Tue, 27 Sep 2016 16:50:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 70E3129282 for ; Tue, 27 Sep 2016 16:50:10 +0000 (UTC) Received: from localhost ([::1]:52377 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bova5-0007ox-8c for patchwork-qemu-devel@patchwork.kernel.org; Tue, 27 Sep 2016 12:50:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60256) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bovZj-0007oL-1l for qemu-devel@nongnu.org; Tue, 27 Sep 2016 12:49:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bovZf-0004Ae-SK for qemu-devel@nongnu.org; Tue, 27 Sep 2016 12:49:46 -0400 Received: from 206-15-90-246.static.twtelecom.net ([206.15.90.246]:31375 helo=felipe-franciosi.localdomain) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bovZf-0004A2-Js for qemu-devel@nongnu.org; Tue, 27 Sep 2016 12:49:43 -0400 Received: by felipe-franciosi.localdomain (Postfix, from userid 500) id 689D0103FA3; Tue, 27 Sep 2016 09:49:42 -0700 (PDT) From: Felipe Franciosi To: "Daniel P. Berrange" , Marc-Andre Lureau , Paolo Bonzini Date: Tue, 27 Sep 2016 09:49:18 -0700 Message-Id: <1474994958-6007-1-git-send-email-felipe@nutanix.com> X-Mailer: git-send-email 1.7.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 206.15.90.246 Subject: [Qemu-devel] [PATCH] io: Fix double shift usages on QIOChannel features X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org, Felipe Franciosi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP When QIOChannels were introduced in 666a3af9, the feature bits were defined shifted. However, when using them, the code was shifting them again. The incorrect use was consistent until 74b6ce43, where QIO_CHANNEL_FEATURE_LISTEN was defined shifted but tested unshifted. This patch fixes all uses of QIOChannel features. They are defined shifted and therefore set unshifted. It also makes all feature tests to use the qio_channel_has_feature() function. Signed-off-by: Felipe Franciosi Reviewed-by: Marc-André Lureau --- io/channel-socket.c | 11 ++++++----- io/channel-tls.c | 4 ++-- io/channel-websock.c | 4 ++-- io/channel.c | 10 ++++------ migration/qemu-file-channel.c | 3 +-- qemu-char.c | 3 +-- 6 files changed, 16 insertions(+), 19 deletions(-) diff --git a/io/channel-socket.c b/io/channel-socket.c index 196a4f1..bb0a0a7 100644 --- a/io/channel-socket.c +++ b/io/channel-socket.c @@ -55,7 +55,7 @@ qio_channel_socket_new(void) sioc->fd = -1; ioc = QIO_CHANNEL(sioc); - ioc->features |= (1 << QIO_CHANNEL_FEATURE_SHUTDOWN); + ioc->features |= QIO_CHANNEL_FEATURE_SHUTDOWN; #ifdef WIN32 ioc->event = CreateEvent(NULL, FALSE, FALSE, NULL); @@ -107,12 +107,12 @@ qio_channel_socket_set_fd(QIOChannelSocket *sioc, #ifndef WIN32 if (sioc->localAddr.ss_family == AF_UNIX) { QIOChannel *ioc = QIO_CHANNEL(sioc); - ioc->features |= (1 << QIO_CHANNEL_FEATURE_FD_PASS); + ioc->features |= QIO_CHANNEL_FEATURE_FD_PASS; } #endif /* WIN32 */ if (getsockopt(fd, SOL_SOCKET, SO_ACCEPTCONN, &val, &len) == 0 && val) { QIOChannel *ioc = QIO_CHANNEL(sioc); - ioc->features |= (1 << QIO_CHANNEL_FEATURE_LISTEN); + ioc->features |= QIO_CHANNEL_FEATURE_LISTEN; } return 0; @@ -380,7 +380,7 @@ qio_channel_socket_accept(QIOChannelSocket *ioc, #ifndef WIN32 if (cioc->localAddr.ss_family == AF_UNIX) { - QIO_CHANNEL(cioc)->features |= (1 << QIO_CHANNEL_FEATURE_FD_PASS); + QIO_CHANNEL(cioc)->features |= QIO_CHANNEL_FEATURE_FD_PASS; } #endif /* WIN32 */ @@ -403,7 +403,8 @@ static void qio_channel_socket_finalize(Object *obj) QIOChannelSocket *ioc = QIO_CHANNEL_SOCKET(obj); if (ioc->fd != -1) { - if (QIO_CHANNEL(ioc)->features & QIO_CHANNEL_FEATURE_LISTEN) { + if (qio_channel_has_feature(QIO_CHANNEL(ioc), + QIO_CHANNEL_FEATURE_LISTEN)) { Error *err = NULL; socket_listen_cleanup(ioc->fd, &err); diff --git a/io/channel-tls.c b/io/channel-tls.c index 9a8525c..d22996b 100644 --- a/io/channel-tls.c +++ b/io/channel-tls.c @@ -111,8 +111,8 @@ qio_channel_tls_new_client(QIOChannel *master, ioc = QIO_CHANNEL(tioc); tioc->master = master; - if (master->features & (1 << QIO_CHANNEL_FEATURE_SHUTDOWN)) { - ioc->features |= (1 << QIO_CHANNEL_FEATURE_SHUTDOWN); + if (qio_channel_has_feature(master, QIO_CHANNEL_FEATURE_SHUTDOWN)) { + ioc->features |= QIO_CHANNEL_FEATURE_SHUTDOWN; } object_ref(OBJECT(master)); diff --git a/io/channel-websock.c b/io/channel-websock.c index 533bd4b..9accd16 100644 --- a/io/channel-websock.c +++ b/io/channel-websock.c @@ -497,8 +497,8 @@ qio_channel_websock_new_server(QIOChannel *master) ioc = QIO_CHANNEL(wioc); wioc->master = master; - if (master->features & (1 << QIO_CHANNEL_FEATURE_SHUTDOWN)) { - ioc->features |= (1 << QIO_CHANNEL_FEATURE_SHUTDOWN); + if (qio_channel_has_feature(master, QIO_CHANNEL_FEATURE_SHUTDOWN)) { + ioc->features |= QIO_CHANNEL_FEATURE_SHUTDOWN; } object_ref(OBJECT(master)); diff --git a/io/channel.c b/io/channel.c index 923c465..ebe9f86 100644 --- a/io/channel.c +++ b/io/channel.c @@ -23,13 +23,11 @@ #include "qapi/error.h" #include "qemu/coroutine.h" -bool qio_channel_has_feature(QIOChannel *ioc, - QIOChannelFeature feature) +bool qio_channel_has_feature(QIOChannel *ioc, QIOChannelFeature feature) { - return ioc->features & (1 << feature); + return ioc->features & feature; } - ssize_t qio_channel_readv_full(QIOChannel *ioc, const struct iovec *iov, size_t niov, @@ -40,7 +38,7 @@ ssize_t qio_channel_readv_full(QIOChannel *ioc, QIOChannelClass *klass = QIO_CHANNEL_GET_CLASS(ioc); if ((fds || nfds) && - !(ioc->features & (1 << QIO_CHANNEL_FEATURE_FD_PASS))) { + !qio_channel_has_feature(ioc, QIO_CHANNEL_FEATURE_FD_PASS)) { error_setg_errno(errp, EINVAL, "Channel does not support file descriptor passing"); return -1; @@ -60,7 +58,7 @@ ssize_t qio_channel_writev_full(QIOChannel *ioc, QIOChannelClass *klass = QIO_CHANNEL_GET_CLASS(ioc); if ((fds || nfds) && - !(ioc->features & (1 << QIO_CHANNEL_FEATURE_FD_PASS))) { + !qio_channel_has_feature(ioc, QIO_CHANNEL_FEATURE_FD_PASS)) { error_setg_errno(errp, EINVAL, "Channel does not support file descriptor passing"); return -1; diff --git a/migration/qemu-file-channel.c b/migration/qemu-file-channel.c index 45c13f1..a39abd5 100644 --- a/migration/qemu-file-channel.c +++ b/migration/qemu-file-channel.c @@ -105,8 +105,7 @@ static int channel_shutdown(void *opaque, { QIOChannel *ioc = QIO_CHANNEL(opaque); - if (qio_channel_has_feature(ioc, - QIO_CHANNEL_FEATURE_SHUTDOWN)) { + if (qio_channel_has_feature(ioc, QIO_CHANNEL_FEATURE_SHUTDOWN)) { QIOChannelShutdown mode; if (rd && wr) { mode = QIO_CHANNEL_SHUTDOWN_BOTH; diff --git a/qemu-char.c b/qemu-char.c index 8826419..b825331 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -2787,8 +2787,7 @@ static int tcp_set_msgfds(CharDriverState *chr, int *fds, int num) s->write_msgfds_num = 0; if (!s->connected || - !qio_channel_has_feature(s->ioc, - QIO_CHANNEL_FEATURE_FD_PASS)) { + !qio_channel_has_feature(s->ioc, QIO_CHANNEL_FEATURE_FD_PASS)) { return -1; }