Skip to contentSkip to conversation

comedi: drivers: ni_tio: Fix arithmetic expression overflow

PATCH In review Denis Arefev 2 participants 2 messages Jan 17, 2024 Comedi drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 comedi: drivers: ni_tio: Fix arithmetic expression overflow

The value of an arithmetic expression period_ns * 1000 is subject to overflow due to a failure to cast operands to a larger data type before performing arithmetic

Found by Linux Verification Center (linuxtesting.org) with SVACE.

---
 drivers/comedi/drivers/ni_tio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/comedi/drivers/ni_tio.c +1 -1
index da6826d77e60..acc914903c70 100644
@@ -800,7 +800,7 @@ static int ni_tio_set_clock_src(struct ni_gpct *counter,
 				GI_PRESCALE_X2(counter_dev->variant) |
 				GI_PRESCALE_X8(counter_dev->variant), bits);
 	}
-	counter->clock_period_ps = period_ns * 1000;
+	counter->clock_period_ps = period_ns * 1000UL;
 	ni_tio_set_sync_mode(counter);
 	return 0;
 }
Signature · 1 line
2.25.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 16 lines · Denis Arefev

The value of an arithmetic expression period_ns * 1000 is subject to overflow due to a failure to cast operands to a larger data type before performing arithmetic

Found by Linux Verification Center (linuxtesting.org) with SVACE.

---
  drivers/comedi/drivers/ni_tio.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/comedi/drivers/ni_tio.c +0 -0
index da6826d77e60..acc914903c70 100644

drivers/comedi/drivers/ni_tio.c static int ni_tio_set_clock_src(struct ni_gpct *counter, · line 806

Quoted 8 lines
drivers/comedi/drivers/ni_tio.c +1 -1
@@ -800,7 +800,7 @@ static int ni_tio_set_clock_src(struct ni_gpct *counter,
  				GI_PRESCALE_X2(counter_dev->variant) |
  				GI_PRESCALE_X8(counter_dev->variant), bits);
  	}
-	counter->clock_period_ps = period_ns * 1000;
+	counter->clock_period_ps = period_ns * 1000UL;
  	ni_tio_set_sync_mode(counter);
  	return 0;
  }

Looks good, thanks!

Could you resend it and Cc Greg Kroah-Hartman <[email protected]> ? It's more likely to get applied that way because I don't maintain my own kernel tree for comedi. Feel free to add my Reviewed-by line.

Signature · 4 lines
-=( Ian Abbott <[email protected]> || MEV Ltd. is a company  )=-
-=( registered in England & Wales.  Regd. number: 02862268.  )=-
-=( Regd. addr.: S11 & 12 Building 67, Europa Business Park, )=-
-=( Bird Hall Lane, STOCKPORT, SK3 0XA, UK. || www.mev.co.uk )=-