linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Chu Lin <linchuyuan@google.com>,
	Guenter Roeck <linux@roeck-us.net>,
	Sasha Levin <sashal@kernel.org>,
	linux-hwmon@vger.kernel.org
Subject: [PATCH AUTOSEL 5.4 20/34] hwmon: (adm1275) Make sure we are reading enough data for different chips
Date: Mon, 20 Jul 2020 17:37:53 -0400	[thread overview]
Message-ID: <20200720213807.407380-20-sashal@kernel.org> (raw)
In-Reply-To: <20200720213807.407380-1-sashal@kernel.org>

From: Chu Lin <linchuyuan@google.com>

[ Upstream commit 6d1d41c075a1a54ba03370e268171fec20e06563 ]

Issue:
When PEC is enabled, binding adm1272 to the adm1275 would
fail due to PEC error. See below:
adm1275: probe of xxxx failed with error -74

Diagnosis:
Per the datasheet of adm1272, adm1278, adm1293 and amd1294,
PMON_CONFIG (0xd4) is 16bits wide. On the other hand,
PMON_CONFIG (0xd4) for adm1275 is 8bits wide. The driver should not
assume everything is 8bits wide and read only 8bits from it.

Solution:
If it is adm1272, adm1278, adm1293 and adm1294, use i2c_read_word.
Else, use i2c_read_byte

Testing:
Binding adm1272 to the driver.
The change is only tested on adm1272.

Signed-off-by: Chu Lin <linchuyuan@google.com>
Link: https://lore.kernel.org/r/20200709040612.3977094-1-linchuyuan@google.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/hwmon/pmbus/adm1275.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/hwmon/pmbus/adm1275.c b/drivers/hwmon/pmbus/adm1275.c
index 5caa37fbfc187..66b12e5ccbc65 100644
--- a/drivers/hwmon/pmbus/adm1275.c
+++ b/drivers/hwmon/pmbus/adm1275.c
@@ -454,6 +454,7 @@ MODULE_DEVICE_TABLE(i2c, adm1275_id);
 static int adm1275_probe(struct i2c_client *client,
 			 const struct i2c_device_id *id)
 {
+	s32 (*config_read_fn)(const struct i2c_client *client, u8 reg);
 	u8 block_buffer[I2C_SMBUS_BLOCK_MAX + 1];
 	int config, device_config;
 	int ret;
@@ -499,11 +500,16 @@ static int adm1275_probe(struct i2c_client *client,
 			   "Device mismatch: Configured %s, detected %s\n",
 			   id->name, mid->name);
 
-	config = i2c_smbus_read_byte_data(client, ADM1275_PMON_CONFIG);
+	if (mid->driver_data == adm1272 || mid->driver_data == adm1278 ||
+	    mid->driver_data == adm1293 || mid->driver_data == adm1294)
+		config_read_fn = i2c_smbus_read_word_data;
+	else
+		config_read_fn = i2c_smbus_read_byte_data;
+	config = config_read_fn(client, ADM1275_PMON_CONFIG);
 	if (config < 0)
 		return config;
 
-	device_config = i2c_smbus_read_byte_data(client, ADM1275_DEVICE_CONFIG);
+	device_config = config_read_fn(client, ADM1275_DEVICE_CONFIG);
 	if (device_config < 0)
 		return device_config;
 
-- 
2.25.1


  parent reply	other threads:[~2020-07-20 21:43 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-20 21:37 [PATCH AUTOSEL 5.4 01/34] HID: i2c-hid: add Mediacom FlexBook edge13 to descriptor override Sasha Levin
2020-07-20 21:37 ` [PATCH AUTOSEL 5.4 02/34] HID: alps: support devices with report id 2 Sasha Levin
2020-07-20 21:37 ` [PATCH AUTOSEL 5.4 03/34] HID: steam: fixes race in handling device list Sasha Levin
2020-07-20 21:37 ` [PATCH AUTOSEL 5.4 04/34] HID: apple: Disable Fn-key key-re-mapping on clone keyboards Sasha Levin
2020-07-20 21:37 ` [PATCH AUTOSEL 5.4 05/34] dmaengine: tegra210-adma: Fix runtime PM imbalance on error Sasha Levin
2020-07-20 21:37 ` [PATCH AUTOSEL 5.4 06/34] Input: add `SW_MACHINE_COVER` Sasha Levin
2020-07-20 21:37 ` [PATCH AUTOSEL 5.4 07/34] ARM: dts: n900: remove mmc1 card detect gpio Sasha Levin
2020-07-20 21:37 ` [PATCH AUTOSEL 5.4 08/34] spi: mediatek: use correct SPI_CFG2_REG MACRO Sasha Levin
2020-07-20 21:37 ` [PATCH AUTOSEL 5.4 09/34] regmap: dev_get_regmap_match(): fix string comparison Sasha Levin
2020-07-20 21:37 ` [PATCH AUTOSEL 5.4 10/34] hwmon: (aspeed-pwm-tacho) Avoid possible buffer overflow Sasha Levin
2020-07-20 21:37 ` [PATCH AUTOSEL 5.4 11/34] dmaengine: fsl-edma: fix wrong tcd endianness for big-endian cpu Sasha Levin
2020-07-20 21:37 ` [PATCH AUTOSEL 5.4 12/34] dmaengine: ioat setting ioat timeout as module parameter Sasha Levin
2020-07-20 21:37 ` [PATCH AUTOSEL 5.4 13/34] Input: synaptics - enable InterTouch for ThinkPad X1E 1st gen Sasha Levin
2020-07-20 21:37 ` [PATCH AUTOSEL 5.4 14/34] Input: elan_i2c - only increment wakeup count on touch Sasha Levin
2020-07-20 21:37 ` [PATCH AUTOSEL 5.4 15/34] usb: dwc3: pci: add support for the Intel Tiger Lake PCH -H variant Sasha Levin
2020-07-20 21:37 ` [PATCH AUTOSEL 5.4 16/34] usb: dwc3: pci: add support for the Intel Jasper Lake Sasha Levin
2020-07-20 21:37 ` [PATCH AUTOSEL 5.4 17/34] usb: gadget: udc: gr_udc: fix memleak on error handling path in gr_ep_init() Sasha Levin
2020-07-20 21:37 ` [PATCH AUTOSEL 5.4 18/34] usb: cdns3: ep0: fix some endian issues Sasha Levin
2020-07-20 21:37 ` [PATCH AUTOSEL 5.4 19/34] usb: cdns3: trace: " Sasha Levin
2020-07-20 21:37 ` Sasha Levin [this message]
2020-07-20 21:37 ` [PATCH AUTOSEL 5.4 21/34] drm/amdgpu/gfx10: fix race condition for kiq Sasha Levin
2020-07-20 21:37 ` [PATCH AUTOSEL 5.4 22/34] drm/amdgpu: fix preemption unit test Sasha Levin
2020-07-20 21:37 ` [PATCH AUTOSEL 5.4 23/34] hwmon: (nct6775) Accept PECI Calibration as temperature source for NCT6798D Sasha Levin
2020-07-20 21:37 ` [PATCH AUTOSEL 5.4 24/34] platform/x86: ISST: Add new PCI device ids Sasha Levin
2020-07-20 21:37 ` [PATCH AUTOSEL 5.4 25/34] platform/x86: asus-wmi: allow BAT1 battery name Sasha Levin
2020-07-20 21:37 ` [PATCH AUTOSEL 5.4 26/34] hwmon: (scmi) Fix potential buffer overflow in scmi_hwmon_probe() Sasha Levin
2020-07-20 21:38 ` [PATCH AUTOSEL 5.4 27/34] ALSA: hda/realtek - fixup for yet another Intel reference board Sasha Levin
2020-07-20 21:38 ` [PATCH AUTOSEL 5.4 28/34] drivers/perf: Fix kernel panic when rmmod PMU modules during perf sampling Sasha Levin
2020-07-20 21:38 ` [PATCH AUTOSEL 5.4 29/34] arm64: Use test_tsk_thread_flag() for checking TIF_SINGLESTEP Sasha Levin
2020-07-20 21:38 ` [PATCH AUTOSEL 5.4 30/34] x86: math-emu: Fix up 'cmp' insn for clang ias Sasha Levin
2020-07-20 21:38 ` [PATCH AUTOSEL 5.4 31/34] asm-generic/mmiowb: Allow mmiowb_set_pending() when preemptible() Sasha Levin
2020-07-20 21:38 ` [PATCH AUTOSEL 5.4 32/34] drivers/perf: Prevent forced unbinding of PMU drivers Sasha Levin
2020-07-20 21:38 ` [PATCH AUTOSEL 5.4 33/34] RISC-V: Upgrade smp_mb__after_spinlock() to iorw,iorw Sasha Levin
2020-07-20 21:38 ` [PATCH AUTOSEL 5.4 34/34] SUNRPC reverting d03727b248d0 ("NFSv4 fix CLOSE not waiting for direct IO compeletion") 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=20200720213807.407380-20-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=linchuyuan@google.com \
    --cc=linux-hwmon@vger.kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).