linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hwmon: (nct7904) Correct divide by 0
@ 2020-08-21 16:20 Jason Baron
  2020-08-21 18:27 ` Guenter Roeck
  0 siblings, 1 reply; 2+ messages in thread
From: Jason Baron @ 2020-08-21 16:20 UTC (permalink / raw)
  To: linux, jdelvare; +Cc: linux-hwmon, linux-kernel

We hit a kernel panic due to a divide by 0 in nct7904_read_fan() for
the hwmon_fan_min case. Extend the check to hwmon_fan_input case as well
for safety.

[ 1656.545650] divide error: 0000 [#1] SMP PTI
[ 1656.545779] CPU: 12 PID: 18010 Comm: sensors Not tainted 5.4.47 #1
[ 1656.546065] RIP: 0010:nct7904_read+0x1e9/0x510 [nct7904]
...
[ 1656.546549] RAX: 0000000000149970 RBX: ffffbd6b86bcbe08 RCX: 0000000000000000
...
[ 1656.547548] Call Trace:
[ 1656.547665]  hwmon_attr_show+0x32/0xd0 [hwmon]
[ 1656.547783]  dev_attr_show+0x18/0x50
[ 1656.547898]  sysfs_kf_seq_show+0x99/0x120
[ 1656.548013]  seq_read+0xd8/0x3e0
[ 1656.548127]  vfs_read+0x89/0x130
[ 1656.548234]  ksys_read+0x7d/0xb0
[ 1656.548342]  do_syscall_64+0x48/0x110
[ 1656.548451]  entry_SYSCALL_64_after_hwframe+0x44/0xa9

Signed-off-by: Jason Baron <jbaron@akamai.com>
---
 drivers/hwmon/nct7904.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/hwmon/nct7904.c b/drivers/hwmon/nct7904.c
index b042569..242ff8b 100644
--- a/drivers/hwmon/nct7904.c
+++ b/drivers/hwmon/nct7904.c
@@ -231,7 +231,7 @@ static int nct7904_read_fan(struct device *dev, u32 attr, int channel,
 		if (ret < 0)
 			return ret;
 		cnt = ((ret & 0xff00) >> 3) | (ret & 0x1f);
-		if (cnt == 0x1fff)
+		if (cnt == 0 || cnt == 0x1fff)
 			rpm = 0;
 		else
 			rpm = 1350000 / cnt;
@@ -243,7 +243,7 @@ static int nct7904_read_fan(struct device *dev, u32 attr, int channel,
 		if (ret < 0)
 			return ret;
 		cnt = ((ret & 0xff00) >> 3) | (ret & 0x1f);
-		if (cnt == 0x1fff)
+		if (cnt == 0 || cnt == 0x1fff)
 			rpm = 0;
 		else
 			rpm = 1350000 / cnt;
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] hwmon: (nct7904) Correct divide by 0
  2020-08-21 16:20 [PATCH] hwmon: (nct7904) Correct divide by 0 Jason Baron
@ 2020-08-21 18:27 ` Guenter Roeck
  0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2020-08-21 18:27 UTC (permalink / raw)
  To: Jason Baron; +Cc: jdelvare, linux-hwmon, linux-kernel

On Fri, Aug 21, 2020 at 12:20:14PM -0400, Jason Baron wrote:
> We hit a kernel panic due to a divide by 0 in nct7904_read_fan() for
> the hwmon_fan_min case. Extend the check to hwmon_fan_input case as well
> for safety.
> 
> [ 1656.545650] divide error: 0000 [#1] SMP PTI
> [ 1656.545779] CPU: 12 PID: 18010 Comm: sensors Not tainted 5.4.47 #1
> [ 1656.546065] RIP: 0010:nct7904_read+0x1e9/0x510 [nct7904]
> ...
> [ 1656.546549] RAX: 0000000000149970 RBX: ffffbd6b86bcbe08 RCX: 0000000000000000
> ...
> [ 1656.547548] Call Trace:
> [ 1656.547665]  hwmon_attr_show+0x32/0xd0 [hwmon]
> [ 1656.547783]  dev_attr_show+0x18/0x50
> [ 1656.547898]  sysfs_kf_seq_show+0x99/0x120
> [ 1656.548013]  seq_read+0xd8/0x3e0
> [ 1656.548127]  vfs_read+0x89/0x130
> [ 1656.548234]  ksys_read+0x7d/0xb0
> [ 1656.548342]  do_syscall_64+0x48/0x110
> [ 1656.548451]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
> 
> Signed-off-by: Jason Baron <jbaron@akamai.com>

Applied.

Thanks,
Guenter

> ---
>  drivers/hwmon/nct7904.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/hwmon/nct7904.c b/drivers/hwmon/nct7904.c
> index b042569..242ff8b 100644
> --- a/drivers/hwmon/nct7904.c
> +++ b/drivers/hwmon/nct7904.c
> @@ -231,7 +231,7 @@ static int nct7904_read_fan(struct device *dev, u32 attr, int channel,
>  		if (ret < 0)
>  			return ret;
>  		cnt = ((ret & 0xff00) >> 3) | (ret & 0x1f);
> -		if (cnt == 0x1fff)
> +		if (cnt == 0 || cnt == 0x1fff)
>  			rpm = 0;
>  		else
>  			rpm = 1350000 / cnt;
> @@ -243,7 +243,7 @@ static int nct7904_read_fan(struct device *dev, u32 attr, int channel,
>  		if (ret < 0)
>  			return ret;
>  		cnt = ((ret & 0xff00) >> 3) | (ret & 0x1f);
> -		if (cnt == 0x1fff)
> +		if (cnt == 0 || cnt == 0x1fff)
>  			rpm = 0;
>  		else
>  			rpm = 1350000 / cnt;

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-08-21 18:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-21 16:20 [PATCH] hwmon: (nct7904) Correct divide by 0 Jason Baron
2020-08-21 18:27 ` Guenter Roeck

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).