From patchwork Thu Jun 16 20:29:37 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 1993 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id A3A5323E54 for ; Thu, 16 Jun 2011 20:31:47 +0000 (UTC) Received: from mail-vw0-f50.google.com (mail-vw0-f50.google.com [209.85.212.50]) by fiordland.canonical.com (Postfix) with ESMTP id 73C55A18585 for ; Thu, 16 Jun 2011 20:31:47 +0000 (UTC) Received: by mail-vw0-f50.google.com with SMTP id 14so1756035vws.37 for ; Thu, 16 Jun 2011 13:31:47 -0700 (PDT) Received: by 10.52.175.197 with SMTP id cc5mr1863227vdc.287.1308256307258; Thu, 16 Jun 2011 13:31:47 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.52.183.130 with SMTP id em2cs211206vdc; Thu, 16 Jun 2011 13:31:46 -0700 (PDT) Received: by 10.227.205.12 with SMTP id fo12mr1331915wbb.70.1308256303433; Thu, 16 Jun 2011 13:31:43 -0700 (PDT) Received: from smtp.smtpout.orange.fr (smtp08.smtpout.orange.fr [80.12.242.130]) by mx.google.com with ESMTP id fs8si1324954wbb.140.2011.06.16.13.31.42; Thu, 16 Jun 2011 13:31:43 -0700 (PDT) Received-SPF: neutral (google.com: 80.12.242.130 is neither permitted nor denied by best guess record for domain of daniel.lezcano@linaro.org) client-ip=80.12.242.130; Authentication-Results: mx.google.com; spf=neutral (google.com: 80.12.242.130 is neither permitted nor denied by best guess record for domain of daniel.lezcano@linaro.org) smtp.mail=daniel.lezcano@linaro.org Received: from monster.dhcp.lxc ([92.134.76.78]) by mwinf5d16 with ME id wkXf1g0031hMfSL03kXiJX; Thu, 16 Jun 2011 22:31:42 +0200 From: Daniel Lezcano To: patches@linaro.org Subject: [PATCH 08/28] provide a clock allocator Date: Thu, 16 Jun 2011 22:29:37 +0200 Message-Id: <1308256197-29155-8-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1308256197-29155-1-git-send-email-daniel.lezcano@linaro.org> References: <1308256197-29155-1-git-send-email-daniel.lezcano@linaro.org> Signed-off-by: Daniel Lezcano --- clocks.c | 43 ++++++++++++++++++++++++++++++++----------- powerdebug.h | 2 +- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/clocks.c b/clocks.c index 677db01..d08c926 100644 --- a/clocks.c +++ b/clocks.c @@ -451,33 +451,48 @@ static struct clock_info *read_clock_info_recur(char *clkpath, int level, return cur; } -void read_clock_info(char *clkpath) +static struct clock_info *clock_alloc(const char *name) +{ + struct clock_info *ci; + + ci = malloc(sizeof(*ci)); + if (ci) { + memset(ci, 0, sizeof(*ci)); + strcpy(ci->name, name); + } + + return ci; +} + +int read_clock_info(char *clkpath) { DIR *dir; struct dirent *item; - char filename[NAME_MAX], clockname[NAME_MAX]; + char filename[NAME_MAX]; struct clock_info *child; struct clock_info *cur; + int ret = -1; dir = opendir(clkpath); if (!dir) - return; + return -1; - clocks_info = (struct clock_info *)malloc(sizeof(struct clock_info)); - memset(clocks_info, 0, sizeof(clocks_info)); - strcpy(clocks_info->name, "/"); - clocks_info->level = 0; + clocks_info = clock_alloc("/"); + if (!clocks_info) + return -1; while ((item = readdir(dir))) { + /* skip hidden dirs except ".." */ if (item->d_name[0] == '.') continue; - strcpy(clockname, item->d_name); sprintf(filename, "%s/%s", clkpath, item->d_name); - cur = (struct clock_info *)malloc(sizeof(struct clock_info)); - memset(cur, 0, sizeof(struct clock_info)); - strcpy(cur->name, clockname); + + cur = clock_alloc(item->d_name); + if (!cur) + goto out; + cur->parent = clocks_info; cur->num_children = 0; cur->expanded = 0; @@ -485,7 +500,13 @@ void read_clock_info(char *clkpath) insert_children(&clocks_info, cur); child = read_clock_info_recur(filename, 2, cur); } + + ret = 0; + +out: closedir(dir); + + return ret; } void read_and_dump_clock_info_one(char *clk, bool dump) diff --git a/powerdebug.h b/powerdebug.h index 1018998..0d8e8d1 100644 --- a/powerdebug.h +++ b/powerdebug.h @@ -30,7 +30,7 @@ enum {CLOCK_SELECTED = 1, REFRESH_WINDOW}; extern void read_and_dump_clock_info(int verbose); extern void read_and_dump_clock_info_one(char *clk, bool dump); -extern void read_clock_info(char *clkpath); +extern int read_clock_info(char *clkpath); extern void find_parents_for_clock(char *clkname, int complete); extern int read_and_print_clock_info(int verbose, int hrow, int selected); extern void print_clock_info(int verbose, int hrow, int selected);