Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp5470530imm; Tue, 16 Oct 2018 10:43:27 -0700 (PDT) X-Google-Smtp-Source: ACcGV63/IIu3GwbhL4iTKamjt1+KSH76eKc9UyJGiNxGvGlsyfkqTOgrRzvtsLNrwlFkjnqf3yR+ X-Received: by 2002:a63:fc46:: with SMTP id r6-v6mr21320390pgk.345.1539711807339; Tue, 16 Oct 2018 10:43:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539711807; cv=none; d=google.com; s=arc-20160816; b=GKmCKqnGZwYnirSu3PYzovJzIHWXYzqbCWJgh3hXCIlloY4lvZWQtx9zyOb5Zu6KX0 Afxo+XDdloNcYXVC12Oj77bzvWdcV6lhJfAL8065x9BuPvGyzq3F0T9Mlyzd6agjmZxZ DcBZY04HLEN4dlZ0Y6pd2CHpYjseM5Rs1hfJkTTuhSO5M+NWAw2tHJp6l7vUkZYRhoif SOY8y/+gxEM0z6QKjXBTbn9PE4YaKo1uutefEvbw6DwdgZs8SJsG6lu5T7Dz5zErl9JG 6fSSZH3SXCVUARaOZ03hnXrCh7rsnmFqJAx7PDMZLwXzThWN26G9+/PcyklTc8U7RuP8 VQRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=TllDu7aIdRXPUhKDMexzU/vsK3gme3mzS6nsv9PsORc=; b=mZxdiEwCPpFYVE3JrrEJIneWy6VbmvIc3m1epMfDjDaLRze2E4xWresCStzioVAmBr ZagS7PjyJE8r0okWaRier1jNb12j6D/oZ1bc19CxD/lq67L8ALLDFed0c9m1dn9afLQr ehha8cmY0xWKYC7AykIXv2W7l+7eX/MsWhtZMZwZHYVVDUbohmfNKUuWcpKdUE3YxKc7 xl/k8VA+v91MHuGIZ0elp1kRpGPRYc94qTCGJ8BD7qF/nx9GrNbXWpFogWlarFggXay1 CmMI+ZELoYu9qT38v8N4NEoyZfYv9isRgqW2dHBIRN7bZvz36lh+KkD2j1i4mRZ87RkE IEfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ywYMVoDH; 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 f76-v6si16789419pfa.73.2018.10.16.10.43.11; Tue, 16 Oct 2018 10:43:27 -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=@kernel.org header.s=default header.b=ywYMVoDH; 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 S1728948AbeJQBFH (ORCPT + 99 others); Tue, 16 Oct 2018 21:05:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:48246 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727280AbeJQBFG (ORCPT ); Tue, 16 Oct 2018 21:05:06 -0400 Received: from localhost (ip-213-127-77-176.ip.prioritytelecom.net [213.127.77.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 16F592098A; Tue, 16 Oct 2018 17:13:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539710023; bh=lcD1Z/SiZSVb0tPJOLh6OgsY+NW4j0uej46Jhc6piOM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ywYMVoDHuVOhNP52wkS58+ZM3dmZ6Kp4xu3fjKBI6gOJWKXWjbkl//4tY9RroDmxt WHK2w4F7lqfvFuDwe+low0HQKBqoYIteuKsCmmeCSGoZLVMCNkbXPN0TzD69W8B/mX Y4fyGGFvTWD6lBEs/+XkDYM76dxu0Jl0dCmgb9N8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Guenter Roeck , Sasha Levin Subject: [PATCH 4.18 077/135] hwmon: (nct6775) Fix access to fan pulse registers Date: Tue, 16 Oct 2018 19:05:07 +0200 Message-Id: <20181016170520.501191047@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181016170515.447235311@linuxfoundation.org> References: <20181016170515.447235311@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Guenter Roeck [ 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 Signed-off-by: Guenter Roeck Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/hwmon/nct6775.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) --- 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[] 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_upda 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); }