From patchwork Mon Aug 7 13:06:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: gsantosh@codeaurora.org X-Patchwork-Id: 9885375 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4EDA2602CC for ; Mon, 7 Aug 2017 13:07:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 42037285A9 for ; Mon, 7 Aug 2017 13:07:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 36C722867E; Mon, 7 Aug 2017 13:07:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CEC78285A9 for ; Mon, 7 Aug 2017 13:07:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752103AbdHGNHW (ORCPT ); Mon, 7 Aug 2017 09:07:22 -0400 Received: from alexa-out.qualcomm.com ([129.46.98.28]:11011 "EHLO alexa-out-lv-01.qualcomm.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751870AbdHGNHV (ORCPT ); Mon, 7 Aug 2017 09:07:21 -0400 X-IronPort-AV: E=Sophos;i="5.41,338,1498546800"; d="scan'208";a="2660651" Received: from ironmsg02-l-new.qualcomm.com (HELO ironmsg02-L.qualcomm.com) ([10.53.140.109]) by alexa-out-lv-01.qualcomm.com with ESMTP; 07 Aug 2017 06:07:20 -0700 X-IronPort-AV: E=McAfee;i="5900,7806,8614"; a="978225653" X-MGA-submission: =?us-ascii?q?MDGj2uLDUd98+CjAeSOGWh+9z48UF3HvbmKMTf?= =?us-ascii?q?dQCZpadE5Xa/lyYJcYaH7s3spJdAEfVBDBY83MpyVtQtD9Aw/J3eLsSx?= =?us-ascii?q?IA+OBfj7Un1FMT24PqfzcyBOI9HClj/V1zwCU+OGPexv+IIdXYUk939i?= =?us-ascii?q?zq?= Received: from gsantosh-ics.qualcomm.com ([10.204.78.23]) by ironmsg02-L.qualcomm.com with ESMTP; 07 Aug 2017 06:07:17 -0700 Received: by gsantosh-ics.qualcomm.com (Postfix, from userid 75714) id BCF572114; Mon, 7 Aug 2017 18:37:15 +0530 (IST) From: Santosh Mardi To: myungjoo.ham@samsung.com, kyungmin.park@samsung.com, rafael.j.wysocki@intel.com, cw00.choi@samsung.com Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, gsantosh@qti.qualcomm.com, gsantosh@codeaurora.org, skannan@quicinc.com, rgottimu@qti.qualcomm.com Subject: [PATCH] devfreq: add error check for sscanf in userspace governor Date: Mon, 7 Aug 2017 18:36:45 +0530 Message-Id: <1502111205-22560-2-git-send-email-gsantosh@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1502111205-22560-1-git-send-email-gsantosh@codeaurora.org> References: <1502111205-22560-1-git-send-email-gsantosh@codeaurora.org> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Acked-by: MyungJoo Ham Reviewed-by: Chanwoo Choi --- 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); + if (err != 1) + 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; }