mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ben Hutchings <ben@decadent.org.uk>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: akpm@linux-foundation.org, "Guenter Roeck" <linux@roeck-us.net>,
	"Jean Delvare" <khali@linux-fr.org>
Subject: [63/83] hwmon: (adm1021) Strengthen chip detection for ADM1021, LM84 and MAX1617
Date: Sun, 16 Jun 2013 23:01:38 +0100	[thread overview]
Message-ID: <lsq.1371420098.848835385@decadent.org.uk> (raw)
In-Reply-To: <lsq.1371420097.958132574@decadent.org.uk>

3.2.47-rc1 review patch.  If anyone has any objections, please let me know.

------------------

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

commit 591bfcfc334a003ba31c0deff03b22e73349939b upstream.

On a system with both MAX1617 and JC42 sensors, JC42 sensors can be misdetected
as LM84. Strengthen detection sufficiently enough to avoid this misdetection.
Also improve detection for ADM1021.

Modeled after chip detection code in sensors-detect command.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Tested-by: Jean Delvare <khali@linux-fr.org>
Acked-by: Jean Delvare <khali@linux-fr.org>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
 drivers/hwmon/adm1021.c |   58 ++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 50 insertions(+), 8 deletions(-)

--- a/drivers/hwmon/adm1021.c
+++ b/drivers/hwmon/adm1021.c
@@ -311,26 +311,68 @@ static int adm1021_detect(struct i2c_cli
 	man_id = i2c_smbus_read_byte_data(client, ADM1021_REG_MAN_ID);
 	dev_id = i2c_smbus_read_byte_data(client, ADM1021_REG_DEV_ID);
 
+	if (man_id < 0 || dev_id < 0)
+		return -ENODEV;
+
 	if (man_id == 0x4d && dev_id == 0x01)
 		type_name = "max1617a";
 	else if (man_id == 0x41) {
 		if ((dev_id & 0xF0) == 0x30)
 			type_name = "adm1023";
-		else
+		else if ((dev_id & 0xF0) == 0x00)
 			type_name = "adm1021";
+		else
+			return -ENODEV;
 	} else if (man_id == 0x49)
 		type_name = "thmc10";
 	else if (man_id == 0x23)
 		type_name = "gl523sm";
 	else if (man_id == 0x54)
 		type_name = "mc1066";
-	/* LM84 Mfr ID in a different place, and it has more unused bits */
-	else if (conv_rate == 0x00
-		 && (config & 0x7F) == 0x00
-		 && (status & 0xAB) == 0x00)
-		type_name = "lm84";
-	else
-		type_name = "max1617";
+	else {
+		int lte, rte, lhi, rhi, llo, rlo;
+
+		/* extra checks for LM84 and MAX1617 to avoid misdetections */
+
+		llo = i2c_smbus_read_byte_data(client, ADM1021_REG_THYST_R(0));
+		rlo = i2c_smbus_read_byte_data(client, ADM1021_REG_THYST_R(1));
+
+		/* fail if any of the additional register reads failed */
+		if (llo < 0 || rlo < 0)
+			return -ENODEV;
+
+		lte = i2c_smbus_read_byte_data(client, ADM1021_REG_TEMP(0));
+		rte = i2c_smbus_read_byte_data(client, ADM1021_REG_TEMP(1));
+		lhi = i2c_smbus_read_byte_data(client, ADM1021_REG_TOS_R(0));
+		rhi = i2c_smbus_read_byte_data(client, ADM1021_REG_TOS_R(1));
+
+		/*
+		 * Fail for negative temperatures and negative high limits.
+		 * This check also catches read errors on the tested registers.
+		 */
+		if ((s8)lte < 0 || (s8)rte < 0 || (s8)lhi < 0 || (s8)rhi < 0)
+			return -ENODEV;
+
+		/* fail if all registers hold the same value */
+		if (lte == rte && lte == lhi && lte == rhi && lte == llo
+		    && lte == rlo)
+			return -ENODEV;
+
+		/*
+		 * LM84 Mfr ID is in a different place,
+		 * and it has more unused bits.
+		 */
+		if (conv_rate == 0x00
+		    && (config & 0x7F) == 0x00
+		    && (status & 0xAB) == 0x00) {
+			type_name = "lm84";
+		} else {
+			/* fail if low limits are larger than high limits */
+			if ((s8)llo > lhi || (s8)rlo > rhi)
+				return -ENODEV;
+			type_name = "max1617";
+		}
+	}
 
 	pr_debug("adm1021: Detected chip %s at adapter %d, address 0x%02x.\n",
 		 type_name, i2c_adapter_id(adapter), client->addr);


  parent reply	other threads:[~2013-06-16 22:16 UTC|newest]

Thread overview: 88+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-16 22:01 [00/83] 3.2.47-rc1 review Ben Hutchings
2013-06-16 22:01 ` [16/83] netback: remove redundant assignment Ben Hutchings
2013-06-16 22:01 ` [26/83] xen/events: Handle VIRQ_TIMER before any other hardirq in event loop Ben Hutchings
2013-06-16 22:01 ` [27/83] b43legacy: Fix crash on unload when firmware not available Ben Hutchings
2013-06-16 22:01 ` [30/83] ftrace: Move ftrace_filter_lseek out of CONFIG_DYNAMIC_FTRACE section Ben Hutchings
2013-06-16 22:01 ` [29/83] thinkpad-acpi: recognize latest V-Series using DMI_BIOS_VENDOR Ben Hutchings
2013-06-16 22:01 ` [24/83] xen-netfront: reduce gso_max_size to account for max TCP header Ben Hutchings
2013-06-16 22:01 ` [11/83] tg3: Add New 5719 Read DMA workaround Ben Hutchings
2013-06-16 22:01 ` [23/83] net: Add net_ratelimited_function and net_<level>_ratelimited macros Ben Hutchings
2013-06-16 22:01 ` [18/83] xen-netback: coalesce slots in TX path and fix regressions Ben Hutchings
2013-06-16 22:01 ` [20/83] xen-netback: remove redundent parameter in netbk_count_requests Ben Hutchings
2013-06-16 22:01 ` [15/83] xen-netback: remove skb in xen_netbk_alloc_page Ben Hutchings
2013-06-16 22:01 ` [03/83] libata: make ata_exec_internal_sg honor DMADIR Ben Hutchings
2013-06-16 22:01 ` [05/83] cifs: fix potential buffer overrun when composing a new options string Ben Hutchings
2013-06-16 22:01 ` [19/83] xen-netback: don't disconnect frontend when seeing oversize packet Ben Hutchings
2013-06-16 22:01 ` [09/83] xfs: kill suid/sgid through the truncate path Ben Hutchings
2013-06-16 22:01 ` [17/83] xen-netback: fix sparse warning Ben Hutchings
2013-06-16 22:01 ` [04/83] cfg80211: check wdev->netdev in connection work Ben Hutchings
2013-06-16 22:01 ` [10/83] iscsi-target: fix heap buffer overflow on error Ben Hutchings
2013-06-16 22:01 ` [08/83] drm/radeon: fix card_posted check for newer asics Ben Hutchings
2013-06-16 22:01 ` [07/83] iwlwifi: dvm: fix zero LQ CMD sending avoidance Ben Hutchings
2013-06-16 22:01 ` [13/83] ALSA: usb-audio: fix possible hang and overflow in parse_uac2_sample_rate_range() Ben Hutchings
2013-06-16 22:01 ` [01/83] rapidio/tsi721: Fix interrupt mask when handling MSI Ben Hutchings
2013-06-16 22:01 ` [22/83] xen-netback: better names for thresholds Ben Hutchings
2013-06-16 22:01 ` [28/83] ext4: lock i_mutex when truncating orphan inodes Ben Hutchings
2013-06-17 10:18   ` Luis Henriques
2013-06-16 22:01 ` [21/83] xen-netback: avoid allocating variable size array on stack Ben Hutchings
2013-06-16 22:01 ` [02/83] ata_piix: add PCI IDs for Intel BayTail Ben Hutchings
2013-06-16 22:01 ` [14/83] ALSA: usb-audio: avoid integer overflow in create_fixed_stream_quirk() Ben Hutchings
2013-06-16 22:01 ` [06/83] mac80211: close AP_VLAN interfaces before unregistering all Ben Hutchings
2013-06-16 22:01 ` [12/83] tg3: Add read dma workaround for 5720 Ben Hutchings
2013-06-16 22:01 ` [25/83] jfs: fix a couple races Ben Hutchings
2013-06-16 22:01 ` [82/83] tg3: Wait for boot code to finish after power on Ben Hutchings
2013-06-16 22:01 ` [33/83] drm/gma500: Increase max resolution for mode setting Ben Hutchings
2013-06-16 22:01 ` [57/83] USB: mos7720: fix hardware flow control Ben Hutchings
2013-06-16 22:01 ` [47/83] ACPI / video: ignore BIOS initial backlight value for HP m4 Ben Hutchings
2013-06-16 22:01 ` [39/83] USB: serial: fix Treo/Kyocera interrrupt-in urb context Ben Hutchings
2013-06-16 22:01 ` [59/83] ARM: 7742/1: topology: export cpu_topology Ben Hutchings
2013-06-16 22:01 ` [42/83] USB: ark3116: fix control-message timeout Ben Hutchings
2013-06-16 22:01 ` [61/83] USB: whiteheat: fix broken port configuration Ben Hutchings
2013-06-16 22:01 ` [81/83] md/raid1: consider WRITE as successful only if at least one non-Faulty and non-rebuilding drive completed it Ben Hutchings
2013-06-16 22:01 ` [75/83] drivers/rtc/rtc-twl.c: fix missing device_init_wakeup() when booted with device tree Ben Hutchings
2013-06-16 22:01 ` [38/83] USB: revert periodic scheduling bugfix Ben Hutchings
2013-06-16 22:01 ` [69/83] ath9k: Use minstrel rate control by default Ben Hutchings
2013-06-16 22:01 ` [79/83] USB: pl2303: fix device initialisation at open Ben Hutchings
2013-06-16 22:01 ` [83/83] powerpc: Fix emulation of illegal instructions on PowerNV platform Ben Hutchings
2013-06-16 22:01 ` [54/83] ALSA: usb-audio - Apply Logitech QuickCam Pro 9000 quirk only to audio iface Ben Hutchings
2013-06-16 22:01 ` [67/83] Bluetooth: Fix missing length checks for L2CAP signalling PDUs Ben Hutchings
2013-06-16 22:01 ` [72/83] reboot: rigrate shutdown/reboot to boot cpu Ben Hutchings
2013-06-16 22:01 ` [70/83] b43: stop format string leaking into error msgs Ben Hutchings
2013-06-16 22:01 ` [76/83] swap: avoid read_swap_cache_async() race to deadlock while waiting on discard I/O completion Ben Hutchings
2013-06-16 22:01 ` [41/83] USB: mos7720: fix DMA to stack Ben Hutchings
2013-06-16 22:01 ` [77/83] mm: migration: add migrate_entry_wait_huge() Ben Hutchings
2013-06-16 22:01 ` [56/83] USB: keyspan: fix bogus array index Ben Hutchings
2013-06-16 22:01 ` [55/83] drm/i915/sdvo: Use &intel_sdvo->ddc instead of intel_sdvo->i2c for DDC Ben Hutchings
2013-06-16 22:01 ` [73/83] audit: wait_for_auditd() should use TASK_UNINTERRUPTIBLE Ben Hutchings
2013-06-16 22:01 ` [68/83] ath9k: Disable PowerSave by default Ben Hutchings
2013-06-17  9:55   ` Luis Henriques
2013-06-17 11:55     ` Ben Hutchings
2013-06-16 22:01 ` [35/83] xhci: fix list access before init Ben Hutchings
2013-06-16 22:01 ` [31/83] USB: serial: ftdi_sio: Handle the old_termios == 0 case e.g. uart_resume_port() Ben Hutchings
2013-06-16 22:01 ` [66/83] drm/i915: prefer VBT modes for SVDO-LVDS over EDID Ben Hutchings
2013-06-16 22:01 ` [58/83] ALSA: usb-audio - Fix invalid volume resolution on Logitech HD webcam c270 Ben Hutchings
2013-06-16 22:01 ` [60/83] ARM: 7743/1: compressed/head.S: work around new binutils warning Ben Hutchings
2013-06-16 22:01 ` [32/83] USB: ftdi_sio: Quiet sparse noise about using plain integer was NULL pointer Ben Hutchings
2013-06-16 22:01 ` [50/83] drm/i915: no lvds quirk for hp t5740 Ben Hutchings
2013-06-16 22:01 ` [43/83] USB: iuu_phoenix: fix bulk-message timeout Ben Hutchings
2013-06-16 22:01 ` [71/83] CPU hotplug: provide a generic helper to disable/enable CPU hotplug Ben Hutchings
2013-06-16 22:01 ` [51/83] radeon: Fix system hang issue when using KMS with older cards Ben Hutchings
2013-06-16 22:01 ` [48/83] ACPI / video: ignore BIOS initial backlight value for HP Pavilion g6 Ben Hutchings
2013-06-16 22:01 ` Ben Hutchings [this message]
2013-06-16 22:01 ` [37/83] usb: dwc3: gadget: free trb pool only from epnum 2 Ben Hutchings
2013-06-16 22:01 ` [80/83] x86: Fix typo in kexec register clearing Ben Hutchings
2013-06-16 22:01 ` [78/83] USB: spcp8x5: fix device initialisation at open Ben Hutchings
2013-06-16 22:01 ` [52/83] USB: Serial: cypress_M8: Enable FRWD Dongle hidcom device Ben Hutchings
2013-06-16 22:01 ` [74/83] cciss: fix broken mutex usage in ioctl Ben Hutchings
2013-06-16 22:01 ` [49/83] drm: fix a use-after-free when GPU acceleration disabled Ben Hutchings
2013-06-16 22:01 ` [62/83] USB: option: blacklist network interface on Huawei E1820 Ben Hutchings
2013-06-16 22:01 ` [64/83] drm/gma500/psb: Unpin framebuffer on crtc disable Ben Hutchings
2013-06-16 22:01 ` [34/83] xhci-mem: init list heads at the beginning of init Ben Hutchings
2013-06-16 22:01 ` [46/83] ACPI video: ignore BIOS initial backlight value for HP 1000 Ben Hutchings
2013-06-16 22:01 ` [65/83] drm/gma500/cdv: Unpin framebuffer on crtc disable Ben Hutchings
2013-06-16 22:01 ` [45/83] ACPI video: ignore BIOS backlight value for HP dm4 Ben Hutchings
2013-06-16 22:01 ` [40/83] USB: visor: fix initialisation of Treo/Kyocera devices Ben Hutchings
2013-06-16 22:01 ` [44/83] USB: mos7720: fix message timeouts Ben Hutchings
2013-06-16 22:01 ` [36/83] xhci - correct comp_mode_recovery_timer on return from hibernate Ben Hutchings
2013-06-16 22:01 ` [53/83] USB: serial: Add Option GTM681W to qcserial device table Ben Hutchings
2013-06-16 22:42 ` [00/83] 3.2.47-rc1 review Ben Hutchings

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=lsq.1371420098.848835385@decadent.org.uk \
    --to=ben@decadent.org.uk \
    --cc=akpm@linux-foundation.org \
    --cc=khali@linux-fr.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

all inboxes | Powered by JetHome®