From patchwork Tue May 21 04:44:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 164674 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1136196ili; Mon, 20 May 2019 21:45:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqxk5eyeFg3myBtIQ96JZIpQ9LGGdkghOZhPlSij7RiUD0wFrDfFRgWl7m6ypUhk4YNbrqsN X-Received: by 2002:a62:55:: with SMTP id 82mr1785452pfa.86.1558413959739; Mon, 20 May 2019 21:45:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558413959; cv=none; d=google.com; s=arc-20160816; b=J9omyTSqm+915HrZase0AzTEj2XnaIS5hBmHcY7wT+8sgGnTAF+aSUfyemLqpDgycA ZqgF7LQVB/yM7P2L32hQkYcu2HNx9AiiosCM+uBe/sz5WBG78rv+Zw92AS3Ybn/dG26P CpKC2mYX65KpIXNgYdwv7gjaehAQ7thxKLfnakoBCpzenVndEOAVCS7J5MaiCOQ7OiR3 +Ra6i824NO4oRAo1SoRAr0xq832aGZrb6Lde21Hs9MWECtz/YhuJm7EPW85zHuuUtz7l KjWfRxbiTcyW0WmfbNoXmvGWlX34rRURVQTqc+9ePDj32gzfk4VoQgQTb7sCNR1DH1tz o2uA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=N88lxtbnzchnuln3kdpCsIRtX8wQQcLnnyr12+pyEA4=; b=BO/ZfqpLsVdm2v9L+CiASfzzQ37Mk6Bt5G1ntyJlXAHZTpRXgq4Nln7G72EbtxXamS PS2I4S2Ub0/PVLx0iADkoZqe87cp1BuF7dF/oYpDsBfwp6av0ox9MzNLu5H5/lx9rLcj VSICn/zUcRZC6sKliCzafzuxIxU7AgQef53xTG7m3b34noL2Z+RIbIdIgZlnr39DIZWv WyXUF1JzHeoYfCXjK0Bn/GkssBFMSN3ZzfsCTat1/xkK3zmISBccrL/DFInN2TeXBsy7 gPKTw8Zi18LtHMkp0d83q6186q4Wh692LyVIBbSr2+wNMqYofO6z83UqvbqUj+PPcXFm aaWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=nN24I3Kc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h34si20446073pld.187.2019.05.20.21.45.59; Mon, 20 May 2019 21:45:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=nN24I3Kc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727012AbfEUEp6 (ORCPT + 30 others); Tue, 21 May 2019 00:45:58 -0400 Received: from conuserg-09.nifty.com ([210.131.2.76]:41790 "EHLO conuserg-09.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725379AbfEUEp6 (ORCPT ); Tue, 21 May 2019 00:45:58 -0400 Received: from localhost.localdomain (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-09.nifty.com with ESMTP id x4L4iwCe021907; Tue, 21 May 2019 13:44:58 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com x4L4iwCe021907 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1558413899; bh=N88lxtbnzchnuln3kdpCsIRtX8wQQcLnnyr12+pyEA4=; h=From:To:Cc:Subject:Date:From; b=nN24I3KcaWzO4XVgA/xvocOFaAthUzPFxiSIjfSsLehlAsUZU4jGu2yxWLX/ALLBF IxNjldFTcUBGajHM5nDe/+4dK/Ps6TiO1PpvEgDqDoEE3hfLM6meVgv66oBExTF0lc GAnMgw55aiGyb+IH+jGTTHGkYPUWM9U5hjh+O23e0JkHLXVPH2lZRO1sq8bkz/vMiq /UkGXBJZ3IrWxUccP06WAu8ZpY33s0/l8NX00PMooZFxX3CP9aL0Kk/U/AkMgjBb4b usYZ0gmIZZSxqgRu7sK8eGUB5P6eGh8Y2HuN9xMk09ZeeICFUBlGF5gsnzyZTTRWA4 gWVxoPFmzsozQ== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: Jean Delvare , Guenter Roeck , linux-hwmon@vger.kernel.org Cc: Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH] hwmon: (smsc47m1) fix outside array bounds warnings Date: Tue, 21 May 2019 13:44:56 +0900 Message-Id: <20190521044456.26431-1-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Kbuild test robot reports outside array bounds warnings: CC [M] drivers/hwmon/smsc47m1.o drivers/hwmon/smsc47m1.c: In function 'fan_div_store': drivers/hwmon/smsc47m1.c:370:49: warning: array subscript [0, 2] is outside array bounds of 'u8[3]' {aka 'unsigned char[3]'} [-Warray-bounds] tmp = 192 - (old_div * (192 - data->fan_preload[nr]) ~~~~~~~~~~~~~~~~~^~~~ drivers/hwmon/smsc47m1.c:372:19: warning: array subscript [0, 2] is outside array bounds of 'u8[3]' {aka 'unsigned char[3]'} [-Warray-bounds] data->fan_preload[nr] = clamp_val(tmp, 0, 191); ~~~~~~~~~~~~~~~~~^~~~ drivers/hwmon/smsc47m1.c:373:53: warning: array subscript [0, 2] is outside array bounds of 'const u8[3]' {aka 'const unsigned char[3]'} [-Warray-bounds] smsc47m1_write_value(data, SMSC47M1_REG_FAN_PRELOAD[nr], ~~~~~~~~~~~~~~~~~~~~~~~~^~~~ The index field in the SENSOR_DEVICE_ATTR_R* defines is 0, 1, or 2. However, the compiler never knows the fact that the default in the switch statement is unreachable. Reported-by: kbuild test robot Signed-off-by: Masahiro Yamada --- drivers/hwmon/smsc47m1.c | 4 ++++ 1 file changed, 4 insertions(+) -- 2.17.1 diff --git a/drivers/hwmon/smsc47m1.c b/drivers/hwmon/smsc47m1.c index 5f92eab24c62..e00102e05666 100644 --- a/drivers/hwmon/smsc47m1.c +++ b/drivers/hwmon/smsc47m1.c @@ -364,6 +364,10 @@ static ssize_t fan_div_store(struct device *dev, tmp |= data->fan_div[2] << 4; smsc47m1_write_value(data, SMSC47M2_REG_FANDIV3, tmp); break; + default: + WARN_ON(1); + mutex_unlock(&data->update_lock); + return -EINVAL; } /* Preserve fan min */