From patchwork Tue Nov 8 05:08:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Valentin X-Patchwork-Id: 9416461 X-Patchwork-Delegate: rui.zhang@intel.com 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 E28C160512 for ; Tue, 8 Nov 2016 05:10:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D3B7027FAC for ; Tue, 8 Nov 2016 05:10:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C87822876A; Tue, 8 Nov 2016 05:10:41 +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_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,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 18CEA28B7F for ; Tue, 8 Nov 2016 05:10:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932162AbcKHFKc (ORCPT ); Tue, 8 Nov 2016 00:10:32 -0500 Received: from mail-pf0-f196.google.com ([209.85.192.196]:34774 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753076AbcKHFKa (ORCPT ); Tue, 8 Nov 2016 00:10:30 -0500 Received: by mail-pf0-f196.google.com with SMTP id y68so18086817pfb.1; Mon, 07 Nov 2016 21:10:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=I0Hi7da7QTb3PUQrRkBlah8dzskxEDwqWVwMJWN474M=; b=WXEU/2wUxlhcjJTCTewknBB1F3od8nNCKkQYtPrfM0YbOEl+v1++IJeCYa2oodJsER mpRQxjV5LoX8JdKmkPDbAEa19yYPFmev9qGjPZ2hWwZLhYJnRz3E9xnN7IyuyjQ4Sqnv FXuo1DTcjV/xYC5+OJ+zzEHTt+oSrNj7F/FezSHoQ/T/Fp4Mhjxts1rf386FV6vzzWEi uryHhtBKBunmgMmaJRqui9lY16f9vMsK7oQT/DkcvBVf5LGA6QMhu0nsyQ9YVcQqFmCG CPB4LMqBFi0mcjfshJ5y29CsNhld53V63O8xX81F8NJxz0hlLk2wwbBdU6SIZxwfP2+Z 7qvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=I0Hi7da7QTb3PUQrRkBlah8dzskxEDwqWVwMJWN474M=; b=JxiLQSTIoXUMobjew5LZteTzqmS59OB1VX/wH+cyl8H5oaWq8hOVOwIF70YbncXSWO TSlRQ9o+8y8mhYPQjcMzve+CEc3hnoXHqONPElzEkSuM6LYYJpB3FgPnn7aXfw75dxs3 NVDNreXkImCTgnW8r0e0Ax0CaXGhaTqzyE/WtXa1iVqNl+azXCGA+VMSfcq/bR/mV4B9 dgTYFUEehMmy1idKP4ca3MjymC34eKejDNAxbz06CQLyB4yKoAJ6K2DS7nyRQqFRAKsF hI2o3aJYdbMF1J85KpjoZZpNqi8WjiWAUN0nZbc3Vg6JQspBM+lX2PPJYH/F1decpnLm WUpQ== X-Gm-Message-State: ABUngvceo8uT9o0CiTrjqKr1VSNcSwnyW77zeMge7PlZNVdy7AGL2nSyC4wI44hNZYEdoA== X-Received: by 10.99.226.83 with SMTP id y19mr16187051pgj.147.1478581829510; Mon, 07 Nov 2016 21:10:29 -0800 (PST) Received: from localhost ([2601:647:4401:a2f0:7256:81ff:febd:926d]) by smtp.gmail.com with ESMTPSA id zf9sm20450631pac.12.2016.11.07.21.10.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Nov 2016 21:10:28 -0800 (PST) From: Eduardo Valentin To: Rui Zhang Cc: LKML , Linux PM , Eduardo Valentin Subject: [PATCHv2 20/49] thermal: core: treat correctly the return value of *scanf calls Date: Mon, 7 Nov 2016 21:08:58 -0800 Message-Id: <1478581767-7009-21-git-send-email-edubezval@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1478581767-7009-1-git-send-email-edubezval@gmail.com> References: <1478581767-7009-1-git-send-email-edubezval@gmail.com> 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 This patch checks the return value of all calls to *scanf. The check is to simply match the number of expect inputs. The current code does not do any recovery in case the number of treated inputs are different than the expected. Therefore, keeping the same behavior. Cc: Zhang Rui Cc: linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Eduardo Valentin --- drivers/thermal/thermal_core.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index f5b519a..e2c4fc4 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -874,7 +874,7 @@ trip_point_type_show(struct device *dev, struct device_attribute *attr, if (!tz->ops->get_trip_type) return -EPERM; - if (!sscanf(attr->attr.name, "trip_point_%d_type", &trip)) + if (sscanf(attr->attr.name, "trip_point_%d_type", &trip) != 1) return -EINVAL; result = tz->ops->get_trip_type(tz, trip, &type); @@ -906,7 +906,7 @@ trip_point_temp_store(struct device *dev, struct device_attribute *attr, if (!tz->ops->set_trip_temp) return -EPERM; - if (!sscanf(attr->attr.name, "trip_point_%d_temp", &trip)) + if (sscanf(attr->attr.name, "trip_point_%d_temp", &trip) != 1) return -EINVAL; if (kstrtoint(buf, 10, &temperature)) @@ -932,7 +932,7 @@ trip_point_temp_show(struct device *dev, struct device_attribute *attr, if (!tz->ops->get_trip_temp) return -EPERM; - if (!sscanf(attr->attr.name, "trip_point_%d_temp", &trip)) + if (sscanf(attr->attr.name, "trip_point_%d_temp", &trip) != 1) return -EINVAL; ret = tz->ops->get_trip_temp(tz, trip, &temperature); @@ -954,7 +954,7 @@ trip_point_hyst_store(struct device *dev, struct device_attribute *attr, if (!tz->ops->set_trip_hyst) return -EPERM; - if (!sscanf(attr->attr.name, "trip_point_%d_hyst", &trip)) + if (sscanf(attr->attr.name, "trip_point_%d_hyst", &trip) != 1) return -EINVAL; if (kstrtoint(buf, 10, &temperature)) @@ -984,7 +984,7 @@ trip_point_hyst_show(struct device *dev, struct device_attribute *attr, if (!tz->ops->get_trip_hyst) return -EPERM; - if (!sscanf(attr->attr.name, "trip_point_%d_hyst", &trip)) + if (sscanf(attr->attr.name, "trip_point_%d_hyst", &trip) != 1) return -EINVAL; ret = tz->ops->get_trip_hyst(tz, trip, &temperature); @@ -999,7 +999,7 @@ passive_store(struct device *dev, struct device_attribute *attr, struct thermal_zone_device *tz = to_thermal_zone(dev); int state; - if (!sscanf(buf, "%d\n", &state)) + if (sscanf(buf, "%d\n", &state) != 1) return -EINVAL; /* sanity check: values below 1000 millicelcius don't make sense @@ -1457,7 +1457,7 @@ thermal_cooling_device_cur_state_store(struct device *dev, unsigned long state; int result; - if (!sscanf(buf, "%ld\n", &state)) + if (sscanf(buf, "%ld\n", &state) != 1) return -EINVAL; if ((long)state < 0)