Skip to contentSkip to conversation

media: rc: rc-ir-raw: drop useless decrements in ir_raw_gen_{manchester,pl}()

PATCH In review Sergey Shtylyov 2 participants 4 messages Aug 18 – Aug 19

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: rc: rc-ir-raw: drop useless decrements in ir_raw_gen_{manchester,pl}()

In ir_raw_gen_{manchester,pl}(), the paremeter max is usually decremented while checking it for 0 but sometimes that action seems fruitless as max isn't used afterwards -- drop the useless decrement operators...

Found by Linux Verification Center (linuxtesting.org) with the Svace static analysis tool.

---
The patch is against the next branch of the linuxtv.org/media.git repo...

 drivers/media/rc/rc-ir-raw.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/rc/rc-ir-raw.c +2 -2
index ba24c2f22d39..ed494be8896f 100644
@@ -362,7 +362,7 @@ int ir_raw_gen_manchester(struct ir_raw_event **ev, unsigned int max,
 	if (timings->trailer_space) {
 		if (!(*ev)->pulse)
 			(*ev)->duration += timings->trailer_space;
-		else if (!max--)
+		else if (!max)
 			goto nobufs;
 		else
 			init_ir_raw_event_duration(++(*ev), 0,
@@ -491,7 +491,7 @@ int ir_raw_gen_pl(struct ir_raw_event **ev, unsigned int max,
 		}
 	}
 
-	if (!max--)
+	if (!max)
 		return ret;
 
 	init_ir_raw_event_duration((*ev)++, 0, timings->trailer_space);
Signature · 1 line
2.55.0
#1 lore raw
Quoted 1 line · Sergey Shtylyov

In ir_raw_gen_{manchester,pl}(), the paremeter max is usually decremented

Oops, s/paremeter/parameter/... :-)

Quoted 7 lines

while checking it for 0 but sometimes that action seems fruitless as max isn't used afterwards -- drop the useless decrement operators...

Found by Linux Verification Center (linuxtesting.org) with the Svace static analysis tool.

MBR, Sergey

maintainer
#2 lore raw
In reply to Sergey Shtylyov
Quoted 28 lines · Sergey Shtylyov

In ir_raw_gen_{manchester,pl}(), the paremeter max is usually decremented while checking it for 0 but sometimes that action seems fruitless as max isn't used afterwards -- drop the useless decrement operators...

Found by Linux Verification Center (linuxtesting.org) with the Svace static analysis tool.

---
The patch is against the next branch of the linuxtv.org/media.git repo...

 drivers/media/rc/rc-ir-raw.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/rc/rc-ir-raw.c +1 -1
index ba24c2f22d39..ed494be8896f 100644
@@ -362,7 +362,7 @@ int ir_raw_gen_manchester(struct ir_raw_event **ev, unsigned int max,
 	if (timings->trailer_space) {
 		if (!(*ev)->pulse)
 			(*ev)->duration += timings->trailer_space;
-		else if (!max--)
+		else if (!max)
 			goto nobufs;
 		else
 			init_ir_raw_event_duration(++(*ev), 0,

drivers/media/rc/rc-ir-raw.c int ir_raw_gen_pl(struct ir_raw_event **ev, unsigned int max, · line 494

Quoted 5 lines
drivers/media/rc/rc-ir-raw.c +1 -1
@@ -491,7 +491,7 @@ int ir_raw_gen_pl(struct ir_raw_event **ev, unsigned int max,
 		}
 	}
 
-	if (!max--)
+	if (!max)

This patch is technically correct, but won't make any difference to generated code. The decremented value of max will have zero users in the SSA tree, and will be droppped.

Changing this is purely cosmetic change to the code.

Sean

Quoted 6 lines
drivers/media/rc/rc-ir-raw.c +0 -0
 		return ret;
 
 	init_ir_raw_event_duration((*ev)++, 0, timings->trailer_space);
Signature · 1 line
2.55.0
#3 lore raw

On 8/19/26 10:31 AM, Sean Young wrote:
[...]

Quoted 31 lines
Quoted 31 lines

In ir_raw_gen_{manchester,pl}(), the paremeter max is usually decremented while checking it for 0 but sometimes that action seems fruitless as max isn't used afterwards -- drop the useless decrement operators...

Found by Linux Verification Center (linuxtesting.org) with the Svace static analysis tool.

---
The patch is against the next branch of the linuxtv.org/media.git repo...

 drivers/media/rc/rc-ir-raw.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/rc/rc-ir-raw.c +1 -1
index ba24c2f22d39..ed494be8896f 100644
@@ -362,7 +362,7 @@ int ir_raw_gen_manchester(struct ir_raw_event **ev, unsigned int max,
      if (timings->trailer_space) {
              if (!(*ev)->pulse)
                      (*ev)->duration += timings->trailer_space;
-             else if (!max--)
+             else if (!max)
                      goto nobufs;
              else
                      init_ir_raw_event_duration(++(*ev), 0,
@@ -491,7 +491,7 @@ int ir_raw_gen_pl(struct ir_raw_event **ev, unsigned int max,
              }
      }
 
Quoted 5 lines

drivers/media/rc/rc-ir-raw.c int ir_raw_gen_pl(struct ir_raw_event **ev, unsigned int max, · line 494

Quoted 2 lines
drivers/media/rc/rc-ir-raw.c +1 -1
-     if (!max--)
+     if (!max)

This patch is technically correct, but won't make any difference to generated code. The decremented value of max will have zero users in the

After looking at the .lst file (that wasn't easy), you're correct...

Quoted 1 line

SSA tree, and will be droppped.

Had to google SSA tree... :-)

Quoted 1 line

Changing this is purely cosmetic change to the code.

Makes the code a bit clearer, no?

Quoted 1 line

Sean

[...]

MBR, Sergey