All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Guenter Roeck <linux@roeck-us.net>,
	Sasha Levin <alexander.levin@microsoft.com>
Subject: [PATCH AUTOSEL 4.18 15/48] hwmon: (nct6775) Fix access to fan pulse registers
Date: Fri,  5 Oct 2018 12:13:51 -0400	[thread overview]
Message-ID: <20181005161424.20521-15-sashal@kernel.org> (raw)
In-Reply-To: <20181005161424.20521-1-sashal@kernel.org>

From: Guenter Roeck <linux@roeck-us.net>

[ Upstream commit c793279c77035053e67937f5743c6ebfc303e7c5 ]

Not all fans have a fan pulse register. This can result in reading
beyond the end of REG_FAN_PULSES and FAN_PULSE_SHIFT arrays,
and was reported by smatch as possible error.

1672          for (i = 0; i < ARRAY_SIZE(data->rpm); i++) {
                              ^^^^^^^^^^^^^^^^^^^^^^^^
			      This is a 7 element array.
...
1685                  data->fan_pulses[i] =
1686                    (nct6775_read_value(data, data->REG_FAN_PULSES[i])
1687                          >> data->FAN_PULSE_SHIFT[i]) & 0x03;
                                 ^^^^^^^^^^^^^^^^^^^^^^^^
				 FAN_PULSE_SHIFT is either 5 or 6
				 elements.

To fix the problem, we have to ensure that all REG_FAN_PULSES and
FAN_PULSE_SHIFT have the appropriate length, and that REG_FAN_PULSES
is only read if the register actually exists.

Fixes: 6c009501ff200 ("hwmon: (nct6775) Add support for NCT6102D/6106D")
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
---
 drivers/hwmon/nct6775.c | 27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)

diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
index b89e8379d898..6f40a9435731 100644
--- a/drivers/hwmon/nct6775.c
+++ b/drivers/hwmon/nct6775.c
@@ -299,8 +299,9 @@ static const u16 NCT6775_REG_PWM_READ[] = {
 
 static const u16 NCT6775_REG_FAN[] = { 0x630, 0x632, 0x634, 0x636, 0x638 };
 static const u16 NCT6775_REG_FAN_MIN[] = { 0x3b, 0x3c, 0x3d };
-static const u16 NCT6775_REG_FAN_PULSES[] = { 0x641, 0x642, 0x643, 0x644, 0 };
-static const u16 NCT6775_FAN_PULSE_SHIFT[] = { 0, 0, 0, 0, 0, 0 };
+static const u16 NCT6775_REG_FAN_PULSES[NUM_FAN] = {
+	0x641, 0x642, 0x643, 0x644 };
+static const u16 NCT6775_FAN_PULSE_SHIFT[NUM_FAN] = { };
 
 static const u16 NCT6775_REG_TEMP[] = {
 	0x27, 0x150, 0x250, 0x62b, 0x62c, 0x62d };
@@ -425,8 +426,8 @@ static const u8 NCT6776_PWM_MODE_MASK[] = { 0x01, 0, 0, 0, 0, 0 };
 
 static const u16 NCT6776_REG_FAN_MIN[] = {
 	0x63a, 0x63c, 0x63e, 0x640, 0x642, 0x64a, 0x64c };
-static const u16 NCT6776_REG_FAN_PULSES[] = {
-	0x644, 0x645, 0x646, 0x647, 0x648, 0x649, 0 };
+static const u16 NCT6776_REG_FAN_PULSES[NUM_FAN] = {
+	0x644, 0x645, 0x646, 0x647, 0x648, 0x649 };
 
 static const u16 NCT6776_REG_WEIGHT_DUTY_BASE[] = {
 	0x13e, 0x23e, 0x33e, 0x83e, 0x93e, 0xa3e };
@@ -502,8 +503,8 @@ static const s8 NCT6779_BEEP_BITS[] = {
 
 static const u16 NCT6779_REG_FAN[] = {
 	0x4b0, 0x4b2, 0x4b4, 0x4b6, 0x4b8, 0x4ba, 0x660 };
-static const u16 NCT6779_REG_FAN_PULSES[] = {
-	0x644, 0x645, 0x646, 0x647, 0x648, 0x649, 0 };
+static const u16 NCT6779_REG_FAN_PULSES[NUM_FAN] = {
+	0x644, 0x645, 0x646, 0x647, 0x648, 0x649 };
 
 static const u16 NCT6779_REG_CRITICAL_PWM_ENABLE[] = {
 	0x136, 0x236, 0x336, 0x836, 0x936, 0xa36, 0xb36 };
@@ -779,8 +780,8 @@ static const u16 NCT6106_REG_TEMP_CONFIG[] = {
 
 static const u16 NCT6106_REG_FAN[] = { 0x20, 0x22, 0x24 };
 static const u16 NCT6106_REG_FAN_MIN[] = { 0xe0, 0xe2, 0xe4 };
-static const u16 NCT6106_REG_FAN_PULSES[] = { 0xf6, 0xf6, 0xf6, 0, 0 };
-static const u16 NCT6106_FAN_PULSE_SHIFT[] = { 0, 2, 4, 0, 0 };
+static const u16 NCT6106_REG_FAN_PULSES[] = { 0xf6, 0xf6, 0xf6 };
+static const u16 NCT6106_FAN_PULSE_SHIFT[] = { 0, 2, 4 };
 
 static const u8 NCT6106_REG_PWM_MODE[] = { 0xf3, 0xf3, 0xf3 };
 static const u8 NCT6106_PWM_MODE_MASK[] = { 0x01, 0x02, 0x04 };
@@ -1682,9 +1683,13 @@ static struct nct6775_data *nct6775_update_device(struct device *dev)
 			if (data->has_fan_min & BIT(i))
 				data->fan_min[i] = nct6775_read_value(data,
 					   data->REG_FAN_MIN[i]);
-			data->fan_pulses[i] =
-			  (nct6775_read_value(data, data->REG_FAN_PULSES[i])
-				>> data->FAN_PULSE_SHIFT[i]) & 0x03;
+
+			if (data->REG_FAN_PULSES[i]) {
+				data->fan_pulses[i] =
+				  (nct6775_read_value(data,
+						      data->REG_FAN_PULSES[i])
+				   >> data->FAN_PULSE_SHIFT[i]) & 0x03;
+			}
 
 			nct6775_select_fan_div(dev, data, i, reg);
 		}
-- 
2.17.1


  parent reply	other threads:[~2018-10-05 16:14 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-05 16:13 [PATCH AUTOSEL 4.18 01/48] ASoC: dapm: Fix NULL pointer deference on CODEC to CODEC DAIs Sasha Levin
2018-10-05 16:13 ` [PATCH AUTOSEL 4.18 02/48] ASoC: max98373: Added speaker FS gain cotnrol register to volatile Sasha Levin
2018-10-05 16:13 ` [PATCH AUTOSEL 4.18 03/48] ASoC: rt5514: Fix the issue of the delay volume applied again Sasha Levin
2018-10-05 16:13 ` [PATCH AUTOSEL 4.18 04/48] selftests: android: move config up a level Sasha Levin
2018-10-05 16:13 ` [PATCH AUTOSEL 4.18 05/48] selftests: kselftest: Remove outdated comment Sasha Levin
2018-10-05 16:13 ` [PATCH AUTOSEL 4.18 06/48] ASoC: max98373: Added 10ms sleep after amp software reset Sasha Levin
2018-10-05 16:13 ` [PATCH AUTOSEL 4.18 07/48] ASoC: wm8804: Add ACPI support Sasha Levin
2018-10-05 16:13 ` [PATCH AUTOSEL 4.18 08/48] ASoC: sigmadsp: safeload should not have lower byte limit Sasha Levin
2018-10-05 16:13 ` [PATCH AUTOSEL 4.18 09/48] ASoC: q6routing: initialize data correctly Sasha Levin
2018-10-05 16:13 ` [PATCH AUTOSEL 4.18 10/48] selftests: add headers_install to lib.mk Sasha Levin
2018-10-05 16:13 ` [PATCH AUTOSEL 4.18 11/48] selftests/efivarfs: add required kernel configs Sasha Levin
2018-10-05 16:13 ` [PATCH AUTOSEL 4.18 12/48] selftests: memory-hotplug: add required configs Sasha Levin
2018-10-05 16:13 ` [PATCH AUTOSEL 4.18 13/48] ASoC: rsnd: adg: care clock-frequency size Sasha Levin
2018-10-05 16:13 ` [PATCH AUTOSEL 4.18 14/48] ASoC: rsnd: don't fallback to PIO mode when -EPROBE_DEFER Sasha Levin
2018-10-05 16:13 ` Sasha Levin [this message]
2018-10-05 16:13 ` [PATCH AUTOSEL 4.18 16/48] Fix cg_read_strcmp() Sasha Levin
2018-10-05 16:13 ` [PATCH AUTOSEL 4.18 17/48] Add tests for memory.oom.group Sasha Levin
2018-10-05 16:13 ` [PATCH AUTOSEL 4.18 18/48] ASoC: AMD: Ensure reset bit is cleared before configuring Sasha Levin
2018-10-05 16:13 ` [PATCH AUTOSEL 4.18 19/48] drm/pl111: Make sure of_device_id tables are NULL terminated Sasha Levin
2018-10-05 16:13 ` [PATCH AUTOSEL 4.18 20/48] Bluetooth: SMP: Fix trying to use non-existent local OOB data Sasha Levin
2018-10-05 16:13 ` [PATCH AUTOSEL 4.18 21/48] Bluetooth: Use correct tfm to generate " Sasha Levin
2018-10-05 16:13 ` [PATCH AUTOSEL 4.18 22/48] Bluetooth: hci_ldisc: Free rw_semaphore on close Sasha Levin
2018-10-05 16:13 ` [PATCH AUTOSEL 4.18 23/48] mfd: omap-usb-host: Fix dts probe of children Sasha Levin
2018-10-05 16:14 ` [PATCH AUTOSEL 4.18 24/48] KVM: PPC: Book3S HV: Don't use compound_order to determine host mapping size Sasha Levin
2018-10-05 16:14   ` [PATCH AUTOSEL 4.18 24/48] KVM: PPC: Book3S HV: Don't use compound_order to determine host mapping s Sasha Levin
2018-10-05 16:14   ` [PATCH AUTOSEL 4.18 24/48] KVM: PPC: Book3S HV: Don't use compound_order to determine host mapping size Sasha Levin
2018-10-05 16:14 ` [PATCH AUTOSEL 4.18 25/48] scsi: iscsi: target: Don't use stack buffer for scatterlist Sasha Levin
2018-10-05 16:14 ` [PATCH AUTOSEL 4.18 26/48] scsi: qla2xxx: Fix an endian bug in fcpcmd_is_corrupted() Sasha Levin
2018-10-05 16:14 ` [PATCH AUTOSEL 4.18 27/48] sound: enable interrupt after dma buffer initialization Sasha Levin
2018-10-08  9:34   ` Mark Brown
2018-10-08  9:36     ` Takashi Iwai
2018-10-05 16:14 ` [PATCH AUTOSEL 4.18 28/48] sound: don't call skl_init_chip() to reset intel skl soc Sasha Levin
2018-10-08  9:34   ` Mark Brown
2018-10-08  9:37     ` Takashi Iwai
2018-10-05 16:14 ` [PATCH AUTOSEL 4.18 29/48] bpf: btf: Fix end boundary calculation for type section Sasha Levin
2018-10-05 16:14 ` [PATCH AUTOSEL 4.18 30/48] bpf: use __GFP_COMP while allocating page Sasha Levin
2018-10-05 16:14 ` [PATCH AUTOSEL 4.18 31/48] hwmon: (nct6775) Fix virtual temperature sources for NCT6796D Sasha Levin
2018-10-05 16:14 ` [PATCH AUTOSEL 4.18 32/48] hwmon: (nct6775) Fix RPM output for fan7 on NCT6796D Sasha Levin
2018-10-05 16:14 ` [PATCH AUTOSEL 4.18 33/48] stmmac: fix valid numbers of unicast filter entries Sasha Levin
2018-10-05 16:14 ` [PATCH AUTOSEL 4.18 34/48] hwmon: (nct6775) Use different register to get fan RPM for fan7 Sasha Levin
2018-10-05 16:14 ` [PATCH AUTOSEL 4.18 35/48] net: ethernet: ti: add missing GENERIC_ALLOCATOR dependency Sasha Levin
2018-10-05 16:14 ` [PATCH AUTOSEL 4.18 36/48] net: macb: disable scatter-gather for macb on sama5d3 Sasha Levin
2018-10-05 16:14 ` [PATCH AUTOSEL 4.18 37/48] ARM: dts: at91: add new compatibility string " Sasha Levin
2018-10-05 16:14 ` [PATCH AUTOSEL 4.18 38/48] PCI: hv: support reporting serial number as slot information Sasha Levin
2018-10-05 16:14 ` [PATCH AUTOSEL 4.18 39/48] hv_netvsc: pair VF based on serial number Sasha Levin
2018-10-05 16:14 ` [PATCH AUTOSEL 4.18 40/48] clk: x86: add "ether_clk" alias for Bay Trail / Cherry Trail Sasha Levin
2018-10-05 16:14 ` [PATCH AUTOSEL 4.18 41/48] clk: x86: Stop marking clocks as CLK_IS_CRITICAL Sasha Levin
2018-10-05 16:14 ` [PATCH AUTOSEL 4.18 42/48] pinctrl: cannonlake: Fix gpio base for GPP-E Sasha Levin
2018-10-05 16:14 ` [PATCH AUTOSEL 4.18 43/48] x86/kvm/lapic: always disable MMIO interface in x2APIC mode Sasha Levin
2018-10-05 16:14 ` [PATCH AUTOSEL 4.18 44/48] drm/amdgpu: Fix SDMA HQD destroy error on gfx_v7 Sasha Levin
2018-10-05 16:14 ` [PATCH AUTOSEL 4.18 45/48] drm/amdkfd: Change the control stack MTYPE from UC to NC on GFX9 Sasha Levin
2018-10-05 16:14 ` [PATCH AUTOSEL 4.18 46/48] drm/amdkfd: Fix ATS capablity was not reported correctly on some APUs Sasha Levin
2018-10-05 16:14 ` [PATCH AUTOSEL 4.18 47/48] ubifs: Check for name being NULL while mounting Sasha Levin
2018-10-05 16:14 ` [PATCH AUTOSEL 4.18 48/48] mm: slowly shrink slabs with a relatively small number of objects Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181005161424.20521-15-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=alexander.levin@microsoft.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.