From patchwork Mon May 30 21:27:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Valentin X-Patchwork-Id: 9142531 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 089BD60761 for ; Mon, 30 May 2016 21:35:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EEF462793B for ; Mon, 30 May 2016 21:35:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E3E282810E; Mon, 30 May 2016 21:35:06 +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 954942793B for ; Mon, 30 May 2016 21:35:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1161715AbcE3Vef (ORCPT ); Mon, 30 May 2016 17:34:35 -0400 Received: from mail-pa0-f67.google.com ([209.85.220.67]:35954 "EHLO mail-pa0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1423339AbcE3V2x (ORCPT ); Mon, 30 May 2016 17:28:53 -0400 Received: by mail-pa0-f67.google.com with SMTP id fg1so22442804pad.3; Mon, 30 May 2016 14:28:53 -0700 (PDT) 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=NBb3CZy9mm8eVNsr57Ne3MFXpzITqX1XdVVAQL8c4io=; b=CsaE1ffzbhXeQqFAvNhnyZSYx33DnFRcIc4rW7Ok4hJCzI0IJ9s3xfGd/Quud5yXE4 ixjmm/KVkkqGn8IAay5I5ES3epGXfLG0YXukJKSp4+KhKjswFRfvFaMiYaWD3QXKO1ms nonXgfRxSu7f3KJKQXzWL02k4OMXMqd3kD8bAgYOy9np/lU3UqY6X3Yhn+WpNuYVBs+w VVNVD17rb2dBoMr/rUkeDneWmF2do9Ah5fJECx7V6oOiV5QVk9OHdcjfTHh7zamV4F36 cHLZMc1awxySg4rbTHaekVbL7z2hS0Z4paTdxw8loy/cIuxSgkj4OAT4KnBhHE2aqwgv eJeQ== 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=NBb3CZy9mm8eVNsr57Ne3MFXpzITqX1XdVVAQL8c4io=; b=QQaUz373FboSkuhOVUwbg/RmClQ9VYzL/770SQfRZHX0NpTwEU+wpT83q+8keugwe2 IjX5dIBzvzTWkCKoT7XntrdE+EB1CSZ8rai5D09GTZiFQ1B6Jwiw0/R4uGaux+A7nuMh D1weVq6KHBXfqKvqmTsk+EfORdzeJ9fZG4C8T88K7eOjs7YSPLzwy8DMvfnychyLBFf9 P1hzTMVuDE/ETD5K/HqdEwx4GHhxMlD9W+XvxzhYigVhGYk/1e1Z/0WDEW1Zd5E6PLLy KDdwiuH89fTNKY7EDfzRtRUWFPPLGYfCWU5KMBlXQnc/qQq5yzUdWgzvPVwXXEmQC1y7 h2Ig== X-Gm-Message-State: ALyK8tKviGgbAsg1Ih+USMllpLT84dCMTHt+hoaB+Gt0GKlM5zwiuewN2eUt1zXqxtZO4Q== X-Received: by 10.66.240.8 with SMTP id vw8mr49999799pac.62.1464643733093; Mon, 30 May 2016 14:28:53 -0700 (PDT) Received: from localhost ([2601:b00:c501:3660:7256:81ff:febd:926d]) by smtp.gmail.com with ESMTPSA id p65sm35097964pfd.6.2016.05.30.14.28.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 May 2016 14:28:52 -0700 (PDT) From: Eduardo Valentin To: Rui Zhang Cc: Linux PM , LKML , Eduardo Valentin Subject: [PATCHv2 20/40] thermal: core: treat correctly the return value of *scanf calls Date: Mon, 30 May 2016 14:27:39 -0700 Message-Id: <1464643679-2733-21-git-send-email-edubezval@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1464643679-2733-1-git-send-email-edubezval@gmail.com> References: <1464643679-2733-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 cfa74e6..98aa7d5 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -817,7 +817,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); @@ -849,7 +849,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)) @@ -875,7 +875,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); @@ -897,7 +897,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)) @@ -924,7 +924,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); @@ -939,7 +939,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 @@ -1381,7 +1381,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)