staging: gdm724x: Replace ternary operator with min macro
PATCH 1/1 staging: gdm724x: Replace ternary operator with min macro
Use macro min() to get the minimum of two values for brevity and readability.
Found using Coccinelle:
@@ type T; T x; T y; @@
(
- x < y ? x : y
+ min(x,y)
|
- x > y ? x : y
+ max(x,y)
)
--- drivers/staging/gdm724x/gdm_tty.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/staging/gdm724x/gdm_tty.c +1 -2
@@ -190,8 +190,7 @@ static int gdm_tty_write(struct tty_struct *tty, const unsigned char *buf,return 0 ;while (1 ) { - sending_len = remain >MUX_TX_MAX_SIZE ?MUX_TX_MAX_SIZE : - remain; + sending_len =min (MUX_TX_MAX_SIZE , remain); gdm_tty_send(gdm, (void *)(buf + sent_len), sending_len,
Signature · 1 line
2.7.4
Quoted 23 lines · Gargi Sharma
Use macro
min()to get the minimum of two values for brevity and readability.Found using Coccinelle:
@@ type T; T x; T y; @@
(
- x < y ? x : y
+min(x,y)
|
- x > y ? x : y
+max(x,y)
)Signed-off-by Gargi Sharma <[email protected]>--- drivers/staging/gdm724x/gdm_tty.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/staging/gdm724x/gdm_tty.c +0
-0
drivers/staging/gdm724x/gdm_tty.c static int gdm_tty_write(struct tty_struct *tty, const unsigned char *buf, · line 193
Quoted 6 lines
drivers/staging/gdm724x/gdm_tty.c +1
-2@@ -190,8 +190,7 @@ static int gdm_tty_write(struct tty_struct *tty, const unsigned char *buf,return 0 ;while (1 ) { - sending_len = remain >MUX_TX_MAX_SIZE ?MUX_TX_MAX_SIZE : - remain; + sending_len =min (MUX_TX_MAX_SIZE , remain);
Just a warning on this one. Coccinelle has no idea what the type of MUX_TX_MAX_SIZE is. It just sees an identifier with all capital letters and assumes it's an int. In this case, it looks ok, because remain is an int and MUX_TX_MAX_SIZE is small (2048).
julia
Quoted 13 lines
drivers/staging/gdm724x/gdm_tty.c +0
-1gdm_tty_send(gdm, (void *)(buf + sent_len), sending_len, --2.7.4
--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1488907371-26513-1-git-send-email-gs051095%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Quoted 29 lines · Julia Lawall
Quoted 25 lines · Gargi Sharma
Use macro
min()to get the minimum of two values for brevity and readability.Found using Coccinelle:
@@ type T; T x; T y; @@
(
- x < y ? x : y
+min(x,y)
|
- x > y ? x : y
+max(x,y)
)Signed-off-by Gargi Sharma <[email protected]>--- drivers/staging/gdm724x/gdm_tty.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/staging/gdm724x/gdm_tty.c +0
-0@@ -190,8 +190,7 @@ static int gdm_tty_write(struct tty_struct *tty, const unsigned char *buf,return 0 ;
Quoted 9 lines
drivers/staging/gdm724x/gdm_tty.c static int gdm_tty_write(struct tty_struct *tty, const unsigned char *buf, · line 193
Quoted 4 lines
drivers/staging/gdm724x/gdm_tty.c +1
-2while (1 ) { - sending_len = remain >MUX_TX_MAX_SIZE ?MUX_TX_MAX_SIZE : - remain; + sending_len =min (MUX_TX_MAX_SIZE , remain);Just a warning on this one. Coccinelle has no idea what the type of
MUX_TX_MAX_SIZEis. It just sees an identifier with all capital letters and assumes it's an int. In this case, it looks ok, because remain is an int andMUX_TX_MAX_SIZEis small (2048).
So, can the script be modified to check bounds on the macros as well? Also, will it be better if I edit the commit log to specify that the maximum value of the MUX_TX_MAX_SIZE is well within the integer range. The min macro uses typeof for strict type-checking, but I'm not sure how it determines the type of a macro like MUX_TX_MAX_SIZE.
thanks,
gargi
Quoted 16 lines
julia
Quoted 13 lines
drivers/staging/gdm724x/gdm_tty.c +0
-1gdm_tty_send(gdm, (void *)(buf + sent_len), sending_len, --2.7.4
--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1488907371-26513-1-git-send-email-gs051095%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Quoted 40 lines · Gargi Sharma
Quoted 29 lines · Julia Lawall
Quoted 25 lines · Gargi Sharma
Use macro
min()to get the minimum of two values for brevity and readability.Found using Coccinelle:
@@ type T; T x; T y; @@
(
- x < y ? x : y
+min(x,y)
|
- x > y ? x : y
+max(x,y)
)Signed-off-by Gargi Sharma <[email protected]>--- drivers/staging/gdm724x/gdm_tty.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/staging/gdm724x/gdm_tty.c +0
-0@@ -190,8 +190,7 @@ static int gdm_tty_write(struct tty_struct *tty, const unsigned char *buf,return 0 ;Quoted 9 lines
drivers/staging/gdm724x/gdm_tty.c static int gdm_tty_write(struct tty_struct *tty, const unsigned char *buf, · line 193
Quoted 4 lines
drivers/staging/gdm724x/gdm_tty.c +1
-2while (1 ) { - sending_len = remain >MUX_TX_MAX_SIZE ?MUX_TX_MAX_SIZE : - remain; + sending_len =min (MUX_TX_MAX_SIZE , remain);Just a warning on this one. Coccinelle has no idea what the type of
MUX_TX_MAX_SIZEis. It just sees an identifier with all capital letters and assumes it's an int. In this case, it looks ok, because remain is an int andMUX_TX_MAX_SIZEis small (2048).
Quoted 5 lines
So, can the script be modified to check bounds on the macros as well? Also, will it be better if I edit the commit log to specify that the maximum value of the
MUX_TX_MAX_SIZEis well within the integer range. The min macro uses typeof for strict type-checking, but I'm not sure how it determines the type of a macro likeMUX_TX_MAX_SIZE.
At the time it is relevant, the preprocessor has expanded all the macros. So it is just taking the type of 2048.
For the script, you would have to match the #define explicitly,eg
type T;
T e;
#define i e
But in general, you would need to get information about include files, ie --recursive-includes. Then you might want to buy a faster machine :)
It could be simpler to do the check manually.
julia
Quoted 27 lines
thanks,
gargiQuoted 16 lines
julia
Quoted 13 lines
drivers/staging/gdm724x/gdm_tty.c +0
-1gdm_tty_send(gdm, (void *)(buf + sent_len), sending_len, --2.7.4
--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1488907371-26513-1-git-send-email-gs051095%40gmail.com.
For more options, visit https://groups.google.com/d/optout.--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/CAOCi2DGJ-QNpvdoo5M4v320qD7dE3w-ZcvNJ8Xa0P%2BcYoZEhiA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Quoted 58 lines · Julia Lawall
Quoted 40 lines · Gargi Sharma
Quoted 29 lines · Julia Lawall
Quoted 25 lines · Gargi Sharma
Use macro
min()to get the minimum of two values for brevity and readability.Found using Coccinelle:
@@ type T; T x; T y; @@
(
- x < y ? x : y
+min(x,y)
|
- x > y ? x : y
+max(x,y)
)Signed-off-by Gargi Sharma <[email protected]>--- drivers/staging/gdm724x/gdm_tty.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/staging/gdm724x/gdm_tty.c +0
-0@@ -190,8 +190,7 @@ static int gdm_tty_write(struct tty_struct *tty, const unsigned char *buf,return 0 ;Quoted 9 lines
drivers/staging/gdm724x/gdm_tty.c static int gdm_tty_write(struct tty_struct *tty, const unsigned char *buf, · line 193
Quoted 4 lines
drivers/staging/gdm724x/gdm_tty.c +1
-2while (1 ) { - sending_len = remain >MUX_TX_MAX_SIZE ?MUX_TX_MAX_SIZE : - remain; + sending_len =min (MUX_TX_MAX_SIZE , remain);Just a warning on this one. Coccinelle has no idea what the type of
MUX_TX_MAX_SIZEis. It just sees an identifier with all capital letters and assumes it's an int. In this case, it looks ok, because remain is an int andMUX_TX_MAX_SIZEis small (2048).Quoted 5 lines
So, can the script be modified to check bounds on the macros as well? Also, will it be better if I edit the commit log to specify that the maximum value of the
MUX_TX_MAX_SIZEis well within the integer range. The min macro uses typeof for strict type-checking, but I'm not sure how it determines the type of a macro likeMUX_TX_MAX_SIZE.At the time it is relevant, the preprocessor has expanded all the macros. So it is just taking the type of 2048.
For the script, you would have to match the #define explicitly,eg
type T;
T e;
Quoted 6 lines
#define i e
But in general, you would need to get information about include files, ie --recursive-includes. Then you might want to buy a faster machine :)
It could be simpler to do the check manually.
Okay :). I'll edit the commit message to reflect that the macro has the value of 2048.
thanks,
gargi
Quoted 16 lines
julia
Quoted 13 lines
thanks,
gargiQuoted 10 lines
julia
Quoted 7 lines
drivers/staging/gdm724x/gdm_tty.c +0
-1gdm_tty_send(gdm, (void *)(buf + sent_len), sending_len, --2.7.4
--