From patchwork Thu Feb 25 09:52:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hongbo Zhang X-Patchwork-Id: 62869 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp70218lbc; Thu, 25 Feb 2016 01:55:18 -0800 (PST) X-Received: by 10.50.62.45 with SMTP id v13mr2225159igr.43.1456394118649; Thu, 25 Feb 2016 01:55:18 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id 26si9364157iom.18.2016.02.25.01.55.18; Thu, 25 Feb 2016 01:55:18 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id D2B30650EB; Thu, 25 Feb 2016 09:55:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 5EBF8650F3; Thu, 25 Feb 2016 09:55:13 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 01770650F5; Thu, 25 Feb 2016 09:55:10 +0000 (UTC) Received: from mail-pf0-f175.google.com (mail-pf0-f175.google.com [209.85.192.175]) by lists.linaro.org (Postfix) with ESMTPS id 11784650EB for ; Thu, 25 Feb 2016 09:55:10 +0000 (UTC) Received: by mail-pf0-f175.google.com with SMTP id x65so30264113pfb.1 for ; Thu, 25 Feb 2016 01:55:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=JwpldcnQGHYYK6MaOKtBqWNzApQNs9djMkuYxclCY0c=; b=Uker87a35Itgic7dA/3/mIBOkJdcmtfP5Pgb0tCtB1H1VZB2UcvRhVgvR3/2cmrBpn 1UZkXa2xKXDqX6YV8x3TIwRzGulzPBU0nAhXQ5wdSB4kCth+JWFJKiS3SIx9hxT3TgZZ mWPTCayEQWrgb474cf734ee+Dyx1RiP7uDxtZz9Iq3f54lQu2y8VDOpWEz8kq8SNOcUQ Q6GxYH2ce0Fx233SOT5Q3yAUlhrGf4QLt/3wtghuLKFcCtHgv0Gyh4ZoPYDOv73OvN1f vn4dv3h0jcxbZBCiTxiQYPpLivmhpsynkwtTpndjh9IkfxRKJ/zJAtDG6xpi8QG4XOIt ioeg== X-Gm-Message-State: AG10YOTisrp/3Cdi5Xivn+jam/UenkmclxruExxj1F8+WyAesIcht1CLsQJOTKtdNrne1vxqZHE= X-Received: by 10.98.79.28 with SMTP id d28mr60862463pfb.77.1456394109437; Thu, 25 Feb 2016 01:55:09 -0800 (PST) Received: from ubuntu1504.ap.freescale.net (gate-zmy3.freescale.com. [192.88.167.1]) by smtp.gmail.com with ESMTPSA id 27sm10894943pfh.48.2016.02.25.01.55.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 25 Feb 2016 01:55:08 -0800 (PST) From: hongbo.zhang@linaro.org To: lng-odp@lists.linaro.org Date: Thu, 25 Feb 2016 17:52:30 +0800 Message-Id: <1456393950-4129-1-git-send-email-hongbo.zhang@linaro.org> X-Mailer: git-send-email 2.1.4 X-Topics: patch Subject: [lng-odp] [PATCH] linux-generic: make x86 cpuinfo parser more robust X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Hongbo Zhang This is for https://bugs.linaro.org/show_bug.cgi?id=2033 If the model string doesn't include speed info, segfault should be avoided. Signed-off-by: Hongbo Zhang --- platform/linux-generic/arch/x86/odp_sysinfo_parse.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/platform/linux-generic/arch/x86/odp_sysinfo_parse.c b/platform/linux-generic/arch/x86/odp_sysinfo_parse.c index 2ef49e4..c1e05c0 100644 --- a/platform/linux-generic/arch/x86/odp_sysinfo_parse.c +++ b/platform/linux-generic/arch/x86/odp_sysinfo_parse.c @@ -24,10 +24,12 @@ int odp_cpuinfo_parser(FILE *file, odp_system_info_t *sysinfo) sizeof(sysinfo->model_str[id]) - 1); pos = strchr(sysinfo->model_str[id], '@'); - *(pos - 1) = '\0'; - if (sscanf(pos, "@ %lfGHz", &ghz) == 1) { - hz = (uint64_t)(ghz * 1000000000.0); - sysinfo->cpu_hz_max[id] = hz; + if (pos) { + *(pos - 1) = '\0'; + if (sscanf(pos, "@ %lfGHz", &ghz) == 1) { + hz = (uint64_t)(ghz * 1000000000.0); + sysinfo->cpu_hz_max[id] = hz; + } } id++; }