From patchwork Fri May 2 19:15:38 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 29574 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f69.google.com (mail-oa0-f69.google.com [209.85.219.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id BDD93203F3 for ; Fri, 2 May 2014 19:16:59 +0000 (UTC) Received: by mail-oa0-f69.google.com with SMTP id i11sf5769701oag.8 for ; Fri, 02 May 2014 12:16:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:in-reply-to:references:cc:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=jmPnENc5+qE0eNEQdy17MszGlDcvw1Wa2TJpL4W5tSA=; b=mrrUCmGtHq5o2Z89O4hcCmOoodo6dh7o19lIEEPfivIxc/TzTtUSXVBcGKdEG4mcSx PmtNIfJ6JeK1+bWalLqK+HsErflXKafgikrrAE0wfT2HlFrWYoJYE8I3/fi2Y4ahvTRV axHNtwPX/URpRnRHKolfefZsZbxinZhdOY1jt4/rtlymuGEVuLjeYERd76zye2/Kiawp SGUeQCH6TmVNN6uFYekNBZE4iOTMrmDST+uHM1ho5ZmUvFHQQZ9XTi5PZIxQp7+yV2Y0 3yRXLguW9QoPY2/WklBfhxkzqRJgdsgq9Rr4pGc33XcAegPE6tprPZYwa7byp8oNeXyO iNgg== X-Gm-Message-State: ALoCoQkL5eQb24PZwz9k3y88foZe/MJZzUXMkm8eR3fO3yajjF6gGcHYuHGiM77eY5bvTQWd3DHY X-Received: by 10.182.60.37 with SMTP id e5mr9853427obr.30.1399058219320; Fri, 02 May 2014 12:16:59 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.32.203 with SMTP id h69ls1654803qgh.56.gmail; Fri, 02 May 2014 12:16:59 -0700 (PDT) X-Received: by 10.52.138.112 with SMTP id qp16mr835040vdb.40.1399058219142; Fri, 02 May 2014 12:16:59 -0700 (PDT) Received: from mail-vc0-f172.google.com (mail-vc0-f172.google.com [209.85.220.172]) by mx.google.com with ESMTPS id fn10si6906987vdc.135.2014.05.02.12.16.59 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 02 May 2014 12:16:59 -0700 (PDT) Received-SPF: none (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) client-ip=209.85.220.172; Received: by mail-vc0-f172.google.com with SMTP id id10so5907933vcb.31 for ; Fri, 02 May 2014 12:16:59 -0700 (PDT) X-Received: by 10.221.26.10 with SMTP id rk10mr14477766vcb.0.1399058219074; Fri, 02 May 2014 12:16:59 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp125797vcb; Fri, 2 May 2014 12:16:58 -0700 (PDT) X-Received: by 10.229.28.2 with SMTP id k2mr25033314qcc.16.1399058218062; Fri, 02 May 2014 12:16:58 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id c8si14489652qab.144.2014.05.02.12.16.57 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 02 May 2014 12:16:58 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:45942 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WgIx7-0000kt-II for patch@linaro.org; Fri, 02 May 2014 15:16:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33466) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WgIwD-000822-8g for qemu-devel@nongnu.org; Fri, 02 May 2014 15:16:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WgIw4-000094-Mf for qemu-devel@nongnu.org; Fri, 02 May 2014 15:16:01 -0400 Received: from afflict.kos.to ([92.243.29.197]:48060) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WgIw4-00005b-CG for qemu-devel@nongnu.org; Fri, 02 May 2014 15:15:52 -0400 Received: from localhost.localdomain (afflict [92.243.29.197]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by afflict.kos.to (Postfix) with ESMTPSA id AD290264C9; Fri, 2 May 2014 21:15:50 +0200 (CEST) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Fri, 2 May 2014 22:15:38 +0300 Message-Id: <52b6549442988e0a0819b6b7fb36ded164952a34.1399057853.git.riku.voipio@linaro.org> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 92.243.29.197 Cc: Huw Davies , peter.maydell@linaro.org Subject: [Qemu-devel] [PULL 03/14] linux-user: Move if-elses to a switch statement. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: riku.voipio@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Huw Davies This makes adding more message types cleaner. Signed-off-by: Huw Davies Signed-off-by: Riku Voipio --- linux-user/syscall.c | 51 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 5203cc4..52bd000 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -1242,25 +1242,40 @@ static inline abi_long host_to_target_cmsg(struct target_msghdr *target_msgh, target_cmsg->cmsg_type = tswap32(cmsg->cmsg_type); target_cmsg->cmsg_len = tswapal(TARGET_CMSG_LEN(len)); - if ((cmsg->cmsg_level == SOL_SOCKET) && - (cmsg->cmsg_type == SCM_RIGHTS)) { - int *fd = (int *)data; - int *target_fd = (int *)target_data; - int i, numfds = len / sizeof(int); + switch (cmsg->cmsg_level) { + case SOL_SOCKET: + switch (cmsg->cmsg_type) { + case SCM_RIGHTS: + { + int *fd = (int *)data; + int *target_fd = (int *)target_data; + int i, numfds = len / sizeof(int); - for (i = 0; i < numfds; i++) - target_fd[i] = tswap32(fd[i]); - } else if ((cmsg->cmsg_level == SOL_SOCKET) && - (cmsg->cmsg_type == SO_TIMESTAMP) && - (len == sizeof(struct timeval))) { - /* copy struct timeval to target */ - struct timeval *tv = (struct timeval *)data; - struct target_timeval *target_tv = - (struct target_timeval *)target_data; - - target_tv->tv_sec = tswapal(tv->tv_sec); - target_tv->tv_usec = tswapal(tv->tv_usec); - } else { + for (i = 0; i < numfds; i++) + target_fd[i] = tswap32(fd[i]); + break; + } + case SO_TIMESTAMP: + { + struct timeval *tv = (struct timeval *)data; + struct target_timeval *target_tv = + (struct target_timeval *)target_data; + + if (len != sizeof(struct timeval)) + goto unimplemented; + + /* copy struct timeval to target */ + target_tv->tv_sec = tswapal(tv->tv_sec); + target_tv->tv_usec = tswapal(tv->tv_usec); + break; + } + default: + goto unimplemented; + } + break; + + default: + unimplemented: gemu_log("Unsupported ancillary data: %d/%d\n", cmsg->cmsg_level, cmsg->cmsg_type); memcpy(target_data, data, len);