All of lore.kernel.org
 help / color / mirror / Atom feed
From: Saravana Kannan <skannan@codeaurora.org>
To: Pavan Kondeti <pkondeti@codeaurora.org>
Cc: Santosh Mardi <gsantosh@codeaurora.org>,
	myungjoo.ham@samsung.com, kyungmin.park@samsung.com,
	rafael.j.wysocki@intel.com, cw00.choi@samsung.com,
	linux-pm@vger.kernel.org, LKML <linux-kernel@vger.kernel.org>,
	gsantosh@qti.qualcomm.com, skannan@quicinc.com,
	rgottimu@qti.qualcomm.com
Subject: Re: [PATCH] devfreq: add error check for sscanf in userspace governor
Date: Tue, 08 Aug 2017 12:26:03 -0700	[thread overview]
Message-ID: <598A104B.4020101@codeaurora.org> (raw)
In-Reply-To: <CAEU1=PmSq+UXO_zwrMSTbsejUi5G8BCKaqYA_cxmo4pcFO1z_Q@mail.gmail.com>

On 08/07/2017 11:56 PM, Pavan Kondeti wrote:
> Hi Santosh,
>
> On Mon, Aug 7, 2017 at 6:36 PM, Santosh Mardi <gsantosh@codeaurora.org> wrote:
>> store_freq function of devfreq userspace governor
>> executes further, even if error is returned from sscanf,
>> this will result in setting up wrong frequency value.
>>
>> Add proper error check to bail out if any error is returned.
>>
>> Signed-off-by: Santosh Mardi <gsantosh@codeaurora.org>
>> ---
>>   drivers/devfreq/governor_userspace.c | 5 ++++-
>>   1 file changed, 4 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/devfreq/governor_userspace.c b/drivers/devfreq/governor_userspace.c
>> index 77028c2..1d0c9cc 100644
>> --- a/drivers/devfreq/governor_userspace.c
>> +++ b/drivers/devfreq/governor_userspace.c
>> @@ -53,12 +53,15 @@ static ssize_t store_freq(struct device *dev, struct device_attribute *attr,
>>          mutex_lock(&devfreq->lock);
>>          data = devfreq->data;
>>
>> -       sscanf(buf, "%lu", &wanted);
>> +       err = sscanf(buf, "%lu", &wanted);

Also, we could just use kstroul().

>> +       if (err != 1)
>> +               goto out;
>
> You can save this goto statement by moving this sscanf checking to
> before taking the mutex.
>
>>          data->user_frequency = wanted;
>>          data->valid = true;
>>          err = update_devfreq(devfreq);
>>          if (err == 0)
>>                  err = count;
>> +out:
>>          mutex_unlock(&devfreq->lock);
>>          return err;
>>   }
>> --
>> 1.9.1
>>

-Saravana


-- 
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

      reply	other threads:[~2017-08-08 19:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-07 13:06 [PATCH] devfreq: add error check for sscanf in userspace governor Santosh Mardi
2017-08-07 13:06 ` Santosh Mardi
2017-08-08  0:14   ` MyungJoo Ham
2017-08-08  0:51   ` Chanwoo Choi
2017-08-08  6:56   ` Pavan Kondeti
2017-08-08 19:26     ` Saravana Kannan [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=598A104B.4020101@codeaurora.org \
    --to=skannan@codeaurora.org \
    --cc=cw00.choi@samsung.com \
    --cc=gsantosh@codeaurora.org \
    --cc=gsantosh@qti.qualcomm.com \
    --cc=kyungmin.park@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=myungjoo.ham@samsung.com \
    --cc=pkondeti@codeaurora.org \
    --cc=rafael.j.wysocki@intel.com \
    --cc=rgottimu@qti.qualcomm.com \
    --cc=skannan@quicinc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.