From patchwork Fri Aug 4 04:23:30 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: 9880419 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 F21DD603B4 for ; Fri, 4 Aug 2017 04:24:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DAC1828975 for ; Fri, 4 Aug 2017 04:24:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BD90E28912; Fri, 4 Aug 2017 04:24:23 +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=ham 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 43A9A28912 for ; Fri, 4 Aug 2017 04:24:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751093AbdHDEXc (ORCPT ); Fri, 4 Aug 2017 00:23:32 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:56354 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750899AbdHDEXb (ORCPT ); Fri, 4 Aug 2017 00:23:31 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 0FAB6602BE; Fri, 4 Aug 2017 04:23:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1501820611; bh=qwXUTUOdSUjR7uNXgMd4x31mek59OPtcJMczpoeT4ro=; h=Date:From:To:Subject:In-Reply-To:References:From; b=iVZLQOe82pF/T9YcnyTgw+keYSSNHqHkdARGoru9TXOwb7QgdjRDJWpUcqRVIJFFp +3CB0U1+VVBfuYEjE8qEZ6gFCC6YxXhLddnNAPfATMrdRAevbCwB120zlKN6BMKaxV nDDjWK4m2POSM7uPT0NsLZbd9dK1vdwIpCbqM2F0= Received: from mail.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.codeaurora.org (Postfix) with ESMTP id 64E9E602BE; Fri, 4 Aug 2017 04:23:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1501820610; bh=qwXUTUOdSUjR7uNXgMd4x31mek59OPtcJMczpoeT4ro=; h=Date:From:To:Subject:In-Reply-To:References:From; b=k/BIhnHN7XRID3gll/33YnV6C8D8Xc/5vJQKyJs3S9rirkGmvxKrK9Pz4eilUxJHi fgF4Hx19IHlAMmRVONSo5O/zt0Nv3ILnsYR7Ta2PZqm3FaPCnTMZ+qbMD2mWZuD5if tCxCflAbKEjm4mGqhGSHtiKmOwbemnXvNCpUb0Qs= MIME-Version: 1.0 Date: Fri, 04 Aug 2017 09:53:30 +0530 From: gsantosh@codeaurora.org To: MyungJoo Ham , Kyungmin Park , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, "Rafael J. Wysocki" , gsantosh@qti.qualcomm.com Subject: [PATCH] devfreq: replace sscanf with kstrtol In-Reply-To: References: Message-ID: <76b99c5399941998bf19e51795c404eb@codeaurora.org> 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;