From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.5 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B73FC433DB for ; Tue, 5 Jan 2021 18:14:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DC12822D57 for ; Tue, 5 Jan 2021 18:14:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729470AbhAESOF (ORCPT ); Tue, 5 Jan 2021 13:14:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727887AbhAESOE (ORCPT ); Tue, 5 Jan 2021 13:14:04 -0500 Received: from mail-ot1-x330.google.com (mail-ot1-x330.google.com [IPv6:2607:f8b0:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C79F8C061574 for ; Tue, 5 Jan 2021 10:13:23 -0800 (PST) Received: by mail-ot1-x330.google.com with SMTP id q25so527260otn.10 for ; Tue, 05 Jan 2021 10:13:23 -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=GxkJo5g4V4czIVLT4j/kAOkJxRGEcQTcKpmMI8mFQbU=; b=S1KTQA0hFGQnlkBt6vPEdxNuehUu3XeZgcYJmw5IVzuvvVi3rZIayqrqbki6LTknon y7c6NGcqfYuX6D4zzOzO5fyVgqpiG/JgEZyY2p0p2ZaWzwO3aqVH7EJbn1mlVPQkp3Zq Xi5k7qgxSHXAb6K0+Tyb1Vz6tCvCQwW87UCUs= 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=GxkJo5g4V4czIVLT4j/kAOkJxRGEcQTcKpmMI8mFQbU=; b=M2SIXYXMGkPcLWCm2BSDmnWI3lM4QniLu3CGQXfoAFG258iVfIIFyCZqU//zfFfGej 9QR7Q6W47LohKIt+VxERhnAjo7BJ85/j2xj6dWpq7zrz1xSJJeIptLSfr+Ojq81QX0u/ bfRLquMzK0+4tJPi6+y24eoIFF5WEuvOvYa2wyaJTqDiYCgRHAszK4RtoPIOlTky4JX7 YKrlitJkN1IYLJQ4FJXkkLiZD/sxWeicN/Y1nSU+y326k9AwRx0rtM1XOzRU1Sxg8PSh sdNTTQ9en2PIOtm0APFa+pVQOUzceQw1Uv5cGny5K6uZIZwads+MVXlSDFeczPnmq4h8 CwZg== X-Gm-Message-State: AOAM532DAeVRO8G3V4GN3GbUWZpoWw6vlQ0wYbwSJ7kp6S8lsMIReqqJ pwEovH7qLxcm2oufaXSP/oJEqKHHlhKDJw== X-Google-Smtp-Source: ABdhPJyJOPa2iuR/DDqycjJ6gFVcvIOxDc6bpCNHPBbNd35njGXSiYkI1RHMAJWfHibjadg1BAhngw== X-Received: by 2002:a05:6830:403a:: with SMTP id i26mr511468ots.111.1609870403194; Tue, 05 Jan 2021 10:13:23 -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 n16sm20932oop.9.2021.01.05.10.13.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 Jan 2021 10:13:22 -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: Date: Tue, 5 Jan 2021 11:13:21 -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. > Another thing. Please add "cpupower:" to identify what you are changing clearly. thanks, -- Shuah