From patchwork Tue Aug 14 09:12:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 10565203 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CBE9E1390 for ; Tue, 14 Aug 2018 09:13:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B89DC28F65 for ; Tue, 14 Aug 2018 09:13:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AAC2C29742; Tue, 14 Aug 2018 09:13: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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY 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 4CB4F28F65 for ; Tue, 14 Aug 2018 09:13:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728978AbeHNL7Z (ORCPT ); Tue, 14 Aug 2018 07:59:25 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:48192 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728314AbeHNL7Z (ORCPT ); Tue, 14 Aug 2018 07:59:25 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w7E98vKB187271; Tue, 14 Aug 2018 09:12:48 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : mime-version : content-type; s=corp-2018-07-02; bh=yA+dDFsMlFT9NYNBBLqMV4rzQ7pdCK9p3fRveGZNn/k=; b=DBjHWPdJhDqGoCzba9NJYj+RVfTY+Nf+v+5W6TfYr+bfpF3oaH5gapK7xlCEb88mjZRa 36hKNqNT3R0CB4ZPOqcJr4+L36+/4iI8Mg/KscApWfH9ROwsO2kwUrOzQjRiQrB7GSWm zqFKon9Y7RNkWZBUbaDXfUES7Tx9s4jBOZjIOwlf/I0NPdCCcAuQLD7Y+9N1gKp+ihLC pFvcxLddU4RtS/67qtU8RLBFH2SOX2tvxBHN6zDiL4fW4YIjZueS9OWLy2a9Pk3WZByt H1t3Qur0NLQSETAna9akI9cC7srqiRwUEHW83bbOu+yhhgX7ccT9c0sCh5crhE2Loubv rw== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2120.oracle.com with ESMTP id 2ksrepykff-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 14 Aug 2018 09:12:48 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w7E9CkEJ015885 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 14 Aug 2018 09:12:46 GMT Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w7E9CjH2002738; Tue, 14 Aug 2018 09:12:45 GMT Received: from kili.mountain (/197.232.248.111) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 14 Aug 2018 02:12:43 -0700 Date: Tue, 14 Aug 2018 12:12:36 +0300 From: Dan Carpenter To: Jean Delvare , Tokunori Ikegami Cc: Guenter Roeck , linux-hwmon@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH 1/2] hwmon: (adt7475) Potential error pointer dereferences Message-ID: <20180814091236.zubxfj32bedobr52@kili.mountain> MIME-Version: 1.0 Content-Disposition: inline X-Mailer: git-send-email haha only kidding User-Agent: NeoMutt/20170113 (1.7.2) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8984 signatures=668707 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=975 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1808140095 Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The adt7475_update_device() function returns error pointers. The problem is that in show_pwmfreq() we dereference it before the check. And then in pwm_use_point2_pwm_at_crit_show() there isn't a check at all. I don't know if it's required, but it silences a static checker warning and it's doesn't hurt anything to check. Signed-off-by: Dan Carpenter Reviewed-by: Tokunori Ikegami diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c index 90837f7c7d0f..16045149f3db 100644 --- a/drivers/hwmon/adt7475.c +++ b/drivers/hwmon/adt7475.c @@ -962,13 +962,14 @@ static ssize_t show_pwmfreq(struct device *dev, struct device_attribute *attr, { struct adt7475_data *data = adt7475_update_device(dev); struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); - int i = clamp_val(data->range[sattr->index] & 0xf, 0, - ARRAY_SIZE(pwmfreq_table) - 1); + int idx; if (IS_ERR(data)) return PTR_ERR(data); + idx = clamp_val(data->range[sattr->index] & 0xf, 0, + ARRAY_SIZE(pwmfreq_table) - 1); - return sprintf(buf, "%d\n", pwmfreq_table[i]); + return sprintf(buf, "%d\n", pwmfreq_table[idx]); } static ssize_t set_pwmfreq(struct device *dev, struct device_attribute *attr, @@ -1004,6 +1005,10 @@ static ssize_t pwm_use_point2_pwm_at_crit_show(struct device *dev, char *buf) { struct adt7475_data *data = adt7475_update_device(dev); + + if (IS_ERR(data)) + return PTR_ERR(data); + return sprintf(buf, "%d\n", !!(data->config4 & CONFIG4_MAXDUTY)); } From patchwork Tue Aug 14 09:14:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 10565205 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8D5011390 for ; Tue, 14 Aug 2018 09:15:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7A55129755 for ; Tue, 14 Aug 2018 09:15:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6D6942978B; Tue, 14 Aug 2018 09:15:01 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY 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 154C129755 for ; Tue, 14 Aug 2018 09:15:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730847AbeHNMBS (ORCPT ); Tue, 14 Aug 2018 08:01:18 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:55024 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728101AbeHNMBR (ORCPT ); Tue, 14 Aug 2018 08:01:17 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w7E992E6196110; Tue, 14 Aug 2018 09:14:41 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : mime-version : content-type : in-reply-to; s=corp-2018-07-02; bh=l3z3xSFRGu/dTBQlYR3PBeJq15qXpGetA3wM0AkNWx0=; b=XIn0RYLGx1PlyCnpMjlkn45XBVodpO8GVWGsIWyHw4Kefjs77DnZHSJwVtt/YKKikgi3 jFxfdgSoIOicJnwrV1HgebpiXmv+0kB+ThaXZ0VFa/oB5AlR5L2IajKiPUGypUc6tN2Y P+05VL0V4H88uWz1u4qgt5tK2ZWw3G+Z0lHI0wJwL+yjBSnEwsWShylEGLP7c5RAT/5v EpkbYNb8szTYwn8MHxtsnQcIAZ69muhus6bZfQ0IgdMSBNs8YhMOaKcPL5udM5Z+kN7/ NZIVzZ7nZHu90qb7AgcG4ATGS9mvk7Z5bsHk0u66AfnsrqUouaJ28N3QDNMe1BH4Lkz6 2w== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2130.oracle.com with ESMTP id 2ksq7t7npe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 14 Aug 2018 09:14:41 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w7E9Eenv029919 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 14 Aug 2018 09:14:40 GMT Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w7E9EefA003664; Tue, 14 Aug 2018 09:14:40 GMT Received: from kili.mountain (/197.232.248.111) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 14 Aug 2018 02:14:39 -0700 Date: Tue, 14 Aug 2018 12:14:32 +0300 From: Dan Carpenter To: Jean Delvare , Tokunori Ikegami Cc: Guenter Roeck , linux-hwmon@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH 2/2] hwmon: (adt7475) Remove some unnecessary checks Message-ID: <20180814091432.xhdmxd7aqbz2si4k@kili.mountain> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20180814091236.zubxfj32bedobr52@kili.mountain> X-Mailer: git-send-email haha only kidding User-Agent: NeoMutt/20170113 (1.7.2) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8984 signatures=668707 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=950 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1808140095 Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The adt7475_read_word() returns u16 values, so it's impossible for "ret" to be negative. The check is harmless, but static checkers complain about it. Signed-off-by: Dan Carpenter Reviewed-by: Tokunori Ikegami diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c index 16045149f3db..9d3da8ea38ba 100644 --- a/drivers/hwmon/adt7475.c +++ b/drivers/hwmon/adt7475.c @@ -1492,10 +1492,7 @@ static int adt7475_update_limits(struct i2c_client *client) for (i = 0; i < ADT7475_TACH_COUNT; i++) { if (i == 3 && !data->has_fan4) continue; - ret = adt7475_read_word(client, TACH_MIN_REG(i)); - if (ret < 0) - return ret; - data->tach[MIN][i] = ret; + data->tach[MIN][i] = adt7475_read_word(client, TACH_MIN_REG(i)); } for (i = 0; i < ADT7475_PWM_COUNT; i++) { @@ -1881,10 +1878,7 @@ static int adt7475_update_measure(struct device *dev) for (i = 0; i < ADT7475_TACH_COUNT; i++) { if (i == 3 && !data->has_fan4) continue; - ret = adt7475_read_word(client, TACH_REG(i)); - if (ret < 0) - return ret; - data->tach[INPUT][i] = ret; + data->tach[INPUT][i] = adt7475_read_word(client, TACH_REG(i)); } /* Updated by hw when in auto mode */