Skip to contentSkip to conversation

staging: media: msi3101: sdr-msi3101.c - replace with time_before_eq()

PATCH In review Anil Belur 2 participants 3 messages Jun 29, 2014 – Jun 30, 2014

Subsystems (2)
lore
Share & tools
lore

Anil Belur

author
#0 lore raw

PATCH 1/1 staging: media: msi3101: sdr-msi3101.c - replace with time_before_eq()

From: Anil Belur <[email protected]>

- this fix replaces jiffies interval comparision with safer function to avoid any overflow and wrap around ?

---
 drivers/staging/media/msi3101/sdr-msi3101.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
drivers/staging/media/msi3101/sdr-msi3101.c +12 -4
index 08d0d09..b828857 100644
@@ -180,6 +180,7 @@ static int msi3101_convert_stream_504(struct msi3101_state *s, u8 *dst,
 {
 	int i, i_max, dst_len = 0;
 	u32 sample_num[3];
+	unsigned long expires;
 
 	/* There could be 1-3 1024 bytes URB frames */
 	i_max = src_len / 1024;
@@ -208,7 +209,8 @@ static int msi3101_convert_stream_504(struct msi3101_state *s, u8 *dst,
 	}
 
 	/* calculate samping rate and output it in 10 seconds intervals */
-	if ((s->jiffies_next + msecs_to_jiffies(10000)) <= jiffies) {
+	expires = s->jiffies_next + msecs_to_jiffies(10000);
+	if (time_before_eq(expires, jiffies)) {
 		unsigned long jiffies_now = jiffies;
 		unsigned long msecs = jiffies_to_msecs(jiffies_now) - jiffies_to_msecs(s->jiffies_next);
 		unsigned int samples = sample_num[i_max - 1] - s->sample;
@@ -332,6 +334,7 @@ static int msi3101_convert_stream_384(struct msi3101_state *s, u8 *dst,
 {
 	int i, i_max, dst_len = 0;
 	u32 sample_num[3];
+	unsigned long expires;
 
 	/* There could be 1-3 1024 bytes URB frames */
 	i_max = src_len / 1024;
@@ -360,7 +363,8 @@ static int msi3101_convert_stream_384(struct msi3101_state *s, u8 *dst,
 	}
 
 	/* calculate samping rate and output it in 10 seconds intervals */
-	if ((s->jiffies_next + msecs_to_jiffies(10000)) <= jiffies) {
+	expires = s->jiffies_next + msecs_to_jiffies(10000);
+	if (time_before_eq(expires, jiffies)) {
 		unsigned long jiffies_now = jiffies;
 		unsigned long msecs = jiffies_to_msecs(jiffies_now) - jiffies_to_msecs(s->jiffies_next);
 		unsigned int samples = sample_num[i_max - 1] - s->sample;
@@ -397,6 +401,7 @@ static int msi3101_convert_stream_336(struct msi3101_state *s, u8 *dst,
 {
 	int i, i_max, dst_len = 0;
 	u32 sample_num[3];
+	unsigned long expires;
 
 	/* There could be 1-3 1024 bytes URB frames */
 	i_max = src_len / 1024;
@@ -425,7 +430,8 @@ static int msi3101_convert_stream_336(struct msi3101_state *s, u8 *dst,
 	}
 
 	/* calculate samping rate and output it in 10 seconds intervals */
-	if ((s->jiffies_next + msecs_to_jiffies(10000)) <= jiffies) {
+	expires = s->jiffies_next + msecs_to_jiffies(10000);
+	if (time_before_eq(expires, jiffies)) {
 		unsigned long jiffies_now = jiffies;
 		unsigned long msecs = jiffies_to_msecs(jiffies_now) - jiffies_to_msecs(s->jiffies_next);
 		unsigned int samples = sample_num[i_max - 1] - s->sample;
@@ -460,6 +466,7 @@ static int msi3101_convert_stream_252(struct msi3101_state *s, u8 *dst,
 {
 	int i, i_max, dst_len = 0;
 	u32 sample_num[3];
+	unsigned long expires;
 
 	/* There could be 1-3 1024 bytes URB frames */
 	i_max = src_len / 1024;
@@ -488,7 +495,8 @@ static int msi3101_convert_stream_252(struct msi3101_state *s, u8 *dst,
 	}
 
 	/* calculate samping rate and output it in 10 seconds intervals */
-	if ((s->jiffies_next + msecs_to_jiffies(10000)) <= jiffies) {
+	expires = s->jiffies_next + msecs_to_jiffies(10000);
+	if (time_before_eq(expires, jiffies)) {
 		unsigned long jiffies_now = jiffies;
 		unsigned long msecs = jiffies_to_msecs(jiffies_now) - jiffies_to_msecs(s->jiffies_next);
 		unsigned int samples = sample_num[i_max - 1] - s->sample;
Signature · 1 line
1.9.1
#1 lore raw

Moikka!
That is already fixed by someone else and patch is somewhere Mauro or Hans queue.

regards
Antti

Quoted 87 lines · Anil Belur

From: Anil Belur <[email protected]>

- this fix replaces jiffies interval comparision with safer function to avoid any overflow and wrap around ?

---
  drivers/staging/media/msi3101/sdr-msi3101.c | 16 ++++++++++++----
  1 file changed, 12 insertions(+), 4 deletions(-)
drivers/staging/media/msi3101/sdr-msi3101.c +12 -4
index 08d0d09..b828857 100644
@@ -180,6 +180,7 @@ static int msi3101_convert_stream_504(struct msi3101_state *s, u8 *dst,
  {
  	int i, i_max, dst_len = 0;
  	u32 sample_num[3];
+	unsigned long expires;
 
  	/* There could be 1-3 1024 bytes URB frames */
  	i_max = src_len / 1024;
@@ -208,7 +209,8 @@ static int msi3101_convert_stream_504(struct msi3101_state *s, u8 *dst,
  	}
 
  	/* calculate samping rate and output it in 10 seconds intervals */
-	if ((s->jiffies_next + msecs_to_jiffies(10000)) <= jiffies) {
+	expires = s->jiffies_next + msecs_to_jiffies(10000);
+	if (time_before_eq(expires, jiffies)) {
  		unsigned long jiffies_now = jiffies;
  		unsigned long msecs = jiffies_to_msecs(jiffies_now) - jiffies_to_msecs(s->jiffies_next);
  		unsigned int samples = sample_num[i_max - 1] - s->sample;
@@ -332,6 +334,7 @@ static int msi3101_convert_stream_384(struct msi3101_state *s, u8 *dst,
  {
  	int i, i_max, dst_len = 0;
  	u32 sample_num[3];
+	unsigned long expires;
 
  	/* There could be 1-3 1024 bytes URB frames */
  	i_max = src_len / 1024;
@@ -360,7 +363,8 @@ static int msi3101_convert_stream_384(struct msi3101_state *s, u8 *dst,
  	}
 
  	/* calculate samping rate and output it in 10 seconds intervals */
-	if ((s->jiffies_next + msecs_to_jiffies(10000)) <= jiffies) {
+	expires = s->jiffies_next + msecs_to_jiffies(10000);
+	if (time_before_eq(expires, jiffies)) {
  		unsigned long jiffies_now = jiffies;
  		unsigned long msecs = jiffies_to_msecs(jiffies_now) - jiffies_to_msecs(s->jiffies_next);
  		unsigned int samples = sample_num[i_max - 1] - s->sample;
@@ -397,6 +401,7 @@ static int msi3101_convert_stream_336(struct msi3101_state *s, u8 *dst,
  {
  	int i, i_max, dst_len = 0;
  	u32 sample_num[3];
+	unsigned long expires;
 
  	/* There could be 1-3 1024 bytes URB frames */
  	i_max = src_len / 1024;
@@ -425,7 +430,8 @@ static int msi3101_convert_stream_336(struct msi3101_state *s, u8 *dst,
  	}
 
  	/* calculate samping rate and output it in 10 seconds intervals */
-	if ((s->jiffies_next + msecs_to_jiffies(10000)) <= jiffies) {
+	expires = s->jiffies_next + msecs_to_jiffies(10000);
+	if (time_before_eq(expires, jiffies)) {
  		unsigned long jiffies_now = jiffies;
  		unsigned long msecs = jiffies_to_msecs(jiffies_now) - jiffies_to_msecs(s->jiffies_next);
  		unsigned int samples = sample_num[i_max - 1] - s->sample;
@@ -460,6 +466,7 @@ static int msi3101_convert_stream_252(struct msi3101_state *s, u8 *dst,
  {
  	int i, i_max, dst_len = 0;
  	u32 sample_num[3];
+	unsigned long expires;
 
  	/* There could be 1-3 1024 bytes URB frames */
  	i_max = src_len / 1024;
@@ -488,7 +495,8 @@ static int msi3101_convert_stream_252(struct msi3101_state *s, u8 *dst,
  	}
 
  	/* calculate samping rate and output it in 10 seconds intervals */
-	if ((s->jiffies_next + msecs_to_jiffies(10000)) <= jiffies) {
+	expires = s->jiffies_next + msecs_to_jiffies(10000);
+	if (time_before_eq(expires, jiffies)) {
  		unsigned long jiffies_now = jiffies;
  		unsigned long msecs = jiffies_to_msecs(jiffies_now) - jiffies_to_msecs(s->jiffies_next);
  		unsigned int samples = sample_num[i_max - 1] - s->sample;
Signature · 1 line
http://palosaari.fi/
#2 lore raw
Quoted 7 lines · Antti Palosaari

Moikka!
That is already fixed by someone else and patch is somewhere Mauro or Hans queue.

regards
Antti

Moikka :)

Ah no worries - I could not find the changes with the latest updates.

Thanks