Skip to contentSkip to conversation

handle more graciously labels with no statement

PATCH In review Luc Van Oostenryck 3 participants 6 messages Oct 26, 2020 Sparse checker

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 handle more graciously labels with no statement

In C a label must precede a statement. A null statement is OK but a closing braces is not.

So, catch this situation, emit a warning and continue as if a null statement was there.

This occurs currently on v5.10-rc1 because of some ifdefery.

---
 parse.c | 5 +++++
 1 file changed, 5 insertions(+)
parse.c +5 -0
index 31ecef0f554d..b6090d38cc61 100644
@@ -2468,6 +2468,11 @@ static struct token *statement(struct token *token, struct statement **tree)
 					warn_label_usage(stmt->pos, s->label_pos, s->ident);
 			}
 			s->stmt = stmt;
+			if (match_op(token, '}')) {
+				warning(token->pos, "statement expected after label");
+				stmt->label_statement = alloc_statement(token->pos, STMT_NONE);
+				return token;
+			}
 			return statement(token, &stmt->label_statement);
 		}
 	}
Signature · 1 line
2.29.0
#1 lore raw
Quoted 2 lines · Luc Van Oostenryck

This occurs currently on v5.10-rc1 because of some ifdefery.

Well, sparse being more robust is good, so the patch looks sane to me..

But can you point to the actual 5.10-rc1 problem? I haven't seen the report, and afaik gcc will complain about this too ("label at end of compound statement") so I'm surprised sparse hits it..

Linus

#2 lore raw
Quoted 10 lines · Linus Torvalds
Quoted 2 lines · Luc Van Oostenryck

This occurs currently on v5.10-rc1 because of some ifdefery.

Well, sparse being more robust is good, so the patch looks sane to me..

But can you point to the actual 5.10-rc1 problem? I haven't seen the report, and afaik gcc will complain about this too ("label at end of compound statement") so I'm surprised sparse hits it..

Well, I was surprised it wasn't caught and was ready to send a patch but it can only happen when using sparse, see below, quite ironical:

	drivers/scsi/qla2xxx/qla_tmpl.c:1052.
	1050         }
	1051 
	1052 bailout:
	1053 #ifndef __CHECKER__
	1054         if (!hardware_locked)
	1055                 spin_unlock_irqrestore(&vha->hw->hardware_lock, flags);
	1056 #endif
	1057 }

-- Luc

#3 lore raw
Quoted 8 lines · Luc Van Oostenryck
Quoted 3 lines · Linus Torvalds

But can you point to the actual 5.10-rc1 problem? I haven't seen the report, and afaik gcc will complain about this too ("label at end of compound statement") so I'm surprised sparse hits it..

Well, I was surprised it wasn't caught and was ready to send a patch but it can only happen when using sparse, see below, quite ironic:

Quoted 9 lines
        drivers/scsi/qla2xxx/qla_tmpl.c:1052.
        1050         }
        1051
        1052 bailout:
        1053 #ifndef __CHECKER__
        1054         if (!hardware_locked)
        1055                 spin_unlock_irqrestore(&vha->hw->hardware_lock, flags);
        1056 #endif
        1057 }

Yeah, that "don't sparse this" pattern has been problematic before.

I removed it.

Bart, Arun - see commit 4525c8781ec0 ("scsi: qla2xxx: remove incorrect sparse #ifdef").

Linus

#4 lore raw
Quoted 20 lines · Linus Torvalds
Quoted 8 lines · Luc Van Oostenryck
Quoted 3 lines · Linus Torvalds

But can you point to the actual 5.10-rc1 problem? I haven't seen the report, and afaik gcc will complain about this too ("label at end of compound statement") so I'm surprised sparse hits it..

Well, I was surprised it wasn't caught and was ready to send a patch but it can only happen when using sparse, see below, quite ironic:

Quoted 9 lines
        drivers/scsi/qla2xxx/qla_tmpl.c:1052.
        1050         }
        1051
        1052 bailout:
        1053 #ifndef __CHECKER__
        1054         if (!hardware_locked)
        1055                 spin_unlock_irqrestore(&vha->hw->hardware_lock, flags);
        1056 #endif
        1057 }
Quoted 6 lines

Yeah, that "don't sparse this" pattern has been problematic before.

I removed it.

Bart, Arun - see commit 4525c8781ec0 ("scsi: qla2xxx: remove incorrect sparse #ifdef").

Hi Linus,

Thank you for having Cc-ed me. I agree that it's better to make the kernel code compliant with the C standard than to make sparse accept non-standard code.

The #ifndef __CHECKER__ / #endif that I added in 2015 in the above code (commit 8d16366b5f23) was added because at that time I didn't see a better solution.

BTW, personally I'm neither enthusiast about #ifndef __CHECKER__ / #endif nor about if (expression) <locking statement>.

Bart.

#5 lore raw
Quoted 4 lines · Bart Van Assche

The #ifndef __CHECKER__ / #endif that I added in 2015 in the above code (commit 8d16366b5f23) was added because at that time I didn't see a better solution.

I think there are only a couple of callers, and all of them just have a constant "device_locked" argument.

It should be easy to make the (I think single) use that _didn't_ lock the device just do the locking, and then all of them have "device_locked = 1", and then that argument can be removed and the whole conditional be replaced by a lockdep assert.

Exactly like y9ou did in 8ae178760b23 ("scsi: qla2xxx: Simplify the functions for dumping firmware") in other words.

But I didn't really look _that_ much into it, this is just from a simple "grep" thing and maybe I missed something. I just did the minimal "don't do invalid C" thing.

Linus