* [PATCH 1/5] Staging: rtl8723au: Use macro min_t instead of ternary operator
2016-02-22 10:45 [PATCH 0/5] Staging: Replace ternary operators with min_t/max_t Bhumika Goyal
@ 2016-02-22 10:45 ` Bhumika Goyal
2016-02-22 10:45 ` [PATCH 2/5] Staging: rdma: " Bhumika Goyal
` (4 subsequent siblings)
5 siblings, 0 replies; 11+ messages in thread
From: Bhumika Goyal @ 2016-02-22 10:45 UTC (permalink / raw)
To: outreachy-kernel; +Cc: Bhumika Goyal, Bhumika Goyal
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)
)
Signed-off-by: Bhumika Goyal <bhumirks@gmai.com>
---
drivers/staging/rtl8723au/os_dep/ioctl_cfg80211.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/drivers/staging/rtl8723au/os_dep/ioctl_cfg80211.c b/drivers/staging/rtl8723au/os_dep/ioctl_cfg80211.c
index 6868392..c9baeef 100644
--- a/drivers/staging/rtl8723au/os_dep/ioctl_cfg80211.c
+++ b/drivers/staging/rtl8723au/os_dep/ioctl_cfg80211.c
@@ -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);
--
1.9.1
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 2/5] Staging: rdma: Use macro min_t instead of ternary operator
2016-02-22 10:45 [PATCH 0/5] Staging: Replace ternary operators with min_t/max_t Bhumika Goyal
2016-02-22 10:45 ` [PATCH 1/5] Staging: rtl8723au: Use macro min_t instead of ternary operator Bhumika Goyal
@ 2016-02-22 10:45 ` Bhumika Goyal
2016-02-22 10:45 ` [PATCH 3/5] Staging: gdm724x: Use " Bhumika Goyal
` (3 subsequent siblings)
5 siblings, 0 replies; 11+ messages in thread
From: Bhumika Goyal @ 2016-02-22 10:45 UTC (permalink / raw)
To: outreachy-kernel; +Cc: Bhumika Goyal
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)
)
Signed-off-by: Bhumika Goyal <bhumirks@gmail.com>
---
drivers/staging/rdma/hfi1/pio_copy.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/staging/rdma/hfi1/pio_copy.c b/drivers/staging/rdma/hfi1/pio_copy.c
index ebb0baf..cd5b439 100644
--- a/drivers/staging/rdma/hfi1/pio_copy.c
+++ b/drivers/staging/rdma/hfi1/pio_copy.c
@@ -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;
--
1.9.1
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 3/5] Staging: gdm724x: Use min_t instead of ternary operator
2016-02-22 10:45 [PATCH 0/5] Staging: Replace ternary operators with min_t/max_t Bhumika Goyal
2016-02-22 10:45 ` [PATCH 1/5] Staging: rtl8723au: Use macro min_t instead of ternary operator Bhumika Goyal
2016-02-22 10:45 ` [PATCH 2/5] Staging: rdma: " Bhumika Goyal
@ 2016-02-22 10:45 ` Bhumika Goyal
2016-02-22 10:45 ` [PATCH 4/5] Staging: lustre: Use min_t or max_t " Bhumika Goyal
` (2 subsequent siblings)
5 siblings, 0 replies; 11+ messages in thread
From: Bhumika Goyal @ 2016-02-22 10:45 UTC (permalink / raw)
To: outreachy-kernel; +Cc: Bhumika Goyal
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)
)
Signed-off-by: Bhumika Goyal <bhumirks@gmail.com>
---
drivers/staging/gdm724x/gdm_mux.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/staging/gdm724x/gdm_mux.c b/drivers/staging/gdm724x/gdm_mux.c
index 937010b..289d41a 100644
--- a/drivers/staging/gdm724x/gdm_mux.c
+++ b/drivers/staging/gdm724x/gdm_mux.c
@@ -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)
--
1.9.1
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 4/5] Staging: lustre: Use min_t or max_t instead of ternary operator
2016-02-22 10:45 [PATCH 0/5] Staging: Replace ternary operators with min_t/max_t Bhumika Goyal
` (2 preceding siblings ...)
2016-02-22 10:45 ` [PATCH 3/5] Staging: gdm724x: Use " Bhumika Goyal
@ 2016-02-22 10:45 ` Bhumika Goyal
2016-02-22 12:40 ` [Outreachy kernel] " Julia Lawall
2016-02-22 21:10 ` Greg KH
2016-02-22 10:45 ` [PATCH 5/5] Staging: rts5208: Use min_t " Bhumika Goyal
2016-02-22 21:11 ` [Outreachy kernel] [PATCH 0/5] Staging: Replace ternary operators with min_t/max_t Greg KH
5 siblings, 2 replies; 11+ messages in thread
From: Bhumika Goyal @ 2016-02-22 10:45 UTC (permalink / raw)
To: outreachy-kernel; +Cc: Bhumika Goyal
Replace 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)
)
Signed-off-by: Bhumika Goyal <bhumirks@gmail.com>
---
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(-)
diff --git a/drivers/staging/lustre/lustre/include/lustre_disk.h b/drivers/staging/lustre/lustre/include/lustre_disk.h
index 7c6933f..c886f7c 100644
--- a/drivers/staging/lustre/lustre/include/lustre_disk.h
+++ b/drivers/staging/lustre/lustre/include/lustre_disk.h
@@ -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 *********************/
diff --git a/drivers/staging/lustre/lustre/osc/osc_request.c b/drivers/staging/lustre/lustre/osc/osc_request.c
index 43b11c6..065a915 100644
--- a/drivers/staging/lustre/lustre/osc/osc_request.c
+++ b/drivers/staging/lustre/lustre/osc/osc_request.c
@@ -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 */
diff --git a/drivers/staging/lustre/lustre/ptlrpc/events.c b/drivers/staging/lustre/lustre/ptlrpc/events.c
index 64eaa0e..3219fad 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/events.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/events.c
@@ -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
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [Outreachy kernel] [PATCH 4/5] Staging: lustre: Use min_t or max_t instead of ternary operator
2016-02-22 10:45 ` [PATCH 4/5] Staging: lustre: Use min_t or max_t " Bhumika Goyal
@ 2016-02-22 12:40 ` Julia Lawall
2016-02-22 13:33 ` Bhumika Goyal
2016-02-22 21:10 ` Greg KH
1 sibling, 1 reply; 11+ messages in thread
From: Julia Lawall @ 2016-02-22 12:40 UTC (permalink / raw)
To: Bhumika Goyal; +Cc: outreachy-kernel
On Mon, 22 Feb 2016, Bhumika Goyal wrote:
> Replace 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;
Nice use of types.
julia
> @@
> (
> - x < y ? x : y
> + min_t(T,x,y)
> |
> - x > y ? x : y
> + max_t(T,x,y)
> )
>
> Signed-off-by: Bhumika Goyal <bhumirks@gmail.com>
> ---
> 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(-)
>
> diff --git a/drivers/staging/lustre/lustre/include/lustre_disk.h b/drivers/staging/lustre/lustre/include/lustre_disk.h
> index 7c6933f..c886f7c 100644
> --- a/drivers/staging/lustre/lustre/include/lustre_disk.h
> +++ b/drivers/staging/lustre/lustre/include/lustre_disk.h
> @@ -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 *********************/
> diff --git a/drivers/staging/lustre/lustre/osc/osc_request.c b/drivers/staging/lustre/lustre/osc/osc_request.c
> index 43b11c6..065a915 100644
> --- a/drivers/staging/lustre/lustre/osc/osc_request.c
> +++ b/drivers/staging/lustre/lustre/osc/osc_request.c
> @@ -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 */
> diff --git a/drivers/staging/lustre/lustre/ptlrpc/events.c b/drivers/staging/lustre/lustre/ptlrpc/events.c
> index 64eaa0e..3219fad 100644
> --- a/drivers/staging/lustre/lustre/ptlrpc/events.c
> +++ b/drivers/staging/lustre/lustre/ptlrpc/events.c
> @@ -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 outreachy-kernel+unsubscribe@googlegroups.com.
> To post to this group, send email to outreachy-kernel@googlegroups.com.
> 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.
>
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [Outreachy kernel] [PATCH 4/5] Staging: lustre: Use min_t or max_t instead of ternary operator
2016-02-22 12:40 ` [Outreachy kernel] " Julia Lawall
@ 2016-02-22 13:33 ` Bhumika Goyal
0 siblings, 0 replies; 11+ messages in thread
From: Bhumika Goyal @ 2016-02-22 13:33 UTC (permalink / raw)
To: Julia Lawall; +Cc: outreachy-kernel
On Mon, Feb 22, 2016 at 6:10 PM, Julia Lawall <julia.lawall@lip6.fr> wrote:
>
>
> On Mon, 22 Feb 2016, Bhumika Goyal wrote:
>
>> Replace 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;
>
> Nice use of types.
>
> julia
>
Thanks to you for always guiding :D .
Bhumika
>> @@
>> (
>> - x < y ? x : y
>> + min_t(T,x,y)
>> |
>> - x > y ? x : y
>> + max_t(T,x,y)
>> )
>>
>> Signed-off-by: Bhumika Goyal <bhumirks@gmail.com>
>> ---
>> 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(-)
>>
>> diff --git a/drivers/staging/lustre/lustre/include/lustre_disk.h b/drivers/staging/lustre/lustre/include/lustre_disk.h
>> index 7c6933f..c886f7c 100644
>> --- a/drivers/staging/lustre/lustre/include/lustre_disk.h
>> +++ b/drivers/staging/lustre/lustre/include/lustre_disk.h
>> @@ -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 *********************/
>> diff --git a/drivers/staging/lustre/lustre/osc/osc_request.c b/drivers/staging/lustre/lustre/osc/osc_request.c
>> index 43b11c6..065a915 100644
>> --- a/drivers/staging/lustre/lustre/osc/osc_request.c
>> +++ b/drivers/staging/lustre/lustre/osc/osc_request.c
>> @@ -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 */
>> diff --git a/drivers/staging/lustre/lustre/ptlrpc/events.c b/drivers/staging/lustre/lustre/ptlrpc/events.c
>> index 64eaa0e..3219fad 100644
>> --- a/drivers/staging/lustre/lustre/ptlrpc/events.c
>> +++ b/drivers/staging/lustre/lustre/ptlrpc/events.c
>> @@ -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 outreachy-kernel+unsubscribe@googlegroups.com.
>> To post to this group, send email to outreachy-kernel@googlegroups.com.
>> 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.
>>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Outreachy kernel] [PATCH 4/5] Staging: lustre: Use min_t or max_t instead of ternary operator
2016-02-22 10:45 ` [PATCH 4/5] Staging: lustre: Use min_t or max_t " Bhumika Goyal
2016-02-22 12:40 ` [Outreachy kernel] " Julia Lawall
@ 2016-02-22 21:10 ` Greg KH
2016-02-23 3:43 ` Bhumika Goyal
1 sibling, 1 reply; 11+ messages in thread
From: Greg KH @ 2016-02-22 21:10 UTC (permalink / raw)
To: Bhumika Goyal; +Cc: outreachy-kernel
On Mon, Feb 22, 2016 at 04:15:33PM +0530, Bhumika Goyal wrote:
> Replace 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)
> )
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
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Outreachy kernel] [PATCH 4/5] Staging: lustre: Use min_t or max_t instead of ternary operator
2016-02-22 21:10 ` Greg KH
@ 2016-02-23 3:43 ` Bhumika Goyal
0 siblings, 0 replies; 11+ messages in thread
From: Bhumika Goyal @ 2016-02-23 3:43 UTC (permalink / raw)
To: Greg KH; +Cc: outreachy-kernel
On Tue, Feb 23, 2016 at 2:40 AM, Greg KH <gregkh@linuxfoundation.org> wrote:
> On Mon, Feb 22, 2016 at 04:15:33PM +0530, Bhumika Goyal wrote:
>> Replace 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)
>> )
>
> 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
Ok I got the point, I will use min() and max() and send a v2 for all
the patches.
Thanks
Bhumika
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 5/5] Staging: rts5208: Use min_t instead of ternary operator
2016-02-22 10:45 [PATCH 0/5] Staging: Replace ternary operators with min_t/max_t Bhumika Goyal
` (3 preceding siblings ...)
2016-02-22 10:45 ` [PATCH 4/5] Staging: lustre: Use min_t or max_t " Bhumika Goyal
@ 2016-02-22 10:45 ` Bhumika Goyal
2016-02-22 21:11 ` [Outreachy kernel] [PATCH 0/5] Staging: Replace ternary operators with min_t/max_t Greg KH
5 siblings, 0 replies; 11+ messages in thread
From: Bhumika Goyal @ 2016-02-22 10:45 UTC (permalink / raw)
To: outreachy-kernel; +Cc: Bhumika Goyal
This 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)
)
Signed-off-by: Bhumika Goyal <bhumirks@gmail.com>
---
drivers/staging/rts5208/sd.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/rts5208/sd.c b/drivers/staging/rts5208/sd.c
index 244d589..adf1848 100644
--- a/drivers/staging/rts5208/sd.c
+++ b/drivers/staging/rts5208/sd.c
@@ -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]);
}
--
1.9.1
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [Outreachy kernel] [PATCH 0/5] Staging: Replace ternary operators with min_t/max_t
2016-02-22 10:45 [PATCH 0/5] Staging: Replace ternary operators with min_t/max_t Bhumika Goyal
` (4 preceding siblings ...)
2016-02-22 10:45 ` [PATCH 5/5] Staging: rts5208: Use min_t " Bhumika Goyal
@ 2016-02-22 21:11 ` Greg KH
5 siblings, 0 replies; 11+ messages in thread
From: Greg KH @ 2016-02-22 21:11 UTC (permalink / raw)
To: Bhumika Goyal; +Cc: outreachy-kernel
On Mon, Feb 22, 2016 at 04:15:29PM +0530, Bhumika Goyal wrote:
> 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)
> )
Same min_t() and max_t() comment for all of these, thanks.
greg k-h
^ permalink raw reply [flat|nested] 11+ messages in thread