From patchwork Fri Jan 18 21:30:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 156048 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3727474jaa; Fri, 18 Jan 2019 13:32:15 -0800 (PST) X-Google-Smtp-Source: ALg8bN6z/oATPCEkJkb9BGFQM/ebl/Z8h60OBIx+JXw3imn+cy01dM3fMkrdIF78tbdYB67a1/DR X-Received: by 2002:a1c:760c:: with SMTP id r12mr16008238wmc.127.1547847135064; Fri, 18 Jan 2019 13:32:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547847135; cv=none; d=google.com; s=arc-20160816; b=OXRBX2az1mP6IcSqnX0KokMAaWeTsRf3elRor1ZB14cM1lb/K/XRZZEMrLdsJzhIjF lgwsdAVh8bXo818BTE7sSdumfCq6vC7oaEWnrLcWsPZetdw8NEkRVGwRw3sZItr2lWIg 7ov4kZwOzvsyl1uRd/s9oXeMorGEgxesggb2BoiwWdFHo3oV+m8CkhflHHSP7hvG8wPp GgzW/lUkbZvzzRX/WYHIGMTwlfxbcIgGtFq99opSlCWCNnmtN7mnw464Jc95JKxyZZFF 6zxiFh2lVoVytGgfgGAdRSHPSv7F9tdF/oXlgfzyk53Y9MI54wg/OdMgxq1EWTy5BJkN 0t1A== 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=uYCCSjdXn0Q17nLwgrskP9sJiH9L/F6XImgNprliAmk=; b=xy/rgZBwT3iJWK2SZQMpdW21PiBA8NzG8yu405Y7kzHh+8RPdq3ka8aKFg6BhTK1LD /aQDGf2D9tbjAsvC1iqMj1OqZ3chqCWpqUYQlYCgbPIfK9ifNYzI39Q9Js3RzeimNdHf BiDg8fNfXho9AY4RiCgoxo8hQVVPNF3tmogUeIEApkODSQXBDhBLDCNZuQ++LJ8mXJPX 9IuP+cmfgFI3hHrNHYra2byi6QFOF4csHHnQ3LcjObiSmTYs/jTGNUkUbkW+Aps/pegw dyl5GBZOHubRaKYELRNAjYD4yFWB1X57sl6wLriv1bznJjHMFvOpXtosrjtZfdOhSYrF +ZbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=dtesyX1v; 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 j6si40085405wrr.94.2019.01.18.13.32.14 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 18 Jan 2019 13:32:15 -0800 (PST) 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=dtesyX1v; 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]:47389 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkbkL-0004im-9g for patch@linaro.org; Fri, 18 Jan 2019 16:32:13 -0500 Received: from eggs.gnu.org ([209.51.188.92]:55701) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkbju-0004hX-Bo for qemu-devel@nongnu.org; Fri, 18 Jan 2019 16:31:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gkbjt-0003xB-ET for qemu-devel@nongnu.org; Fri, 18 Jan 2019 16:31:46 -0500 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:39395) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gkbjt-0003ow-5t for qemu-devel@nongnu.org; Fri, 18 Jan 2019 16:31:45 -0500 Received: by mail-pf1-x442.google.com with SMTP id r136so7200758pfc.6 for ; Fri, 18 Jan 2019 13:31:40 -0800 (PST) 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=uYCCSjdXn0Q17nLwgrskP9sJiH9L/F6XImgNprliAmk=; b=dtesyX1vmoJi+pbJBljf39RXZ+3CqrqCR3ti2Q9jWYTKSjNmkCe03koIIyUd5iPvtd TAmiAwW5rMoXTffPMkUih2mBmcqKqK45CHV3x+NgJe1umyoetzvhaT5XeUgjpDiNnmxU fv4N/lgRKe6dW2xyKkk68EHIGS+gdMo4hdP2w= 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=uYCCSjdXn0Q17nLwgrskP9sJiH9L/F6XImgNprliAmk=; b=BYk6+QKpfmovysETUWWYnJNA+quIUsoFSy4xOcvUU3emcOV8TaQwD+e+hAKYFC0TwG SX7F3Prt+Y3Q/Z4ZJRVk7+b9f7W3hyrD604s4Xuhn2LJT++nIFW/Vm3y4qyrPh1chtcX +M9rn62hP4kuHSQjaXpEG/Bsf4iclNrxRlKJfONqzRyMO5rqAO3b/KTc15D1YWWKfYoy Ry615m78TmMhpZylA7iuYAvcnE5XSHEdXpv5TQQoPuj05MGqJ1SQr2D4v4lBepl4+5z4 g1WVv/owrNtDYjQoO5V01icFYAcy4QI93/VggfcMD5bx1rOJowifCCAOHnps00mjPNNG qqTw== X-Gm-Message-State: AJcUukcMfHsvnRTCdX+U2P2GZTtuhziLudTmlEC7vmFfIOW0kzILYCCZ OQS+fadYowCfIep046djxL4Wu1Z75Tw= X-Received: by 2002:a62:2044:: with SMTP id g65mr20839729pfg.127.1547847099238; Fri, 18 Jan 2019 13:31:39 -0800 (PST) Received: from cloudburst.twiddle.net ([2001:8000:10e0:a000:c673:a6b6:fdef:1933]) by smtp.gmail.com with ESMTPSA id v12sm5833667pgg.41.2019.01.18.13.31.37 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 18 Jan 2019 13:31:38 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sat, 19 Jan 2019 08:30:38 +1100 Message-Id: <20190118213122.22865-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190118213122.22865-1-richard.henderson@linaro.org> References: <20190118213122.22865-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 v6 05/49] 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.2 diff --git a/linux-user/syscall-file.inc.c b/linux-user/syscall-file.inc.c index ffa70bbea8..f202a4c8f4 100644 --- a/linux-user/syscall-file.inc.c +++ b/linux-user/syscall-file.inc.c @@ -229,7 +229,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 }, @@ -238,12 +237,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; @@ -257,17 +256,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) {