From patchwork Fri Aug 4 03:57:56 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: 9880407 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 2368F60360 for ; Fri, 4 Aug 2017 04:01:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1C83A28995 for ; Fri, 4 Aug 2017 04:01:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1164328998; Fri, 4 Aug 2017 04:01:09 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 96D2728997 for ; Fri, 4 Aug 2017 04:01:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751864AbdHDD6b (ORCPT ); Thu, 3 Aug 2017 23:58:31 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:43262 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751921AbdHDD55 (ORCPT ); Thu, 3 Aug 2017 23:57:57 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 3F5C26074C; Fri, 4 Aug 2017 03:57:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1501819077; bh=xnTbU9579xaD/db/3TwcMYdBbBuhGVUIA6zOp3ysqpM=; h=Date:From:To:Subject:From; b=Ccc13W6beNva5lwa8WwlZ+1OisJBVS3XsEoyQdcL6eeDyve0oLZDc/C9OWqfUwx0P vCIcSZIGfY5gwokpAlZoq4Ugg4iQP/gr5zyn/WZ4D1B/GEy/T9a5argYYHj7Nk8MCP zDgauzG/xfbxC7l2/MoyBRjvPPNbHqXiHFVqNfHc= Received: from mail.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.codeaurora.org (Postfix) with ESMTP id BC5B360727; Fri, 4 Aug 2017 03:57:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1501819076; bh=xnTbU9579xaD/db/3TwcMYdBbBuhGVUIA6zOp3ysqpM=; h=Date:From:To:Subject:From; b=g6mWHkg98lKtmTr/h2fnnH08of5RAFuuZaL3Owpx9TTxBDiUbY/aSPtP5nIEFX/CC p7Sz0yElhH5KY4Ut1PpxVJTvRTsP9u0P/Rj73UJuLwyBUdoiJoBneiFxwJOoGOsMTe 72ltY0d6CsNs49nfxOdTg/ZdcAW83x16EnfltYX0= MIME-Version: 1.0 Date: Fri, 04 Aug 2017 09:27:56 +0530 From: gsantosh@codeaurora.org To: MyungJoo Ham , Kyungmin Park , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, "Rafael J. Wysocki" , gsantosh@qtil.qualcomm.com Subject: [PATCH] devfreq: replace sscanf with kstrtol Message-ID: X-Sender: gsantosh@codeaurora.org User-Agent: Roundcube Webmail/1.2.5 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 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 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 --- 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;