Skip to contentSkip to conversation

kernel/compat.c: mark expected switch fall-throughs

PATCH Superseded Stephen Rothwell 2 participants 4 messages Apr 16, 2019

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kernel/compat.c: mark expected switch fall-throughs

In preparation to enabling -Wimplicit-fallthrough, mark switch cases where we are expecting to fall through.

This patch aims to suppress up to 3 missing-break-in-switch false positives on some architectures.

Cc Arnd Bergmann <[email protected]>
Cc Deepa Dinamani <[email protected]>
Cc Gustavo A. R. Silva <[email protected]>
Cc Kees Cook <[email protected]>
Cc Jann Horn <[email protected]>
---
 kernel/compat.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

I know that this makes the lines longer than 80 characters, but I though that this was better than adding new lines.

Build tested on PowerPC.

kernel/compat.c +3 -3
index d8a36c6ad7c9..b61f75df188d 100644
@@ -345,9 +345,9 @@ get_compat_sigset(sigset_t *set, const compat_sigset_t __user *compat)
 	if (copy_from_user(&v, compat, sizeof(compat_sigset_t)))
 		return -EFAULT;
 	switch (_NSIG_WORDS) {
-	case 4: set->sig[3] = v.sig[6] | (((long)v.sig[7]) << 32 );
-	case 3: set->sig[2] = v.sig[4] | (((long)v.sig[5]) << 32 );
-	case 2: set->sig[1] = v.sig[2] | (((long)v.sig[3]) << 32 );
+	case 4: set->sig[3] = v.sig[6] | (((long)v.sig[7]) << 32 ); /* fall through */
+	case 3: set->sig[2] = v.sig[4] | (((long)v.sig[5]) << 32 ); /* fall through */
+	case 2: set->sig[1] = v.sig[2] | (((long)v.sig[3]) << 32 ); /* fall through */
 	case 1: set->sig[0] = v.sig[0] | (((long)v.sig[1]) << 32 );
 	}
 #else
Signature · 5 lines
2.20.1

-- 
Cheers,
Stephen Rothwell
Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · Stephen Rothwell

In preparation to enabling -Wimplicit-fallthrough, mark switch cases where we are expecting to fall through.

This patch aims to suppress up to 3 missing-break-in-switch false positives on some architectures.

Quoted 6 lines
Cc Arnd Bergmann <[email protected]>
Cc Deepa Dinamani <[email protected]>
Cc Gustavo A. R. Silva <[email protected]>
Cc Kees Cook <[email protected]>
Cc Jann Horn <[email protected]>
Quoted 6 lines
---
 kernel/compat.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

I know that this makes the lines longer than 80 characters, but I though that this was better than adding new lines.

It's a bit inconsistent though since put_compat_sigset() has the comments in separate lines, as of commit 89976005536c ("include/linux/compat.h: mark expected switch fall-throughs").

I don't care either way, but it might be better to do it the same way for both.

We could also consider just getting rid of put_compat_sigset() and get_compat_sigset() but replacing them with a combined put_sigset()/get_sigset() that does the right thing for both native and compat tasks. This lets us kill a couple of compat system calls that only differ in their sigset_t argument. On little-endian systems (which are the vast majority of the installed base), there is no difference anyway there is no overhead anyway since native and compat sigset_t are identical.

Arnd

#2 lore raw

Hi Arnd,

Quoted 2 lines · On Tue, 16 Apr 2019 10:32:55 +0200 Arnd Bergmann <[email protected]> wrote:

Thanks

Quoted 3 lines

It's a bit inconsistent though since put_compat_sigset() has the comments in separate lines, as of commit 89976005536c ("include/linux/compat.h: mark expected switch fall-throughs").

OK, I wasn't aware of that one.

Quoted 2 lines

I don't care either way, but it might be better to do it the same way for both.

Indeed, I will redo it that way (with your Acked-by).

Quoted 8 lines

We could also consider just getting rid of put_compat_sigset() and get_compat_sigset() but replacing them with a combined put_sigset()/get_sigset() that does the right thing for both native and compat tasks. This lets us kill a couple of compat system calls that only differ in their sigset_t argument. On little-endian systems (which are the vast majority of the installed base), there is no difference anyway there is no overhead anyway since native and compat sigset_t are identical.

That sounds like a bigger patch that would require some real testing :-)

Signature · 2 lines
Cheers,
Stephen Rothwell
#3 lore raw
Quoted 11 lines · Stephen Rothwell
Quoted 8 lines · On Tue, 16 Apr 2019 10:32:55 +0200 Arnd Bergmann <[email protected]> wrote:

We could also consider just getting rid of put_compat_sigset() and get_compat_sigset() but replacing them with a combined put_sigset()/get_sigset() that does the right thing for both native and compat tasks. This lets us kill a couple of compat system calls that only differ in their sigset_t argument. On little-endian systems (which are the vast majority of the installed base), there is no difference anyway there is no overhead anyway since native and compat sigset_t are identical.

That sounds like a bigger patch that would require some real testing :-)

Yes, definitely. I mainly mentioned it in case someone wants to do that work anyway, as it would avoid the need for your patch.

Arnd