From patchwork Wed May 24 21:31:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: David Matlack X-Patchwork-Id: 9746973 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 4626060246 for ; Wed, 24 May 2017 21:31:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 38CF826E3A for ; Wed, 24 May 2017 21:31:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2ABF526E4D; Wed, 24 May 2017 21:31:54 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 92D0126E3A for ; Wed, 24 May 2017 21:31:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S941092AbdEXVbv (ORCPT ); Wed, 24 May 2017 17:31:51 -0400 Received: from mail-pf0-f170.google.com ([209.85.192.170]:35112 "EHLO mail-pf0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S941088AbdEXVbt (ORCPT ); Wed, 24 May 2017 17:31:49 -0400 Received: by mail-pf0-f170.google.com with SMTP id n23so147239573pfb.2 for ; Wed, 24 May 2017 14:31:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sKuqvlHu3I9tBLVPIzyb5FyGPMl3L23IMo+dIis0FiI=; b=ll/liyoJRHfEAzImJWy/2Tnr1WNz0fmlBeX3R0Y4ty9GbhVHFLyoXfLAWHczIaGl0H GWni+igk7bGmO7+DBu2nuZTBEOQBTJ2cVczYwj2VUuAzVlBkfatfdwCtg53pYgclfuz2 OrOXAuVrPALSIld03EmuLjx3fcMvhgbHRej08muHhdKTOPmWkMpV4zNBNWg7iDFdNHGD AtTq504zIe4sOtw7Y9Cuzdn6AstKDqDtGopm0qitJnWmkynVcf18MOB5AgtfgnHianhq UR05m5DtzC8Q9ZXhXM/5quGQjDTxXqxrdXpY0kGQuS3IgigwNazwrE0Wm+4FzqPpYAE+ arOQ== 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:mime-version:content-transfer-encoding; bh=sKuqvlHu3I9tBLVPIzyb5FyGPMl3L23IMo+dIis0FiI=; b=BP0kdv2UxI10XhbMkjBqo0G7Q6ZAE8w53bLB5lMLHww3rIeNqaHe+BPa4zXoJQ1IXc fRTUutcMQ+xwxy0XdaTxOwAj5SIfsGIDnFjBzPRkAfOF75IsfzQl82AR7fLZO5xPEEtr Dcnhap+M8QqnA2xuJCyGV9tFoozioWnVcltdgiXKOVnooIpo6aoJNn6AhH2odVYn6zhY gj5NDEWqALiulu8hdhZ9Mgf6LH0srIB1VF+DCxQ/2jxP2vE2d58S9YpEjMY/lTp2syIw dhAN/mflZB9YDCOm4U6NAlKa3fHG/7uk1VG1QgQFbAeIrcFgk9h3+o/jzgIQZ0J0Hkqj 48og== X-Gm-Message-State: AODbwcBBOKjYZQEoqzjFNyb6ZOoVWDSRgEEFpyY86anJEyeOfDnHwE6M Fv2vC5ztf5gH4rOb X-Received: by 10.84.132.2 with SMTP id 2mr46866146ple.46.1495661508287; Wed, 24 May 2017 14:31:48 -0700 (PDT) Received: from dmatlack.sea.corp.google.com ([100.100.206.82]) by smtp.gmail.com with ESMTPSA id u9sm8580429pgn.55.2017.05.24.14.31.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 24 May 2017 14:31:47 -0700 (PDT) From: David Matlack To: kvm@vger.kernel.org Cc: jmattson@google.com, David Matlack Subject: [kvm-unit-tests PATCH 2/3] api: fix "ignoring return value" of posix_memalign errors Date: Wed, 24 May 2017 14:31:22 -0700 Message-Id: <20170524213123.71538-2-dmatlack@google.com> X-Mailer: git-send-email 2.13.0.219.gdb65acc882-goog In-Reply-To: <20170524213123.71538-1-dmatlack@google.com> References: <20170524213123.71538-1-dmatlack@google.com> MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP posix_memalign returns zero on success and an errno value otherwise. The value of the global variable "errno" is actually indeterminiate after a call to posix_memalign(), according to the man page. This patch also fixes the compilation errors: api/dirty-log.cc:55:50: error: ignoring return value of ‘int posix_memalign(void**, size_t, size_t)’, declared with attribute warn_unused_result [-Werror=unused-result] posix_memalign(&logged_slot_virt, 4096, 4096); api/identity.cc:23:41: error: ignoring return value of ‘int posix_memalign(void**, size_t, size_t)’, declared with attribute warn_unused_result [-Werror=unused-result] posix_memalign(&tss, 4096, 4 * 4096); Signed-off-by: David Matlack --- api/dirty-log.cc | 5 ++++- api/identity.cc | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/api/dirty-log.cc b/api/dirty-log.cc index 47fbac2b1cc6..9891e98fde9e 100644 --- a/api/dirty-log.cc +++ b/api/dirty-log.cc @@ -52,7 +52,10 @@ int test_main(int ac, char **av) kvm::vm vm(sys); mem_map memmap(vm); void* logged_slot_virt; - posix_memalign(&logged_slot_virt, 4096, 4096); + int ret = posix_memalign(&logged_slot_virt, 4096, 4096); + if (ret) { + throw errno_exception(ret); + } volatile int* shared_var = static_cast(logged_slot_virt); identity::hole hole(logged_slot_virt, 4096); identity::vm ident_vm(vm, memmap, hole); diff --git a/api/identity.cc b/api/identity.cc index 6dd42315a0af..24609ef9d6d0 100644 --- a/api/identity.cc +++ b/api/identity.cc @@ -20,9 +20,9 @@ hole::hole(void* address, size_t size) vm::vm(kvm::vm& vm, mem_map& mmap, hole h) { - posix_memalign(&tss, 4096, 4 * 4096); - if (!tss) { - throw errno_exception(errno); + int ret = posix_memalign(&tss, 4096, 4 * 4096); + if (ret) { + throw errno_exception(ret); } uint64_t hole_gpa = reinterpret_cast(h.address);