All of lore.kernel.org
 help / color / mirror / Atom feed
From: gsantosh@codeaurora.org
To: MyungJoo Ham <myungjoo.ham@samsung.com>,
	Kyungmin Park <kyungmin.park@samsung.com>,
	linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
	gsantosh@qtil.qualcomm.com
Subject: [PATCH] devfreq: replace sscanf with kstrtol
Date: Fri, 04 Aug 2017 09:27:56 +0530	[thread overview]
Message-ID: <a74af8cd71537efd19c5b7154d34ec65@codeaurora.org> (raw)

Hi,

Adding error checks to devfreq userspace governor, the current 
implementation results in setting wrong
frequency when sscanf returns error.


 From 12e0a347addd70529b2c378299b27b65f0766f99 Mon Sep 17 00:00:00 2001
 From: Santosh Mardi <gsantosh@codeaurora.org>
Date: Tue, 25 Jul 2017 18:47:11 +0530
Subject: [PATCH] devfreq: replace sscanf with kstrtol

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.

The usage for the sscanf is only for single variable so
replace sscanf with kstrtol along with 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..a84796d 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 = kstrtol(buf, 0, &wanted);
+	if (err < 0)
+		goto out;
  	data->user_frequency = wanted;
  	data->valid = true;
  	err = update_devfreq(devfreq);
  	if (err == 0)
  		err = count;
+out:
  	mutex_unlock(&devfreq->lock);
  	return err;
  }
-- 

Regards,
Santosh M G.
Qualcomm Innovation Center

             reply	other threads:[~2017-08-04  3:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-04  3:57 gsantosh [this message]
2017-08-04  4:23 ` [PATCH] devfreq: replace sscanf with kstrtol gsantosh
2017-08-04 15:12 ` Chanwoo Choi
2017-08-07  4:47   ` gsantosh
2017-08-07  5:25     ` Chanwoo Choi
2017-08-07 12:26       ` gsantosh

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=a74af8cd71537efd19c5b7154d34ec65@codeaurora.org \
    --to=gsantosh@codeaurora.org \
    --cc=gsantosh@qtil.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=rafael.j.wysocki@intel.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.