From patchwork Tue Aug 25 15:26:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Holmes X-Patchwork-Id: 52700 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f198.google.com (mail-lb0-f198.google.com [209.85.217.198]) by patches.linaro.org (Postfix) with ESMTPS id EA04722E8F for ; Tue, 25 Aug 2015 15:34:25 +0000 (UTC) Received: by lbcue2 with SMTP id ue2sf52623853lbc.1 for ; Tue, 25 Aug 2015 08:34:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:delivered-to:from:to:date :message-id:in-reply-to:references:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :mime-version:content-type:content-transfer-encoding:errors-to :sender:x-original-sender:x-original-authentication-results :mailing-list; bh=7QYQL9GVVRzbGk7vGdxxYdp61gqyXiLIF9fCKSzxyPA=; b=CuTv1PbGTvEJKkTIha/gigRGajWPiIme5bgNpWGhANrL3YN6+jm8mGd19OuHquQlfj BxarTmLZ7UJ1Jo+UKHxXgM8g8Mp27uehX363zX/c9sPNkNK88sviMsOI189QyFXwAKp4 L8MPFgQ8oOpMxphcpRqbGW1sVjwByF+UgvAPl5/x37+hjyMo3gNrJPdkGWivf3MJSv6a bl9b5ryaZm0YWc1MsVkmqip7SgSSvvAVStta6uvuqARfj7+tCGY7WExri79UBhuPQ6fX b0tNTvaOiZoJWOYYwXghcfrWpBcj2FgiinP2AJB6BXKiGoP1iOd0A36ZZ+1EEnfnpIuS x6+A== X-Gm-Message-State: ALoCoQkJ4WyEzOAvrvUULqp3dO3aYWSTJ029/78RMchOlrxZwWNyrAGh0aIgUDN3KUJ8gXoxhF1N X-Received: by 10.194.115.135 with SMTP id jo7mr8623730wjb.7.1440516864904; Tue, 25 Aug 2015 08:34:24 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.5.1 with SMTP id o1ls733114lao.12.gmail; Tue, 25 Aug 2015 08:34:24 -0700 (PDT) X-Received: by 10.112.156.168 with SMTP id wf8mr26180148lbb.114.1440516864596; Tue, 25 Aug 2015 08:34:24 -0700 (PDT) Received: from mail-la0-f43.google.com (mail-la0-f43.google.com. [209.85.215.43]) by mx.google.com with ESMTPS id kz1si16295404lab.19.2015.08.25.08.34.24 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Aug 2015 08:34:24 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.43 as permitted sender) client-ip=209.85.215.43; Received: by laba3 with SMTP id a3so100951426lab.1 for ; Tue, 25 Aug 2015 08:34:24 -0700 (PDT) X-Received: by 10.112.166.106 with SMTP id zf10mr26237696lbb.36.1440516864485; Tue, 25 Aug 2015 08:34:24 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.162.200 with SMTP id yc8csp3260425lbb; Tue, 25 Aug 2015 08:34:23 -0700 (PDT) X-Received: by 10.140.151.212 with SMTP id 203mr71407910qhx.1.1440516862753; Tue, 25 Aug 2015 08:34:22 -0700 (PDT) Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id p68si938028qkh.42.2015.08.25.08.34.21; Tue, 25 Aug 2015 08:34:22 -0700 (PDT) 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; Received: by lists.linaro.org (Postfix, from userid 109) id D0DD061F17; Tue, 25 Aug 2015 15:34:21 +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_H3, RCVD_IN_MSPIKE_WL, 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 757DC61F33; Tue, 25 Aug 2015 15:27:23 +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 6592861F25; Tue, 25 Aug 2015 15:27:10 +0000 (UTC) Received: from mail-qk0-f179.google.com (mail-qk0-f179.google.com [209.85.220.179]) by lists.linaro.org (Postfix) with ESMTPS id 0747B61F0B for ; Tue, 25 Aug 2015 15:26:54 +0000 (UTC) Received: by qkda128 with SMTP id a128so52570423qkd.3 for ; Tue, 25 Aug 2015 08:26:53 -0700 (PDT) X-Received: by 10.55.52.194 with SMTP id b185mr65322534qka.45.1440516413731; Tue, 25 Aug 2015 08:26:53 -0700 (PDT) Received: from localhost.localdomain (c-98-221-136-245.hsd1.nj.comcast.net. [98.221.136.245]) by smtp.gmail.com with ESMTPSA id z71sm13994853qkz.16.2015.08.25.08.26.52 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 25 Aug 2015 08:26:53 -0700 (PDT) From: Mike Holmes To: lng-odp@lists.linaro.org Date: Tue, 25 Aug 2015 11:26:43 -0400 Message-Id: <1440516404-4177-5-git-send-email-mike.holmes@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1440516404-4177-1-git-send-email-mike.holmes@linaro.org> References: <1440516404-4177-1-git-send-email-mike.holmes@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCH 5/6] linux-generic: check return from sscanf X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: 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" X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: mike.holmes@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.43 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Signed-off-by: Mike Holmes --- platform/linux-generic/odp_system_info.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/platform/linux-generic/odp_system_info.c b/platform/linux-generic/odp_system_info.c index 9e217ff..1919af9 100644 --- a/platform/linux-generic/odp_system_info.c +++ b/platform/linux-generic/odp_system_info.c @@ -95,7 +95,10 @@ static int huge_page_size(void) while ((dirent = readdir(dir)) != NULL) { int temp = 0; - sscanf(dirent->d_name, "hugepages-%i", &temp); + if (sscanf(dirent->d_name, "hugepages-%i", &temp) == EOF) { + ODP_ERR("failed to read hugepages\n"); + return 0; + } if (temp > size) size = temp; @@ -126,7 +129,10 @@ static int cpuinfo_x86(FILE *file, odp_system_info_t *sysinfo) if (!mhz) { pos = strstr(str, "cpu MHz"); if (pos) { - sscanf(pos, "cpu MHz : %lf", &mhz); + if (sscanf(pos, "cpu MHz : %lf", &mhz) == EOF) { + ODP_ERR("failed to read cpu MHz\n"); + return -1; + } count--; } } @@ -169,13 +175,18 @@ static int cpuinfo_octeon(FILE *file, odp_system_info_t *sysinfo) double mhz = 0.0; int model = 0; int count = 2; + int result; while (fgets(str, sizeof(str), file) && count > 0) { if (!mhz) { pos = strstr(str, "BogoMIPS"); if (pos) { - sscanf(pos, "BogoMIPS : %lf", &mhz); + result = sscanf(pos, "BogoMIPS : %lf", &mhz); + if (result == EOF) { + ODP_ERR("failed to read BogoMIPSn"); + return -1; + } count--; } } @@ -216,7 +227,10 @@ static int cpuinfo_powerpc(FILE *file, odp_system_info_t *sysinfo) pos = strstr(str, "clock"); if (pos) { - sscanf(pos, "clock : %lf", &mhz); + if (sscanf(pos, "clock : %lf", &mhz) == EOF) { + ODP_ERR("failed to read clock"); + return -1; + } count--; } }