From patchwork Tue Mar 27 14:28:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 10310287 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 9074C60212 for ; Tue, 27 Mar 2018 14:28:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 82619297A8 for ; Tue, 27 Mar 2018 14:28:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 76D3229B1F; Tue, 27 Mar 2018 14:28:19 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D7F2A29B51 for ; Tue, 27 Mar 2018 14:28:18 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2FB906E63D; Tue, 27 Mar 2018 14:28:18 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from fireflyinternet.com (mail.fireflyinternet.com [109.228.58.192]) by gabe.freedesktop.org (Postfix) with ESMTPS id 245DF6E63D; Tue, 27 Mar 2018 14:28:16 +0000 (UTC) X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=78.156.65.138; Received: from haswell.alporthouse.com (unverified [78.156.65.138]) by fireflyinternet.com (Firefly Internet (M1)) with ESMTP id 11175260-1500050 for multiple; Tue, 27 Mar 2018 15:28:06 +0100 Received: by haswell.alporthouse.com (sSMTP sendmail emulation); Tue, 27 Mar 2018 15:28:06 +0100 From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Tue, 27 Mar 2018 15:28:05 +0100 Message-Id: <20180327142805.18259-1-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.16.3 X-Originating-IP: 78.156.65.138 X-Country: code=GB country="United Kingdom" ip=78.156.65.138 Subject: [Intel-gfx] [PATCH igt] overlay: Call setlocale around strtod X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: igt-dev@lists.freedesktop.org MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP strtod() is locale-dependent. The decimal conversion depends on the radix character ('.' for some of us like myself) varies by locale. As the kernel reports its values using the "C" locale, we need to switch to that when parsing; and switch back before reporting to the user. Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=105712 Signed-off-by: Chris Wilson Cc: Tvrtko Ursulin Reviewed-by: Tvrtko Ursulin --- overlay/power.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/overlay/power.c b/overlay/power.c index 9ac90fde..0f99e2a4 100644 --- a/overlay/power.c +++ b/overlay/power.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include "igt_perf.h" @@ -97,12 +98,18 @@ static uint64_t rapl_gpu_power(void) static double filename_to_double(const char *filename) { - char buf[64]; + char *oldlocale; + char buf[80]; + double v; if (filename_to_buf(filename, buf, sizeof(buf))) return 0; - return strtod(buf, NULL); + oldlocale = setlocale(LC_ALL, "C"); + v = strtod(buf, NULL); + setlocale(LC_ALL, oldlocale); + + return v; } static double rapl_gpu_power_scale(void)