Staging: Replace ternary operators with min_t/max_t
cover Staging: Replace ternary operators with min_t/max_t
This patchset replaces ternary operators with macros min_t/max_t as they are shorter and thus increases code readability. Macro min_t return the minimum and min_t returns maximum of the two compared values. Made a semantic patch for changes:
@@
type T;
T x;
T y;
@@
(
- x < y ? x : y
+ min_t(T,x,y)
|
- x > y ? x : y
+ max_t(T,x,y)
)
Bhumika Goyal (5):
Staging: rtl8723au: Use macro min_t instead of ternary operator
Staging: rdma: Use macro min_t instead of ternary operator
Staging: gdm724x: Use min_t instead of ternary operator
Staging: lustre: Use min_t and max_t instead of ternary operator
Staging: rts5208: Use min_t instead of ternary operator
drivers/staging/gdm724x/gdm_mux.c | 2 +- drivers/staging/lustre/lustre/include/lustre_disk.h | 6 ++---- drivers/staging/lustre/lustre/osc/osc_request.c | 2 +- drivers/staging/lustre/lustre/ptlrpc/events.c | 2 +- drivers/staging/rdma/hfi1/pio_copy.c | 6 +++--- drivers/staging/rtl8723au/os_dep/ioctl_cfg80211.c | 14 +++++++------- drivers/staging/rts5208/sd.c | 4 ++-- 7 files changed, 17 insertions(+), 19 deletions(-)
Signature · 1 line
1.9.1
PATCH 1/5 Staging: rtl8723au: Use macro min_t instead of ternary operator
This patch replaces ternary operator with macro min_t as it shorter and thus increases code readability. Macro min_t return the minimum of the two compared values.
Made a semantic patch for changes:
@@
type T;
T x;
T y;
@@
(
- x < y ? x : y
+ min_t(T,x,y)
|
- x > y ? x : y
+ max_t(T,x,y)
)
--- drivers/staging/rtl8723au/os_dep/ioctl_cfg80211.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/staging/rtl8723au/os_dep/ioctl_cfg80211.c +7 -7
@@ -542,7 +542,7 @@ static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, u8 key_index,memcpy (psecuritypriv-> dot118021XGrpKey[key_index].skey, keyparms->key, - (key_len >16 ?16 : key_len)); + (min_t (int,16 , key_len)));/* set mic key */ memcpy(psecuritypriv->
@@ -564,7 +564,7 @@ static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, u8 key_index,memcpy (psecuritypriv-> dot118021XGrpKey[key_index].skey, keyparms->key, - (key_len >16 ?16 : key_len)); + (min_t (int,16 , key_len))); }else {DBG_8723A ("%s, set group_key, none\n" , __func__);
@@ -602,7 +602,7 @@ static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, u8 key_index,if (set_tx ==1 ) {/* pairwise key */ memcpy (psta->dot118021x_UncstKey.skey, - keyparms->key, (key_len >16 ?16 : key_len)); + keyparms->key, (min_t (int,16 , key_len)));if (keyparms->cipher ==WLAN_CIPHER_SUITE_WEP40 || keyparms->cipher ==WLAN_CIPHER_SUITE_WEP104 ) {
@@ -660,7 +660,7 @@ static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, u8 key_index,memcpy (psecuritypriv-> dot118021XGrpKey[key_index].skey, keyparms->key, - (key_len >16 ?16 : key_len)); + (min_t (int,16 , key_len)));/* set mic key */ memcpy(psecuritypriv->
@@ -678,7 +678,7 @@ static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, u8 key_index,memcpy (psecuritypriv-> dot118021XGrpKey[key_index].skey, keyparms->key, - (key_len >16 ?16 : key_len)); + (min_t (int,16 , key_len))); }else { psecuritypriv->dot118021XGrpPrivacy =0 ; }
@@ -788,7 +788,7 @@ static int rtw_cfg80211_set_encryption(struct net_device *dev, u8 key_index,memcpy (psta->dot118021x_UncstKey.skey, keyparms->key, - (key_len >16 ?16 : key_len)); + (min_t (int,16 , key_len)));if (keyparms->cipher ==WLAN_CIPHER_SUITE_TKIP ) {
@@ -811,7 +811,7 @@ static int rtw_cfg80211_set_encryption(struct net_device *dev, u8 key_index,memcpy (padapter->securitypriv. dot118021XGrpKey[key_index].skey, keyparms->key, - (key_len >16 ?16 : key_len)); + (min_t (int,16 , key_len)));memcpy (padapter->securitypriv. dot118021XGrptxmickey[key_index]. skey, &keyparms->key[16 ],8 );
Signature · 1 line
1.9.1
PATCH 2/5 Staging: rdma: Use macro min_t instead of ternary operator
In reply to Bhumika GoyalThis patch replaces ternary operator with macro min_t as it shorter and thus increases code readability. Macro min_t return the minimum of the two compared values.
Made a semantic patch for changes:
@@
type T;
T x;
T y;
@@
(
- x < y ? x : y
+ min_t(T,x,y)
|
- x > y ? x : y
+ max_t(T,x,y)
)
--- drivers/staging/rdma/hfi1/pio_copy.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/staging/rdma/hfi1/pio_copy.c +3 -3
@@ -235,7 +235,7 @@ static inline void read_extra_bytes(struct pio_buf *pbuf,while (nbytes) {/* find the number of bytes in this u64 */ room =8 - off;/* this u64 has room for this many bytes */ - xbytes = nbytes > room ? room : nbytes; + xbytes = min_t(unsigned int, room, nbytes);/* * shift down to zero lower bytes, shift up to zero upper
@@ -565,7 +565,7 @@ static void mid_copy_mix(struct pio_buf *pbuf, const void *from, size_t nbytes)/* calculate the end of data or end of block, whichever comes first */ send = pbuf->start +PIO_BLOCK_SIZE ; - xend = send < dend ? send : dend; + xend = min_t(void __iomem *, send, dend);/* shift up to SOP=1 space */ dest +=SOP_DISTANCE ;
@@ -659,7 +659,7 @@ static void mid_copy_straight(struct pio_buf *pbuf,/* calculate the end of data or end of block, whichever comes first */ send = pbuf->start +PIO_BLOCK_SIZE ; - xend = send < dend ? send : dend; + xend = min_t(void __iomem *, send, dend);/* shift up to SOP=1 space */ dest +=SOP_DISTANCE ;
Signature · 1 line
1.9.1
PATCH 3/5 Staging: gdm724x: Use min_t instead of ternary operator
In reply to Bhumika GoyalThis patch replaces ternary operator with macro min_t as it shorter and thus increases code readability. Macro min_t return the minimum of the two compared values.
Made a semantic patch for changes:
@@
type T;
T x;
T y;
@@
(
- x < y ? x : y
+ min_t(T,x,y)
|
- x > y ? x : y
+ max_t(T,x,y)
)
--- drivers/staging/gdm724x/gdm_mux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/gdm724x/gdm_mux.c +1 -1
@@ -433,7 +433,7 @@ static int gdm_mux_send_control(void *priv_dev, int request, int value,if (ret <0 )pr_err ("usb_control_msg error: %d\n" , ret); -return ret <0 ? ret :0 ; +return min_t (int, ret,0 ); }static void release_usb (struct mux_dev *mux_dev)
Signature · 1 line
1.9.1
PATCH 4/5 Staging: lustre: Use min_t or max_t instead of ternary operator
In reply to Bhumika GoyalReplace ternary operators with macros min_t/max_t as they are shorter and thus increases code readability. Macro min_t return the minimum and min_t returns maximum of the two compared values.
Made a semantic patch for changes:
@@
type T;
T x;
T y;
@@
(
- x < y ? x : y
+ min_t(T,x,y)
|
- x > y ? x : y
+ max_t(T,x,y)
)
--- drivers/staging/lustre/lustre/include/lustre_disk.h | 6 ++---- drivers/staging/lustre/lustre/osc/osc_request.c | 2 +- drivers/staging/lustre/lustre/ptlrpc/events.c | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-)
drivers/staging/lustre/lustre/include/lustre_disk.h +2 -4
@@ -331,14 +331,12 @@ static inline void lcd_cpu_to_le(struct lsd_client_data *lcd,static inline __u64 lcd_last_transno (struct lsd_client_data *lcd) { -return (lcd->lcd_last_transno > lcd->lcd_last_close_transno ? - lcd->lcd_last_transno : lcd->lcd_last_close_transno); +return max_t (__u64, lcd->lcd_last_transno, lcd->lcd_last_close_transno); }static inline __u64 lcd_last_xid (struct lsd_client_data *lcd) { -return (lcd->lcd_last_xid > lcd->lcd_last_close_xid ? - lcd->lcd_last_xid : lcd->lcd_last_close_xid); +return max_t (__u64, lcd->lcd_last_xid, lcd->lcd_last_close_xid); }/****************** superblock additional info *********************/
drivers/staging/lustre/lustre/osc/osc_request.c +1 -1
@@ -1170,7 +1170,7 @@ static u32 osc_checksum_bulk(int nob, u32 pg_count, }while (nob >0 && pg_count >0 ) { -int count = pga[i]->count > nob ? nob : pga[i]->count; +int count =min_t (int, nob, pga[i]->count);/* corrupt the data before we compute the checksum, to * simulate an OST->client data error */
drivers/staging/lustre/lustre/ptlrpc/events.c +1 -1
@@ -254,7 +254,7 @@ static void ptlrpc_req_add_history(struct ptlrpc_service_part *svcpt, new_seq = (sec <<REQS_SEC_SHIFT ) | (usec <<REQS_USEC_SHIFT ) | - (svcpt->scp_cpt <0 ?0 : svcpt->scp_cpt); + (max_t (int,0 , svcpt->scp_cpt));if (new_seq > svcpt->scp_hist_seq) {/* This handles the initial case of scp_hist_seq == 0 or
Signature · 1 line
1.9.1
Re: [Outreachy kernel] [PATCH 4/5] Staging: lustre: Use min_t or max_t instead of ternary operator
Quoted 9 lines · Bhumika Goyal
Replace ternary operators with macros min_t/max_t as they are shorter and thus increases code readability. Macro
min_treturn the minimum andmin_treturns maximum of the two compared values.
Made a semantic patch for changes:@@
type T;
T x;
T y;
Nice use of types.
julia
Quoted 73 lines
@@
(
- x < y ? x : y
+min_t(T,x,y)
|
- x > y ? x : y
+max_t(T,x,y)
)Signed-off-by Bhumika Goyal <[email protected]>--- drivers/staging/lustre/lustre/include/lustre_disk.h | 6 ++---- drivers/staging/lustre/lustre/osc/osc_request.c | 2 +- drivers/staging/lustre/lustre/ptlrpc/events.c | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-)drivers/staging/lustre/lustre/include/lustre_disk.h +2
-4@@ -331,14 +331,12 @@ static inline void lcd_cpu_to_le(struct lsd_client_data *lcd,static inline __u64 lcd_last_transno (struct lsd_client_data *lcd) { -return (lcd->lcd_last_transno > lcd->lcd_last_close_transno ? - lcd->lcd_last_transno : lcd->lcd_last_close_transno); +return max_t (__u64, lcd->lcd_last_transno, lcd->lcd_last_close_transno); }static inline __u64 lcd_last_xid (struct lsd_client_data *lcd) { -return (lcd->lcd_last_xid > lcd->lcd_last_close_xid ? - lcd->lcd_last_xid : lcd->lcd_last_close_xid); +return max_t (__u64, lcd->lcd_last_xid, lcd->lcd_last_close_xid); }/****************** superblock additional info *********************/ drivers/staging/lustre/lustre/osc/osc_request.c +1
-1@@ -1170,7 +1170,7 @@ static u32 osc_checksum_bulk(int nob, u32 pg_count, }while (nob >0 && pg_count >0 ) { -int count = pga[i]->count > nob ? nob : pga[i]->count; +int count =min_t (int, nob, pga[i]->count);/* corrupt the data before we compute the checksum, to * simulate an OST->client data error */ drivers/staging/lustre/lustre/ptlrpc/events.c +1
-2@@ -254,7 +254,7 @@ static void ptlrpc_req_add_history(struct ptlrpc_service_part *svcpt, new_seq = (sec <<REQS_SEC_SHIFT ) | (usec <<REQS_USEC_SHIFT ) | - (svcpt->scp_cpt <0 ?0 : svcpt->scp_cpt); + (max_t (int,0 , svcpt->scp_cpt));if (new_seq > svcpt->scp_hist_seq) {/* This handles the initial case of scp_hist_seq == 0 or -- 1.9.1
--
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/ae653a4fe839af60c62a545477d803c8b0866968.1456136671.git.bhumirks%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Re: [Outreachy kernel] [PATCH 4/5] Staging: lustre: Use min_t or max_t instead of ternary operator
Quoted 9 lines · Julia Lawall
Quoted 5 lines · Bhumika Goyal
Replace ternary operators with macros min_t/max_t as they are shorter and thus increases code readability. Macro
min_treturn the minimum andmin_treturns maximum of the two compared values.
Made a semantic patch for changes:
Quoted 9 lines
Quoted 4 lines
@@
type T;
T x;
T y;Nice use of types.
julia
Thanks to you for always guiding :D .
Bhumika
Quoted 73 lines
Quoted 73 lines
@@
(
- x < y ? x : y
+min_t(T,x,y)
|
- x > y ? x : y
+max_t(T,x,y)
)Signed-off-by Bhumika Goyal <[email protected]>--- drivers/staging/lustre/lustre/include/lustre_disk.h | 6 ++---- drivers/staging/lustre/lustre/osc/osc_request.c | 2 +- drivers/staging/lustre/lustre/ptlrpc/events.c | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-)drivers/staging/lustre/lustre/include/lustre_disk.h +2
-4@@ -331,14 +331,12 @@ static inline void lcd_cpu_to_le(struct lsd_client_data *lcd,static inline __u64 lcd_last_transno (struct lsd_client_data *lcd) { -return (lcd->lcd_last_transno > lcd->lcd_last_close_transno ? - lcd->lcd_last_transno : lcd->lcd_last_close_transno); +return max_t (__u64, lcd->lcd_last_transno, lcd->lcd_last_close_transno); }static inline __u64 lcd_last_xid (struct lsd_client_data *lcd) { -return (lcd->lcd_last_xid > lcd->lcd_last_close_xid ? - lcd->lcd_last_xid : lcd->lcd_last_close_xid); +return max_t (__u64, lcd->lcd_last_xid, lcd->lcd_last_close_xid); }/****************** superblock additional info *********************/ drivers/staging/lustre/lustre/osc/osc_request.c +1
-1@@ -1170,7 +1170,7 @@ static u32 osc_checksum_bulk(int nob, u32 pg_count, }while (nob >0 && pg_count >0 ) { -int count = pga[i]->count > nob ? nob : pga[i]->count; +int count =min_t (int, nob, pga[i]->count);/* corrupt the data before we compute the checksum, to * simulate an OST->client data error */ drivers/staging/lustre/lustre/ptlrpc/events.c +1
-2@@ -254,7 +254,7 @@ static void ptlrpc_req_add_history(struct ptlrpc_service_part *svcpt, new_seq = (sec <<REQS_SEC_SHIFT ) | (usec <<REQS_USEC_SHIFT ) | - (svcpt->scp_cpt <0 ?0 : svcpt->scp_cpt); + (max_t (int,0 , svcpt->scp_cpt));if (new_seq > svcpt->scp_hist_seq) {/* This handles the initial case of scp_hist_seq == 0 or -- 1.9.1
--
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/ae653a4fe839af60c62a545477d803c8b0866968.1456136671.git.bhumirks%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Greg KH
maintainerRe: [Outreachy kernel] [PATCH 4/5] Staging: lustre: Use min_t or max_t instead of ternary operator
In reply to Bhumika GoyalQuoted 5 lines · Bhumika Goyal
Replace ternary operators with macros min_t/max_t as they are shorter and thus increases code readability. Macro
min_treturn the minimum andmin_treturns maximum of the two compared values.
Made a semantic patch for changes:
Quoted 12 lines
@@
type T;
T x;
T y;
@@
(
- x < y ? x : y
+min_t(T,x,y)
|
- x > y ? x : y
+max_t(T,x,y)
)
If they are the same type, why can't you just use min() and max()? The call to min_t() and max_t() seem a bit of an overkill as they do an explicit cast for when the types of the two variables are not the same type.
So I'd prefer this patch to just be min() and max() if at all possible.
thanks,
greg k-h
Re: [Outreachy kernel] [PATCH 4/5] Staging: lustre: Use min_t or max_t instead of ternary operator
Quoted 24 lines · Greg KH
Quoted 5 lines · Bhumika Goyal
Replace ternary operators with macros min_t/max_t as they are shorter and thus increases code readability. Macro
min_treturn the minimum andmin_treturns maximum of the two compared values.
Made a semantic patch for changes:Quoted 12 lines
@@
type T;
T x;
T y;
@@
(
- x < y ? x : y
+min_t(T,x,y)
|
- x > y ? x : y
+max_t(T,x,y)
)If they are the same type, why can't you just use
min()andmax()? The call tomin_t()andmax_t()seem a bit of an overkill as they do an explicit cast for when the types of the two variables are not the same type.
Quoted 5 lines
So I'd prefer this patch to just be
min()andmax()if at all possible.thanks,
greg k-h
Ok I got the point, I will use min() and max() and send a v2 for all the patches.
Thanks
Bhumika
PATCH 5/5 Staging: rts5208: Use min_t instead of ternary operator
In reply to Bhumika GoyalThis patch replaces ternary operator with macro min_t as it is shorter and thus increases code readability. Macro min_t return the minimum of the two compared values.
Made a semantic patch for changes:
@@
type T;
T x;
T y;
@@
(
- x < y ? x : y
+ min_t(T,x,y)
|
- x > y ? x : y
+ max_t(T,x,y)
)
--- drivers/staging/rts5208/sd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/rts5208/sd.c +2 -2
@@ -303,7 +303,7 @@ static int sd_read_data(struct rtsx_chip *chip,if (cmd_len) {dev_dbg (rtsx_dev (chip),"SD/MMC CMD %d\n" , cmd[0 ] -0x40 ); -for (i =0 ; i < (cmd_len <6 ? cmd_len :6 ); i++) +for (i =0 ; i < (min_t (int, cmd_len,6 )); i++)rtsx_add_cmd (chip,WRITE_REG_CMD ,REG_SD_CMD0 + i,0xFF , cmd[i]); }
@@ -383,7 +383,7 @@ static int sd_write_data(struct rtsx_chip *chip, u8 trans_mode,if (cmd_len) {dev_dbg (rtsx_dev (chip),"SD/MMC CMD %d\n" , cmd[0 ] -0x40 ); -for (i =0 ; i < (cmd_len <6 ? cmd_len :6 ); i++) { +for (i =0 ; i < (min_t (int, cmd_len,6 )); i++) {rtsx_add_cmd (chip,WRITE_REG_CMD ,REG_SD_CMD0 + i,0xFF , cmd[i]); }
Signature · 1 line
1.9.1
Greg KH
maintainerQuoted 5 lines · Bhumika Goyal
This patchset replaces ternary operators with macros min_t/max_t as they are shorter and thus increases code readability. Macro
min_treturn the minimum andmin_treturns maximum of the two compared values. Made a semantic patch for changes:
Quoted 12 lines
@@
type T;
T x;
T y;
@@
(
- x < y ? x : y
+min_t(T,x,y)
|
- x > y ? x : y
+max_t(T,x,y)
)
Same min_t() and max_t() comment for all of these, thanks.
greg k-h