From patchwork Sun May 19 20:36:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164497 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp4781793ili; Sun, 19 May 2019 13:44:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqyZSPtpxLyIS15fGetUroZg8b1elt8gihjvVpslki24sRK4hxd43AYLbJ8ZlSfXNOf19/2M X-Received: by 2002:a17:906:5e50:: with SMTP id b16mr33333643eju.287.1558298654442; Sun, 19 May 2019 13:44:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558298654; cv=none; d=google.com; s=arc-20160816; b=eaneKyWF2w75BkE3Yyd+mgQTYhspsRe9gFqr4z74sb8IpJWDYk9XuOFUGmGRQOYowQ 8VkJCFBsNaMA2ISkgePeppBDgn+M5sMoeEyj3zr+zGWwpUaVUFvC1ilz1rm9Rrb0mupJ OtrgLtE4HdNkL7YjBysVn4phFcNLeP41N23NL+AWitb7MR+RYPzaLx0L0z5tvMGJMkZ/ /74oC3Hz0H/R4tADRU3B1STEi1qskCXL1t3NlUFoZFHS+du6ZSYlMvL4lyowklevFMy9 Lhaf1rTrtsTkmhfQj0UxgAUkQPtjVxaz7Qj5MgwQhtciy+AALsUauppxSfIaoOVg9AQ2 +xLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=qYhnP8CmUyN8DJK4QlR57fQbe3qhOBTecaegSn//V4c=; b=rHF/hRrsBfBbgftt02RvF7PUZo83Ps1X91qxCGIl3tknLkJJUBXndg8Npb5HVidepz +ZQdL5p38iUlnVEaQ/3EJzPRqEnTOenExyiaDP88TVw41v5nWqgktSNFbaKJHn26wrxJ ruTMTFYsM1EFKisBUkYa4/CHTzFAgkkUdEykpwCiOD9zOLLlP5mKPjlNLzAFoqR8yZY4 +fAQsbau/TeYtvk0htimEbHgYZQJCyVvSL9ImCq3EyjXg8PY6wTPbcMAj+++gBM9ASXO c5TaRSgbJREU7FyGN0GIk/DFgD45b7hdvvE1gGpJ4Win+XvdsmQVqoNUf3EIkpY32PQ5 v8cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Pig4dPrh; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 43si2963729edz.253.2019.05.19.13.44.14 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sun, 19 May 2019 13:44:14 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Pig4dPrh; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:53185 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hSSfF-00089M-CI for patch@linaro.org; Sun, 19 May 2019 16:44:13 -0400 Received: from eggs.gnu.org ([209.51.188.92]:50098) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hSSYq-0002kh-8y for qemu-devel@nongnu.org; Sun, 19 May 2019 16:37:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hSSYp-0003Py-9e for qemu-devel@nongnu.org; Sun, 19 May 2019 16:37:36 -0400 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:38309) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hSSYp-0003P3-3o for qemu-devel@nongnu.org; Sun, 19 May 2019 16:37:35 -0400 Received: by mail-pf1-x442.google.com with SMTP id b76so6171269pfb.5 for ; Sun, 19 May 2019 13:37:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=qYhnP8CmUyN8DJK4QlR57fQbe3qhOBTecaegSn//V4c=; b=Pig4dPrhh0IQm2puL4y7L1z5VCzEWx8rAXfTzOzVG954/QZK7RpTsJZy4z1bW2BNJS 9v3NoT/3b/QSvihL1POvzSZRt4gq2lg2io6GZq/U2AEs8N8kExJuGYMNvsuBHsrfUOD7 3Fzr5mz/qoklKqDJChWhpBRxx8gp0NwT8J7SpMUTo9scUeFs7t7wLf4v5AV1HbvuWGT7 1K+GKhj63Z20E7QZ54UdZp5dalZt3qFXAKCA+G4O5E/7aFeU2UrXngO1pcqH/hbsU1Ik 5GFfjOim4KUAgj14hfzp6dH799w/9EeGfavRjwLKoq+GMOxj+Dg9JdIlmXwon58A3vML e8gQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=qYhnP8CmUyN8DJK4QlR57fQbe3qhOBTecaegSn//V4c=; b=m6M2EXQh0/KffIsSKekup6+dXnG/ftK8S2wS+7t1VmFhV0fFTOvKOJLilpmA8Hb/xZ k7jltatGDXTL28yHap8JE9Rb7nptJ2Ewy0WBgxz6pJblUBcynxhEbgNysoD7nqY4NiF/ xMiHJwnXhi1KRJscI87W1EgWlQo4pExHA6pTbr28GftR5wfX8z7O39uW7pfhWginv7tJ bML9RSf4dYZcQ3o0nkMo+xOq3BDErMWHU+Qbm3rpd3pBlFykHFGNzlbiE/bC9B0f2Der hwhcFFhktcgEaOZIRXf0VwWP6VV8SHZBdegxZk16SN5ry67/Ywh8yLzCRrtgNrwuyoib mKKQ== X-Gm-Message-State: APjAAAUi3OEbEAf+BzUYIZIZov/AdYdnh04IK7rZUYZvjlRCaKKSWdJu A4eQUbdIOGcsKXls48QEN4diPATPamw= X-Received: by 2002:a63:374b:: with SMTP id g11mr15571441pgn.421.1558298253819; Sun, 19 May 2019 13:37:33 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id i7sm11397448pfo.19.2019.05.19.13.37.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 19 May 2019 13:37:32 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sun, 19 May 2019 13:36:16 -0700 Message-Id: <20190519203726.20729-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190519203726.20729-1-richard.henderson@linaro.org> References: <20190519203726.20729-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::442 Subject: [Qemu-devel] [PATCH v7 04/74] linux-user: Tidy do_openat loop over fakes 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: laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Cleaner to use ARRAY_SIZE to loop over elements instead of using a sentinel within the data structure. Signed-off-by: Richard Henderson --- linux-user/syscall-file.inc.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) -- 2.17.1 diff --git a/linux-user/syscall-file.inc.c b/linux-user/syscall-file.inc.c index 961eed13ae..30f8e35cdd 100644 --- a/linux-user/syscall-file.inc.c +++ b/linux-user/syscall-file.inc.c @@ -235,7 +235,6 @@ static abi_long do_openat(void *cpu_env, int dirfd, abi_ulong target_path, int (*fill)(void *cpu_env, int fd); int (*cmp)(const char *s1, const char *s2); }; - const struct fake_open *fake_open; static const struct fake_open fakes[] = { { "maps", open_self_maps, is_proc_myself }, { "stat", open_self_stat, is_proc_myself }, @@ -244,12 +243,12 @@ static abi_long do_openat(void *cpu_env, int dirfd, abi_ulong target_path, #if defined(HOST_WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN) { "/proc/net/route", open_net_route, is_proc }, #endif - { NULL, NULL, NULL } }; char *pathname = lock_user_string(target_path); int flags = target_to_host_bitmask(target_flags, fcntl_flags_tbl); abi_long ret; + size_t i; if (!pathname) { return -TARGET_EFAULT; @@ -263,17 +262,16 @@ static abi_long do_openat(void *cpu_env, int dirfd, abi_ulong target_path, goto done; } - for (fake_open = fakes; fake_open->filename; fake_open++) { - if (fake_open->cmp(pathname, fake_open->filename)) { - break; - } - } - - if (fake_open->filename) { + for (i = 0; i < ARRAY_SIZE(fakes); ++i) { + const struct fake_open *fake_open = &fakes[i]; const char *tmpdir; char filename[PATH_MAX]; int fd; + if (!fake_open->cmp(pathname, fake_open->filename)) { + continue; + } + /* create temporary file to map stat to */ tmpdir = getenv("TMPDIR"); if (!tmpdir) {