From mboxrd@z Thu Jan 1 00:00:00 1970 From: Julien Grall Subject: Re: [PATCH v2] tools/libxl: libxl_get_scheduler should return an int Date: Fri, 21 Mar 2014 14:40:05 +0000 Message-ID: <532C4F45.6020101@linaro.org> References: <1395404743-13833-1-git-send-email-julien.grall@linaro.org> <21292.19607.305924.483523@mariner.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WR0cE-0001Ph-Ka for xen-devel@lists.xenproject.org; Fri, 21 Mar 2014 14:40:10 +0000 Received: by mail-we0-f173.google.com with SMTP id w61so1650693wes.18 for ; Fri, 21 Mar 2014 07:40:08 -0700 (PDT) In-Reply-To: <21292.19607.305924.483523@mariner.uk.xensource.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Ian Jackson Cc: xen-devel@lists.xenproject.org, stefano.stabellini@citrix.com, ian.campbell@citrix.com List-Id: xen-devel@lists.xenproject.org On 03/21/2014 02:28 PM, Ian Jackson wrote: > Julien Grall writes ("[PATCH v2] tools/libxl: libxl_get_scheduler should return an int"): >> libxl_get_scheduler returns either a valid value in enum range or ERROR_FAIL. >> >> As function return type is an enum, chekcing if the value is negative will >> be always false. Therefore both GCC and clang will never go to the error >> case. > ... > > Thanks. > > The libxl part is correct, but I > >> diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c >> index 8990020..7c73ee0 100644 >> --- a/tools/libxl/xl_cmdimpl.c >> +++ b/tools/libxl/xl_cmdimpl.c >> @@ -4819,7 +4819,7 @@ int main_vcpuset(int argc, char **argv) >> static void output_xeninfo(void) >> { >> const libxl_version_info *info; >> - libxl_scheduler sched; >> + int sched; > > OK... > >> if (!(info = libxl_get_version_info(ctx))) { >> fprintf(stderr, "libxl_get_version_info failed.\n"); >> @@ -6706,10 +6706,12 @@ int main_cpupoolcreate(int argc, char **argv) >> goto out_cfg; >> } >> } else { >> - if ((sched = libxl_get_scheduler(ctx)) < 0) { >> + >> + if ((ret = libxl_get_scheduler(ctx)) < 0) { >> fprintf(stderr, "get_scheduler sysctl failed.\n"); >> goto out_cfg; >> } >> + sched = ret; > > But then I don't understand why you changed this too. Either of these > changes would suffice by itself, and the former is marginally less > fiddly. The variable sched is a libxl_scheduler in this function. I can't modify the type because it's used with lixbl_scheduler_from_string (see xl_cmdimpl.c:6703). If I let sched as an enum I will get the same error as before, e.g xl_cmdimpl.c:6709:48: error: comparison of unsigned enum expression < 0 is always false [-Werror,-Wtautological-compare] if ((sched = libxl_get_scheduler(ctx)) < 0) { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~ So I need to use ret as a temporary variable. Regards, -- Julien Grall