linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mISDN: Fix type of switch control variable in ctrl_teimanager
@ 2018-10-19 18:00 Nathan Chancellor
  2018-10-23  2:30 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Nathan Chancellor @ 2018-10-19 18:00 UTC (permalink / raw)
  To: Karsten Keil, David S. Miller; +Cc: netdev, linux-kernel, Nathan Chancellor

Clang warns (trimmed for brevity):

drivers/isdn/mISDN/tei.c:1193:7: warning: overflow converting case value
to switch condition type (2147764552 to 18446744071562348872) [-Wswitch]
        case IMHOLD_L1:
             ^
drivers/isdn/mISDN/tei.c:1187:7: warning: overflow converting case value
to switch condition type (2147764550 to 18446744071562348870) [-Wswitch]
        case IMCLEAR_L2:
             ^
2 warnings generated.

The root cause is that the _IOC macro can generate really large numbers,
which don't find into type int. My research into how GCC and Clang are
handling this at a low level didn't prove fruitful and surveying the
kernel tree shows that aside from here and a few places in the scsi
subsystem, everything that uses _IOC is at least of type 'unsigned int'.
Make that change here because as nothing in this function cares about
the signedness of the variable and it removes ambiguity, which is never
good when dealing with compilers.

While we're here, remove the unnecessary local variable ret (just return
-EINVAL and 0 directly).

Link: https://github.com/ClangBuiltLinux/linux/issues/67
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
---
 drivers/isdn/mISDN/tei.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/isdn/mISDN/tei.c b/drivers/isdn/mISDN/tei.c
index 12d9e5f4beb1..58635b5f296f 100644
--- a/drivers/isdn/mISDN/tei.c
+++ b/drivers/isdn/mISDN/tei.c
@@ -1180,8 +1180,7 @@ static int
 ctrl_teimanager(struct manager *mgr, void *arg)
 {
 	/* currently we only have one option */
-	int	*val = (int *)arg;
-	int	ret = 0;
+	unsigned int *val = (unsigned int *)arg;
 
 	switch (val[0]) {
 	case IMCLEAR_L2:
@@ -1197,9 +1196,9 @@ ctrl_teimanager(struct manager *mgr, void *arg)
 			test_and_clear_bit(OPTION_L1_HOLD, &mgr->options);
 		break;
 	default:
-		ret = -EINVAL;
+		return -EINVAL;
 	}
-	return ret;
+	return 0;
 }
 
 /* This function does create a L2 for fixed TEI in NT Mode */
-- 
2.19.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] mISDN: Fix type of switch control variable in ctrl_teimanager
  2018-10-19 18:00 [PATCH] mISDN: Fix type of switch control variable in ctrl_teimanager Nathan Chancellor
@ 2018-10-23  2:30 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2018-10-23  2:30 UTC (permalink / raw)
  To: natechancellor; +Cc: isdn, netdev, linux-kernel

From: Nathan Chancellor <natechancellor@gmail.com>
Date: Fri, 19 Oct 2018 11:00:30 -0700

> Clang warns (trimmed for brevity):
> 
> drivers/isdn/mISDN/tei.c:1193:7: warning: overflow converting case value
> to switch condition type (2147764552 to 18446744071562348872) [-Wswitch]
>         case IMHOLD_L1:
>              ^
> drivers/isdn/mISDN/tei.c:1187:7: warning: overflow converting case value
> to switch condition type (2147764550 to 18446744071562348870) [-Wswitch]
>         case IMCLEAR_L2:
>              ^
> 2 warnings generated.
> 
> The root cause is that the _IOC macro can generate really large numbers,
> which don't find into type int. My research into how GCC and Clang are
> handling this at a low level didn't prove fruitful and surveying the
> kernel tree shows that aside from here and a few places in the scsi
> subsystem, everything that uses _IOC is at least of type 'unsigned int'.
> Make that change here because as nothing in this function cares about
> the signedness of the variable and it removes ambiguity, which is never
> good when dealing with compilers.
> 
> While we're here, remove the unnecessary local variable ret (just return
> -EINVAL and 0 directly).
> 
> Link: https://github.com/ClangBuiltLinux/linux/issues/67
> Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>

Applied.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-10-23  2:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-19 18:00 [PATCH] mISDN: Fix type of switch control variable in ctrl_teimanager Nathan Chancellor
2018-10-23  2:30 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).