misc: nct1008: avoid reading bogus temperature
Diwakar Tundlam [Tue, 4 Mar 2014 02:11:34 +0000 (18:11 -0800)]
Added a check for temperature above max value and return error when
that happens to avoid showing insane temperature values to user. Bogus
temperature readout happens rarely due to the NCT device still being
initialized and unprepared while interrupts happen.

Based on commit 707c55d46a9c9f3780caa64426efa8220be11a1e which was
reviewed-on: http://git-master/r/376832

Bug 1454792

Change-Id: I7f31f80f47abc197e6dda3d661dfb82e946ea039
Signed-off-by: Diwakar Tundlam <dtundlam@nvidia.com>
Reviewed-on: http://git-master/r/392045
Reviewed-by: Automatic_Commit_Validation_User
GVS: Gerrit_Virtual_Submit
Reviewed-by: Matthew Pedro <mapedro@nvidia.com>

drivers/misc/nct1008.c

index f6cc442..e4fe1f7 100644 (file)
@@ -202,6 +202,9 @@ static int nct1008_ext_get_temp_common(struct nct1008_data *data,
        }
        temp_ext_milli += off;
 
+       if (temp_ext_milli > NCT1008_MAX_TEMP_MILLI)
+               return -1;
+
        *temp = temp_ext_milli;
        data->etemp = temp_ext_milli;