Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp406551pxu; Tue, 5 Jan 2021 14:41:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJzKqcnTFh3I6G5hRh2Wa6mRGZJyIi+TvXF7l6Ne4hbS1zWyOm3sK7dji8oyuxF61GOhYrp6 X-Received: by 2002:a17:906:85cf:: with SMTP id i15mr1085409ejy.373.1609886496919; Tue, 05 Jan 2021 14:41:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609886496; cv=none; d=google.com; s=arc-20160816; b=z3L9ny+0yLjA7Z6pbtB63AjwyCKXWb+h4zG1H+05lvAXlc65JrQ0muYfpH1iEhyhcf GwfoJv53yeBgu2ShOmVNpbpigcu6TB0XO3UXCtLLpbXS0z94cb39glGYF7UrcGSJTgyS Jy79Jh/kKeek1En29nYSvHCYtIMPnA57H6Cxtqqxelj/63gndFYkwMs8pS/K4NbQv79p 5+OwZ2oyllxtkuDjllLpme5cyLbI0Lz75m6AP1tzDroAEbvk39FvFghbKkg5LkIz5/SE +Jk4G/2iV0qbmeY9jYvoVHFVKkzZ1zN7c2U3+KA+u+EruV3K1TVW0NPITJwogAjsEzMn hvKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=yuUp96Dy9EvE7pFdc2UT55pn6ORXJwMoBW6BB0BgLiY=; b=VyWQKAd1FgkCFVO2pjkWUJqkJPQiUyHxOVssbHCCi1z52bdo7L46fo5Q7oztVbGwUL KbU0RXRWHx0ZDm1vglAaBFtd093nI+p2cvA0tCTF5pM5n4PGeVZcXSZASMWnktzu3EbO aqdiGDbRN8RESmKgJaOocGryoiiTncODRWTfevErDtwShcQCzqUgvBmc7f6Xny+LMwMe 8E1+RmnDp9IBHYm+NI0hMSOQlYLtq+gfO6yL7kO4/0BCvblkNyGa6UotDWWJGjYbbBuU DdBAgYtU8H7BZXoj+cjH3envl59vtKijblTGXmBjBXRu22qRMd5GhcwWL1u7Vlue0ed6 J9oQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=google header.b=bQP7qIex; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y13si211473ejw.564.2021.01.05.14.41.13; Tue, 05 Jan 2021 14:41:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=google header.b=bQP7qIex; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728152AbhAETv6 (ORCPT + 99 others); Tue, 5 Jan 2021 14:51:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726171AbhAETv6 (ORCPT ); Tue, 5 Jan 2021 14:51:58 -0500 Received: from mail-il1-x132.google.com (mail-il1-x132.google.com [IPv6:2607:f8b0:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08D07C061574 for ; Tue, 5 Jan 2021 11:51:18 -0800 (PST) Received: by mail-il1-x132.google.com with SMTP id u12so852500ilv.3 for ; Tue, 05 Jan 2021 11:51:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=yuUp96Dy9EvE7pFdc2UT55pn6ORXJwMoBW6BB0BgLiY=; b=bQP7qIexcx4SZMa8hnp7djt8zuWQK49oCKLFrDYhJE0sDnGAMowJQ9lmYtVomf/p2K hU/kE2ebouwRhxiIrgclabCBKCYE/E5D14nO/8AQRbT4y7CYwvSxfvB2VcHpTEen0nnF E4A24VFEkT6v1gL7dWvqKLKd1qjJoKAcu+i9g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=yuUp96Dy9EvE7pFdc2UT55pn6ORXJwMoBW6BB0BgLiY=; b=E1Gg3aUMCKOq5lacjP0OvsfZx4zWWXejSSHqnruMxHjlT0JpCzitbmIqwfNZyUYe6S h4OvV9wtLAqd7hVN6pot0nyX1bYdZLqFxmTycA59jI8sosr2P39oBCixV9twDrd7KXDN s0DVK98RISwqmEMeMTDHpruTUFEVsl8OzafxHCwUHNGJTPRS3nd3+dNAUHYqH2dIpOGP racNK/JSHN53J+UfcNyDLb2aNxmwmKTSPO6upjPXVG0AsizRd7OOU4r6GV3rHoReLDO1 imcDbDYc9eoP0qF+Ktr6498ZfL+jRxx33528x+W7Os54ZnRf1MSGn8NVSn0L9hOn0YmZ wWOg== X-Gm-Message-State: AOAM5305S5rr8NWPzVp55BuNnJZgYkPBMFKFGsRYkarYzvf0xX56AddF u+L5phhPk+EIjyFBheUb4EQ0yA== X-Received: by 2002:a92:8495:: with SMTP id y21mr1131074ilk.55.1609876277463; Tue, 05 Jan 2021 11:51:17 -0800 (PST) Received: from [192.168.1.112] (c-24-9-64-241.hsd1.co.comcast.net. [24.9.64.241]) by smtp.gmail.com with ESMTPSA id i6sm139679ilm.70.2021.01.05.11.51.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 Jan 2021 11:51:16 -0800 (PST) Subject: Re: [PATCH] cpuidle_set accepts alpha numeric values for idle-set operation To: Brahadambal Srinivasan , shuah@kernel.org, trenn@suse.com Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Shuah Khan References: <20210105122452.8687-1-latha@linux.vnet.ibm.com> From: Shuah Khan Message-ID: <5bf14c30-0c47-a93c-fd31-8b5d4caf1616@linuxfoundation.org> Date: Tue, 5 Jan 2021 12:51:16 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 1/5/21 11:03 AM, Shuah Khan wrote: > On 1/5/21 5:24 AM, Brahadambal Srinivasan wrote: >> For both the d and e options in cpuidle_set, an atoi() conversion is >> done without checking if the input argument is all numeric. So, an >> atoi conversion is done on any character provided as input and the >> CPU idle_set operation continues with that integer value, which may >> not be what is intended or entirely correct. >> >> A similar check is present for cpufreq-set already. >> >> This patch adds a check to see that the idle_set value is all numeric >> before doing a string-to-int conversion. >> >> Signed-off-by: Brahadambal Srinivasan >> --- >>   tools/power/cpupower/utils/cpuidle-set.c | 39 +++++++++++++++++++++--- >>   1 file changed, 34 insertions(+), 5 deletions(-) >> >> diff --git a/tools/power/cpupower/utils/cpuidle-set.c >> b/tools/power/cpupower/utils/cpuidle-set.c >> index 46158928f9ad..b3dec48e7141 100644 >> --- a/tools/power/cpupower/utils/cpuidle-set.c >> +++ b/tools/power/cpupower/utils/cpuidle-set.c >> @@ -21,6 +21,19 @@ static struct option info_opts[] = { >>        { }, >>   }; >> +int is_number(char *arg) >> +{ >> +    size_t len, i = 0; >> + >> +    len = strlen(arg); >> + >> +    for (i = 0; i < len; i++) { >> +        if (!isdigit(arg[i])) >> +            return 0; >> +    } >> + >> +    return 1; >> +} > > Any reason why you can't use isdigit()? Please see isdigit() > usages examples in other tools and cpupower itself. > Okay - Let me clarify my question a bit. What I am looking for is if there is an existing function that can do what you are doing here. It appears there is one: Please take a look at the exiting is_number() in tools/perf/tests/pmu-events.c It uses strtod() to do what you are doing with strlen() and loop over it with isdigit(). It is static and you can't use it as is. Unfortunately you will have to duplicate this routine to keep cpupower not dependent on tools/lib. Please add it to cpupower lib instead. thanks, -- Shuah