Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/torvalds/linux.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2022-01-25hwmon: (nct6775) Fix crash in clear_caseopenGuenter Roeck
Paweł Marciniak reports the following crash, observed when clearing the chassis intrusion alarm. BUG: kernel NULL pointer dereference, address: 0000000000000028 PGD 0 P4D 0 Oops: 0000 [#1] PREEMPT SMP PTI CPU: 3 PID: 4815 Comm: bash Tainted: G S 5.16.2-200.fc35.x86_64 #1 Hardware name: To Be Filled By O.E.M. To Be Filled By O.E.M./Z97 Extreme4, BIOS P2.60A 05/03/2018 RIP: 0010:clear_caseopen+0x5a/0x120 [nct6775] Code: 68 70 e8 e9 32 b1 e3 85 c0 0f 85 d2 00 00 00 48 83 7c 24 ... RSP: 0018:ffffabcb02803dd8 EFLAGS: 00010246 RAX: 0000000000000000 RBX: 0000000000000002 RCX: 0000000000000000 RDX: ffff8e8808192880 RSI: 0000000000000000 RDI: ffff8e87c7509a68 RBP: 0000000000000000 R08: 0000000000000001 R09: 000000000000000a R10: 000000000000000a R11: f000000000000000 R12: 000000000000001f R13: ffff8e87c7509828 R14: ffff8e87c7509a68 R15: ffff8e88494527a0 FS: 00007f4db9151740(0000) GS:ffff8e8ebfec0000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000000000028 CR3: 0000000166b66001 CR4: 00000000001706e0 Call Trace: <TASK> kernfs_fop_write_iter+0x11c/0x1b0 new_sync_write+0x10b/0x180 vfs_write+0x209/0x2a0 ksys_write+0x4f/0xc0 do_syscall_64+0x3b/0x90 entry_SYSCALL_64_after_hwframe+0x44/0xae The problem is that the device passed to clear_caseopen() is the hwmon device, not the platform device, and the platform data is not set in the hwmon device. Store the pointer to sio_data in struct nct6775_data and get if from there if needed. Fixes: 2e7b9886968b ("hwmon: (nct6775) Use superio_*() function pointers in sio_data.") Cc: Denis Pauk <pauk.denis@gmail.com> Cc: Bernhard Seibold <mail@bernhard-seibold.de> Reported-by: Paweł Marciniak <pmarciniak@lodz.home.pl> Tested-by: Denis Pauk <pauk.denis@gmail.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2021-12-27hwmon: (nct6775) Additional check for ChipID before ASUS WMI usageDenis Pauk
WMI monitoring methods can be changed or removed in new ASUS boards BIOS versions. Such versions return zero instead of a real one as Chip ID. Commit adds additional validation for the result of Chip ID call before enabling access by ASUS WMI methods. BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=204807 Signed-off-by: Denis Pauk <pauk.denis@gmail.com> Link: https://lore.kernel.org/r/20211218205206.615865-1-pauk.denis@gmail.com Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2021-12-27hwmon: (nct6775) add ROG STRIX B550-A/X570-I GAMINGDenis Pauk
ASUS ROG STRIX B550-A/X570-I GAMING boards have got an nct6775 chip, but by default there's no use of it because of resource conflict with WMI method. This commit adds "ROG STRIX B550-A GAMING" and "ROG STRIX X570-I GAMING" to the list of boards that can be monitored using ASUS WMI. BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=204807 Signed-off-by: Denis Pauk <pauk.denis@gmail.com> Tested-by: Daniel Gibson <metalcaedes@gmail.com> Tested-by: Michael Altizer <michael@theoddone.net> Tested-by: Mikhail Gavrilov <mikhail.v.gavrilov@gmail.com> Link: https://lore.kernel.org/r/20211211180037.367062-1-pauk.denis@gmail.com Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2021-12-27hwmon: (nct6775) delete some extension linesDan Carpenter
This code can fit on one line. No need to break it up. Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Link: https://lore.kernel.org/r/20211215114050.GB14967@kili Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2021-11-15hwmon: (nct6775) mask out bank number in nct6775_wmi_read_value()Zev Weiss
The first call to nct6775_asuswmi_read() in nct6775_wmi_read_value() had been passing the full bank+register number instead of just the lower 8 bits. It didn't end up actually causing problems because the second argument of that function is a u8 anyway, but it seems preferable to be explicit about it at the call site (and consistent with the rest of the code). Signed-off-by: Zev Weiss <zev@bewilderbeest.net> Fixes: 3fbbfc27f955 ("hwmon: (nct6775) Support access via Asus WMI") Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Link: https://lore.kernel.org/r/20211111025339.27520-1-zev@bewilderbeest.net Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2021-10-27hwmon: (nct6775) add ProArt X570-CREATOR WIFI.Denis Pauk
ASUS ProArt X570-CREATOR WIFI board has got an nct6775 chip, but by default there's no use of it because of resource conflict with WMI method. This commit adds ProArt X570-CREATOR WIFI to the list of boards that can be monitored using ASUS WMI. BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=204807 Signed-off-by: Denis Pauk <pauk.denis@gmail.com> Tested-by: Joel Wirāmu Pauling <jwp@redhat.com> Link: https://lore.kernel.org/r/20211025194748.6784-1-pauk.denis@gmail.com Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2021-10-12hwmon: (nct6775) add Pro WS X570-ACEOleksandr Natalenko
ASUS Pro WS X570-ACE board has got an nct6775 chip, but by default there's no use of it because of resource conflict: ``` ACPI Warning: SystemIO range 0x0000000000000295-0x0000000000000296 conflicts with OpRegion 0x0000000000000290-0x0000000000000299 (\AMW0.SHWM) (20210604/utaddress-204 ) ACPI: OSL: Resource conflict; ACPI support missing from driver? ACPI: OSL: Resource conflict: System may be unstable or behave erratically ``` A workaround is to use `acpi_enforce_resources=lax`, but a proper support needs to be added instead. This commit adds Pro WS X570-ACE to the list of boards that can be monitored using ASUS WMI. Tested by me on this hardware: ``` Base Board Information Manufacturer: ASUSTeK COMPUTER INC. Product Name: Pro WS X570-ACE BIOS Information Vendor: American Megatrends Inc. Version: 3801 Release Date: 07/30/2021 ``` Signed-off-by: Oleksandr Natalenko <oleksandr@natalenko.name> Link: https://lore.kernel.org/r/20211003133344.9036-2-oleksandr@natalenko.name Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2021-10-12hwmon: (nct6775) Add additional ASUS motherboards.Denis Pauk
Add support: * PRIME B360-PLUS * PRIME X570-PRO * ROG CROSSHAIR VIII FORMULA * ROG STRIX B550-I GAMING * ROG STRIX X570-F GAMING * ROG STRIX Z390-E GAMING * TUF GAMING B550-PRO * TUF GAMING Z490-PLUS * TUF GAMING Z490-PLUS (WI-FI) BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=204807 Signed-off-by: Denis Pauk <pauk.denis@gmail.com> Tested-by: matt-testalltheway <sefoci9222@rerunway.com> Tested-by: Kamil Dudka <kdudka@redhat.com> Tested-by: Robert Swiecki <robert@swiecki.net> Tested-by: Kamil Pietrzak <kpietrzak@disroot.org> Tested-by: Igor <igor@svelig.com> Tested-by: Tor Vic <torvic9@mailbox.org> Tested-by: Poezevara <nephartyz@gmail.com> Cc: Andy Shevchenko <andriy.shevchenko@intel.com> Cc: Guenter Roeck <linux@roeck-us.net> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Link: https://lore.kernel.org/r/20211002210857.709956-2-pauk.denis@gmail.com Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2021-10-12hwmon: (nct6775) Support access via Asus WMIDenis Pauk
Support accessing the NCT677x via Asus WMI functions. On mainboards that support this way of accessing the chip, the driver will usually not work without this option since in these mainboards, ACPI will mark the I/O port as used. Code uses ACPI firmware interface to communicate with sensors with ASUS motherboards: * PRIME B460-PLUS, * ROG CROSSHAIR VIII IMPACT, * ROG STRIX B550-E GAMING, * ROG STRIX B550-F GAMING, * ROG STRIX B550-F GAMING (WI-FI), * ROG STRIX Z490-I GAMING, * TUF GAMING B550M-PLUS, * TUF GAMING B550M-PLUS (WI-FI), * TUF GAMING B550-PLUS, * TUF GAMING X570-PLUS, * TUF GAMING X570-PRO (WI-FI). BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=204807 Signed-off-by: Denis Pauk <pauk.denis@gmail.com> Co-developed-by: Bernhard Seibold <mail@bernhard-seibold.de> Signed-off-by: Bernhard Seibold <mail@bernhard-seibold.de> Tested-by: Pär Ekholm <pehlm@pekholm.org> Tested-by: <to.eivind@gmail.com> Tested-by: Artem S. Tashkinov <aros@gmx.com> Tested-by: Vittorio Roberto Alfieri <me@rebtoor.com> Tested-by: Sahan Fernando <sahan.h.fernando@gmail.com> Cc: Andy Shevchenko <andriy.shevchenko@intel.com> Cc: Guenter Roeck <linux@roeck-us.net> Link: https://lore.kernel.org/r/20210917220240.56553-4-pauk.denis@gmail.com Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2021-10-12hwmon: (nct6775) Use nct6775_*() function pointers in nct6775_data.Denis Pauk
Prepare for platform specific callbacks usage: * Use nct6775 function pointers in struct nct6775_data instead direct calls. BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=204807 Signed-off-by: Denis Pauk <pauk.denis@gmail.com> Co-developed-by: Bernhard Seibold <mail@bernhard-seibold.de> Signed-off-by: Bernhard Seibold <mail@bernhard-seibold.de> Cc: Andy Shevchenko <andriy.shevchenko@intel.com> Cc: Guenter Roeck <linux@roeck-us.net> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Link: https://lore.kernel.org/r/20210917220240.56553-3-pauk.denis@gmail.com Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2021-10-12hwmon: (nct6775) Use superio_*() function pointers in sio_data.Denis Pauk
Prepare for platform specific callbacks usage: * Rearrange code for directly use struct nct6775_sio_data in superio_*() functions. * Use superio function pointers in nct6775_sio_data struct instead direct calls. BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=204807 Signed-off-by: Denis Pauk <pauk.denis@gmail.com> Co-developed-by: Bernhard Seibold <mail@bernhard-seibold.de> Signed-off-by: Bernhard Seibold <mail@bernhard-seibold.de> Cc: Andy Shevchenko <andriy.shevchenko@intel.com> Cc: Guenter Roeck <linux@roeck-us.net> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Link: https://lore.kernel.org/r/20210917220240.56553-2-pauk.denis@gmail.com Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2020-08-24treewide: Use fallthrough pseudo-keywordGustavo A. R. Silva
Replace the existing /* fall through */ comments and its variants with the new pseudo-keyword macro fallthrough[1]. Also, remove unnecessary fall-through markings when it is the case. [1] https://www.kernel.org/doc/html/v5.7/process/deprecated.html?highlight=fallthrough#implicit-switch-case-fall-through Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
2020-07-15hwmon: (nct6775) Accept PECI Calibration as temperature source for NCT6798DGuenter Roeck
Stefan Dietrich reports invalid temperature source messages on Asus Formula XII Z490. nct6775 nct6775.656: Invalid temperature source 28 at index 0, source register 0x100, temp register 0x73 Debugging suggests that temperature source 28 reports the CPU temperature. Let's assume that temperature sources 28 and 29 reflect "PECI Agent {0,1} Calibration", similar to other chips of the series. Reported-by: Stefan Dietrich <roots@gmx.de> Cc: Stefan Dietrich <roots@gmx.de> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2020-05-22hwmon : (nct6775) Use kobj_to_dev() APIzhouchuangao
Use kobj_to_dev() API instead of container_of(). Signed-off-by: zhouchuangao <zhouchuangao@xiaomi.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2019-09-03hwmon: (nct6775) Integrate new model nct6116Björn Gerhart
Add support for NCT6116D to nct6775 driver. Signed-off-by: Bjoern Gerhart <gerhart@posteo.de> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2019-07-22hwmon: (nct6775) Fix register address and added missed tolerance for nct6106Björn Gerhart
Fixed address of third NCT6106_REG_WEIGHT_DUTY_STEP, and added missed NCT6106_REG_TOLERANCE_H. Fixes: 6c009501ff200 ("hwmon: (nct6775) Add support for NCT6102D/6106D") Signed-off-by: Bjoern Gerhart <gerhart@posteo.de> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2019-05-24treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 61Thomas Gleixner
Based on 1 normalized pattern(s): this program is free software you can redistribute it and or modify it under the terms of the gnu general public license as published by the free software foundation either version 2 of the license or at your option any later version this program is distributed in the hope that it will be useful but without any warranty without even the implied warranty of merchantability or fitness for a particular purpose see the gnu general public license for more details you should have received a copy of the gnu general public license along with this program if not write to the free software foundation inc 675 mass ave cambridge ma 02139 usa extracted by the scancode license scanner the SPDX license identifier GPL-2.0-or-later has been chosen to replace the boilerplate/reference in 441 file(s). Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Michael Ellerman <mpe@ellerman.id.au> (powerpc) Reviewed-by: Richard Fontana <rfontana@redhat.com> Reviewed-by: Allison Randal <allison@lohutok.net> Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org> Cc: linux-spdx@vger.kernel.org Link: https://lkml.kernel.org/r/20190520071858.739733335@linutronix.de Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-01-28hwmon: (nct6775) Fix fan6 detection for NCT6793DGuenter Roeck
Commit 2d99925a15b6 ("hwmon: (nct6775) Separate fan/pwm configuration detection for NCT6793D") accidentally removed part of the code detecting if fan6 is enabled or not. As result, fan6 is no longer detected on Asus PRIME Z370-A. Restore the missing detection code. Fixes: 2d99925a15b6 ("hwmon: (nct6775) Separate fan/pwm configuration detection for NCT6793D") Reported-by: Chris Siebenmann <cks@cs.toronto.edu> Cc: Chris Siebenmann <cks@cs.toronto.edu> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2019-01-07hwmon: (nct6775) Enable IO mapping for NCT6797D and NCT6798DGuenter Roeck
Similar to other recent chips from Nuvoton, IO mapping may be disabled by default. Enable it when instantiating the driver and after resume. Fixes: 0599682b826f ("hwmon: (nct6775) Add support for NCT6798D") Fixes: e41da286a2fd ("hwmon: (nct6775) Add support for NCT6797D") Reported-by: Michael Cook <mcook@mackal.net> Cc: Michael Cook <mcook@mackal.net> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2019-01-07hwmon: (nct6775) Fix chip ID for NCT6798DGuenter Roeck
The chip ID is 0xd42[8-f], not 0xd45[8-f]. Fixes: 0599682b826f ("hwmon: (nct6775) Add support for NCT6798D") Reported-by: Michael Cook <mcook@mackal.net> Cc: Michael Cook <mcook@mackal.net> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-10-11hwmon: (nct6775) Add support for NCT6798DGuenter Roeck
NCT6798D is, with the exception of fan and pwm channel configuration registers, similar to other chips of the series. One interesting difference is the chip ID, which is now extended to 13 bit (the 12-bit chip ID value overlaps with the chip ID of NCT6797D). Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-10-11hwmon: (nct6775) Add support for NCT6797DGuenter Roeck
Add support for NCT6797D. With the exception of fan/pwm configuration registers, it is mostly compatible with NCT6795D. Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-10-11hwmon: (nct6775) Fix names of DIMM temperature sourcesGuenter Roeck
For NCT6795D and NCT6796D, the DIMM temperature sources are named "Agent[01] Dimm [01]" per datasheet. Match names in datasheets to avoid confusion. Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-10-11hwmon: (nct6796) Clean up and amend fan/pwm configuration for NCT6796DGuenter Roeck
Now that everything is separated, clean up fan and pwm configuration for NCT6796D. While doing that, take the forgotten configuration register cre0 into account to determine if AUXFANIN2 (fan5) and AUXFANOUT2 (pwm5) are connected. Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-10-11hwmon: (nct6775) Separate fan/pwm configuration detection for NCT6795DGuenter Roeck
Separate fan/pwm configuration detection for NCT6795D into separate case statement to make the code easier to read. No functional change. Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-10-11hwmon: (nct6775) Separate fan/pwm configuration detection for NCT6793DGuenter Roeck
While detecting the configuration for multiple chips in one go reduces code size, it also increases code complexity. Separate chip detection to improve code readability. As first step, separate detection for NCT6793D. No functional change. Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-10-11hwmon: (nct6775) Fix fan6/pwm6 detection for NCT6792DGuenter Roeck
Per datasheet, AUXFANIN3 (fan6) and AUXFANOUT3 (pwm6) are only connected if DSW_EN is false. Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-10-11hwmon: (nct6775) Improve instruction groupingGuenter Roeck
When determining support for a given fan or pwm control, the code is easier to read if the necessary instructions are grouped together. No functional change. Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-10-11hwmon: (nct6775) Use logical or instead of if statements where possibleGuenter Roeck
Use boolean |= <expression>; instead of if (!boolean) boolean = <expression>; to assign values to boolean variables. No functional change. Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-10-11hwmon: (nct6775) Declare and initialize LDN specific config variables earlierGuenter Roeck
Declare and initialize LDN / chip specific configuration variables earlier. This simplifies re-using the configuration variables for multiple chips and makes the code easier to read. Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-10-11hwmon: (nct6775) Move config variable declarations and initializationsGuenter Roeck
Group configuration variable declarations and initialization together. While this results in reading more registers than necessary for a given chip, it improves code readability and simplifies extending the code. Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-10-11hwmon: (nct6775) Replace 'regval' with variables named after config registersGuenter Roeck
Using variables named after configuration registers makes it more obvious which configuration register value is used, especially if more than one configuration register value is used to determine a configuration detail. No functional change. Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-10-11hwmon: (nct6775) Rename configuration register variablesGuenter Roeck
Use variable names from chip datasheets (crXX) instead of regval_XX for configuration register variables. This is shorter and, together with subsequent changes, makes the code easier to read. No functional change. Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-10-11hwmon: (nct6775) Only display fan speed tolerance conditionallyGuenter Roeck
A fan speed tolerance only makes sense if a fan target speed has been configured in the first place. Otherwise we get odd output such as fan1_target:0 fan1_tolerance:337500 Only display values other than 0 if a fan target speed has been configured. Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-10-11hwmon: (nct6775) Clean up a conditionDan Carpenter
I removed the "dsw_en &&" chunk of the condition because we know that "dsw_en" is set. Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-09-17hwmon: (nct6775) Use different register to get fan RPM for fan7Guenter Roeck
The documented register to retrieve the fan RPM for fan7 is found to be unreliable at least with NCT6796D revision 3. Let's use register 0x4ce instead. This is undocumented for NCT6796D, but documented for NCT6797D and NCT6798D and known to be working. Reported-by: Robert Kern <ulteq@web.de> Cc: Robert Kern <ulteq@web.de> Fixes: 81820059a428 ("hwmon: (nct6775) Add support for NCT6796D") Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-09-16hwmon: (nct6775) Fix RPM output for fan7 on NCT6796DGuenter Roeck
fan7 on NCT6796D does not have a fan count register; it only has an RPM register. Switch to using RPM registers to read the fan speed for all chips supporting it to solve the problem for good. Reported-by: Robert Kern <ulteq@web.de> Cc: Robert Kern <ulteq@web.de> Fixes: 81820059a428 ("hwmon: (nct6775) Add support for NCT6796D") Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-09-15hwmon: (nct6775) Fix virtual temperature sources for NCT6796DGuenter Roeck
The following kernel log message is reported for the nct6775 driver on ASUS WS X299 SAGE. nct6775: Found NCT6796D or compatible chip at 0x2e:0x290 nct6775 nct6775.656: Invalid temperature source 11 at index 0, source register 0x100, temp register 0x73 nct6775 nct6775.656: Invalid temperature source 11 at index 2, source register 0x300, temp register 0x77 nct6775 nct6775.656: Invalid temperature source 11 at index 3, source register 0x800, temp register 0x79 nct6775 nct6775.656: Invalid temperature source 11 at index 4, source register 0x900, temp register 0x7b A recent version of the datasheet lists temperature source 11 as reserved. However, an older version of the datasheet lists temperature sources 10 and 11 as supported virtual temperature sources. Apparently the older version of the datasheet is correct, so list those temperature sources as supported. Virtual temperature sources are different than other temperature sources: Values are not read from a temperature sensor, but written either from BIOS or an embedded controller. As such, each virtual temperature has to be reported. Since there is now more than one temperature source, we have to keep virtual temperature sources in a chip-specific mask and can no longer rely on the assumption that there is only one virtual temperature source with a fixed index. This accounts for most of the complexity of this patch. Reported-by: Robert Kern <ulteq@web.de> Cc: Robert Kern <ulteq@web.de> Fixes: 81820059a428 ("hwmon: (nct6775) Add support for NCT6796D") Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-09-07hwmon: (nct6775) Fix access to fan pulse registersGuenter Roeck
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>
2018-09-06hwmon: (nct6775) Set weight source to zero correctlyDan Carpenter
This is dead code because j can never be 1 at this point. We had intended to just test if the bit was clear. Fixes: bbd8decd4123 ("hwmon: (nct6775) Add support for weighted fan control") Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-08-27hwmon: (nct6775) Fix potential Spectre v1Gustavo A. R. Silva
val can be indirectly controlled by user-space, hence leading to a potential exploitation of the Spectre variant 1 vulnerability. This issue was detected with the help of Smatch: vers/hwmon/nct6775.c:2698 store_pwm_weight_temp_sel() warn: potential spectre issue 'data->temp_src' [r] Fix this by sanitizing val before using it to index data->temp_src Notice that given that speculation windows are large, the policy is to kill the speculation on the first load and not worry if it can be completed with a dependent load/store [1]. [1] https://marc.info/?l=linux-kernel&m=152449131114778&w=2 Cc: stable@vger.kernel.org Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-07-09hwmon: Mark expected switch fall-throughsGustavo A. R. Silva
In preparation to enabling -Wimplicit-fallthrough, mark switch cases where we are expecting to fall through. Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com> Reviewed-by: Jean Delvare <jdelvare@suse.de> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-07-09hwmon: (nct6775) Fix comment in the description of pwm_modeGuenter Roeck
Commit 415eb2a1aaa488 ("hwmon: (nct6775) Fix writing pwmX_mode") changed the definition of the pwm_mode variable, but did not update the comment describing it. Reported-by: Ben Hutchings <ben.hutchings@codethink.co.uk> Cc: Ben Hutchings <ben.hutchings@codethink.co.uk> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-06-17hwmon: (nct6775) Fix loop limitGuenter Roeck
Commit cc66b3038254 ("hwmon: (nct6775) Rework temperature source and label handling") changed a loop limit from "data->temp_label_num - 1" to "32", as part of moving from a string array to a bit mask. This results in the following error, reported by UBSAN. UBSAN: Undefined behaviour in drivers/hwmon/nct6775.c:4179:27 shift exponent 32 is too large for 32-bit type 'long unsigned int' Similar to the original loop, the limit has to be one less than the number of bits. Fixes: cc66b3038254 ("hwmon: (nct6775) Rework temperature source and label handling") Reported-by: Paul Menzel <pmenzel+linux-hwmon@molgen.mpg.de> Cc: Paul Menzel <pmenzel+linux-hwmon@molgen.mpg.de> Tested-by: Paul Menzel <pmenzel+linux-hwmon@molgen.mpg.de> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-06-13treewide: devm_kzalloc() -> devm_kcalloc()Kees Cook
The devm_kzalloc() function has a 2-factor argument form, devm_kcalloc(). This patch replaces cases of: devm_kzalloc(handle, a * b, gfp) with: devm_kcalloc(handle, a * b, gfp) as well as handling cases of: devm_kzalloc(handle, a * b * c, gfp) with: devm_kzalloc(handle, array3_size(a, b, c), gfp) as it's slightly less ugly than: devm_kcalloc(handle, array_size(a, b), c, gfp) This does, however, attempt to ignore constant size factors like: devm_kzalloc(handle, 4 * 1024, gfp) though any constants defined via macros get caught up in the conversion. Any factors with a sizeof() of "unsigned char", "char", and "u8" were dropped, since they're redundant. Some manual whitespace fixes were needed in this patch, as Coccinelle really liked to write "=devm_kcalloc..." instead of "= devm_kcalloc...". The Coccinelle script used for this was: // Fix redundant parens around sizeof(). @@ expression HANDLE; type TYPE; expression THING, E; @@ ( devm_kzalloc(HANDLE, - (sizeof(TYPE)) * E + sizeof(TYPE) * E , ...) | devm_kzalloc(HANDLE, - (sizeof(THING)) * E + sizeof(THING) * E , ...) ) // Drop single-byte sizes and redundant parens. @@ expression HANDLE; expression COUNT; typedef u8; typedef __u8; @@ ( devm_kzalloc(HANDLE, - sizeof(u8) * (COUNT) + COUNT , ...) | devm_kzalloc(HANDLE, - sizeof(__u8) * (COUNT) + COUNT , ...) | devm_kzalloc(HANDLE, - sizeof(char) * (COUNT) + COUNT , ...) | devm_kzalloc(HANDLE, - sizeof(unsigned char) * (COUNT) + COUNT , ...) | devm_kzalloc(HANDLE, - sizeof(u8) * COUNT + COUNT , ...) | devm_kzalloc(HANDLE, - sizeof(__u8) * COUNT + COUNT , ...) | devm_kzalloc(HANDLE, - sizeof(char) * COUNT + COUNT , ...) | devm_kzalloc(HANDLE, - sizeof(unsigned char) * COUNT + COUNT , ...) ) // 2-factor product with sizeof(type/expression) and identifier or constant. @@ expression HANDLE; type TYPE; expression THING; identifier COUNT_ID; constant COUNT_CONST; @@ ( - devm_kzalloc + devm_kcalloc (HANDLE, - sizeof(TYPE) * (COUNT_ID) + COUNT_ID, sizeof(TYPE) , ...) | - devm_kzalloc + devm_kcalloc (HANDLE, - sizeof(TYPE) * COUNT_ID + COUNT_ID, sizeof(TYPE) , ...) | - devm_kzalloc + devm_kcalloc (HANDLE, - sizeof(TYPE) * (COUNT_CONST) + COUNT_CONST, sizeof(TYPE) , ...) | - devm_kzalloc + devm_kcalloc (HANDLE, - sizeof(TYPE) * COUNT_CONST + COUNT_CONST, sizeof(TYPE) , ...) | - devm_kzalloc + devm_kcalloc (HANDLE, - sizeof(THING) * (COUNT_ID) + COUNT_ID, sizeof(THING) , ...) | - devm_kzalloc + devm_kcalloc (HANDLE, - sizeof(THING) * COUNT_ID + COUNT_ID, sizeof(THING) , ...) | - devm_kzalloc + devm_kcalloc (HANDLE, - sizeof(THING) * (COUNT_CONST) + COUNT_CONST, sizeof(THING) , ...) | - devm_kzalloc + devm_kcalloc (HANDLE, - sizeof(THING) * COUNT_CONST + COUNT_CONST, sizeof(THING) , ...) ) // 2-factor product, only identifiers. @@ expression HANDLE; identifier SIZE, COUNT; @@ - devm_kzalloc + devm_kcalloc (HANDLE, - SIZE * COUNT + COUNT, SIZE , ...) // 3-factor product with 1 sizeof(type) or sizeof(expression), with // redundant parens removed. @@ expression HANDLE; expression THING; identifier STRIDE, COUNT; type TYPE; @@ ( devm_kzalloc(HANDLE, - sizeof(TYPE) * (COUNT) * (STRIDE) + array3_size(COUNT, STRIDE, sizeof(TYPE)) , ...) | devm_kzalloc(HANDLE, - sizeof(TYPE) * (COUNT) * STRIDE + array3_size(COUNT, STRIDE, sizeof(TYPE)) , ...) | devm_kzalloc(HANDLE, - sizeof(TYPE) * COUNT * (STRIDE) + array3_size(COUNT, STRIDE, sizeof(TYPE)) , ...) | devm_kzalloc(HANDLE, - sizeof(TYPE) * COUNT * STRIDE + array3_size(COUNT, STRIDE, sizeof(TYPE)) , ...) | devm_kzalloc(HANDLE, - sizeof(THING) * (COUNT) * (STRIDE) + array3_size(COUNT, STRIDE, sizeof(THING)) , ...) | devm_kzalloc(HANDLE, - sizeof(THING) * (COUNT) * STRIDE + array3_size(COUNT, STRIDE, sizeof(THING)) , ...) | devm_kzalloc(HANDLE, - sizeof(THING) * COUNT * (STRIDE) + array3_size(COUNT, STRIDE, sizeof(THING)) , ...) | devm_kzalloc(HANDLE, - sizeof(THING) * COUNT * STRIDE + array3_size(COUNT, STRIDE, sizeof(THING)) , ...) ) // 3-factor product with 2 sizeof(variable), with redundant parens removed. @@ expression HANDLE; expression THING1, THING2; identifier COUNT; type TYPE1, TYPE2; @@ ( devm_kzalloc(HANDLE, - sizeof(TYPE1) * sizeof(TYPE2) * COUNT + array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2)) , ...) | devm_kzalloc(HANDLE, - sizeof(TYPE1) * sizeof(THING2) * (COUNT) + array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2)) , ...) | devm_kzalloc(HANDLE, - sizeof(THING1) * sizeof(THING2) * COUNT + array3_size(COUNT, sizeof(THING1), sizeof(THING2)) , ...) | devm_kzalloc(HANDLE, - sizeof(THING1) * sizeof(THING2) * (COUNT) + array3_size(COUNT, sizeof(THING1), sizeof(THING2)) , ...) | devm_kzalloc(HANDLE, - sizeof(TYPE1) * sizeof(THING2) * COUNT + array3_size(COUNT, sizeof(TYPE1), sizeof(THING2)) , ...) | devm_kzalloc(HANDLE, - sizeof(TYPE1) * sizeof(THING2) * (COUNT) + array3_size(COUNT, sizeof(TYPE1), sizeof(THING2)) , ...) ) // 3-factor product, only identifiers, with redundant parens removed. @@ expression HANDLE; identifier STRIDE, SIZE, COUNT; @@ ( devm_kzalloc(HANDLE, - (COUNT) * STRIDE * SIZE + array3_size(COUNT, STRIDE, SIZE) , ...) | devm_kzalloc(HANDLE, - COUNT * (STRIDE) * SIZE + array3_size(COUNT, STRIDE, SIZE) , ...) | devm_kzalloc(HANDLE, - COUNT * STRIDE * (SIZE) + array3_size(COUNT, STRIDE, SIZE) , ...) | devm_kzalloc(HANDLE, - (COUNT) * (STRIDE) * SIZE + array3_size(COUNT, STRIDE, SIZE) , ...) | devm_kzalloc(HANDLE, - COUNT * (STRIDE) * (SIZE) + array3_size(COUNT, STRIDE, SIZE) , ...) | devm_kzalloc(HANDLE, - (COUNT) * STRIDE * (SIZE) + array3_size(COUNT, STRIDE, SIZE) , ...) | devm_kzalloc(HANDLE, - (COUNT) * (STRIDE) * (SIZE) + array3_size(COUNT, STRIDE, SIZE) , ...) | devm_kzalloc(HANDLE, - COUNT * STRIDE * SIZE + array3_size(COUNT, STRIDE, SIZE) , ...) ) // Any remaining multi-factor products, first at least 3-factor products, // when they're not all constants... @@ expression HANDLE; expression E1, E2, E3; constant C1, C2, C3; @@ ( devm_kzalloc(HANDLE, C1 * C2 * C3, ...) | devm_kzalloc(HANDLE, - (E1) * E2 * E3 + array3_size(E1, E2, E3) , ...) | devm_kzalloc(HANDLE, - (E1) * (E2) * E3 + array3_size(E1, E2, E3) , ...) | devm_kzalloc(HANDLE, - (E1) * (E2) * (E3) + array3_size(E1, E2, E3) , ...) | devm_kzalloc(HANDLE, - E1 * E2 * E3 + array3_size(E1, E2, E3) , ...) ) // And then all remaining 2 factors products when they're not all constants, // keeping sizeof() as the second factor argument. @@ expression HANDLE; expression THING, E1, E2; type TYPE; constant C1, C2, C3; @@ ( devm_kzalloc(HANDLE, sizeof(THING) * C2, ...) | devm_kzalloc(HANDLE, sizeof(TYPE) * C2, ...) | devm_kzalloc(HANDLE, C1 * C2 * C3, ...) | devm_kzalloc(HANDLE, C1 * C2, ...) | - devm_kzalloc + devm_kcalloc (HANDLE, - sizeof(TYPE) * (E2) + E2, sizeof(TYPE) , ...) | - devm_kzalloc + devm_kcalloc (HANDLE, - sizeof(TYPE) * E2 + E2, sizeof(TYPE) , ...) | - devm_kzalloc + devm_kcalloc (HANDLE, - sizeof(THING) * (E2) + E2, sizeof(THING) , ...) | - devm_kzalloc + devm_kcalloc (HANDLE, - sizeof(THING) * E2 + E2, sizeof(THING) , ...) | - devm_kzalloc + devm_kcalloc (HANDLE, - (E1) * E2 + E1, E2 , ...) | - devm_kzalloc + devm_kcalloc (HANDLE, - (E1) * (E2) + E1, E2 , ...) | - devm_kzalloc + devm_kcalloc (HANDLE, - E1 * E2 + E1, E2 , ...) ) Signed-off-by: Kees Cook <keescook@chromium.org>
2018-03-27hwmon: (nct6775) Fix writing pwmX_modeGuenter Roeck
pwmX_mode is defined in the ABI as 0=DC mode, 1=pwm mode. The chip register bit is set to 1 for DC mode. This got mixed up, and writing 1 into pwmX_mode resulted in DC mode enabled. Fix it up by using the ABI definition throughout the driver for consistency. Fixes: 77eb5b3703d99 ("hwmon: (nct6775) Add support for pwm, pwm_mode, ... ") Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-03-11hwmon: (nct6775) Add support for NCT6796DGuenter Roeck
NCT6796D is mostly compatible to NCT6795D. It supports an additional pwm control and fan speed channel. While we are at it, update documentation for NCT6795D. Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-03-11hwmon: (nct6775) Initialize boolean variables with declarationGuenter Roeck
Initialize boolean flags in nct6775_check_fan_inputs() while declaring them instead of several times throughout the code. Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-03-11hwmon: (nct6775) Improve fan6/pwm6 supportGuenter Roeck
Improve fan6/pwm6 detection on NCT6795D. Add support for fan pulses for fans 4..6 and fan min limits for fan6. Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-03-11hwmon: (nct6775) Use NUM_FAN consistentlyGuenter Roeck
The size of some of the arrays using the number of fans is hardcoded. Use NUM_FAN consistently throughout the driver. Signed-off-by: Guenter Roeck <linux@roeck-us.net>