All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/5] Staging: Replace ternary operators with macros min/max
@ 2016-02-23 15:47 Bhumika Goyal
  2016-02-23 15:47 ` [PATCH v2 1/5] Staging: rtl8723au: Use min macro instead of ternary operator Bhumika Goyal
                   ` (5 more replies)
  0 siblings, 6 replies; 13+ messages in thread
From: Bhumika Goyal @ 2016-02-23 15:47 UTC (permalink / raw)
  To: outreachy-kernel; +Cc: Bhumika Goyal

This patchset replaces ternary operators with macros min/max as
they are shorter and thus increases code readability. Macro min returns
the minimum and macro max returns maximum  of the two compared values.
Made a semantic patch for changes:

@@
type T;
T x;
T y;
@@
(
- x < y ? x : y
+ min(x,y)
|
- x > y ? x : y
+ max(x,y)
)

Changes in v2:
* Use min()/max() instead of min_t()/max_t() as the values passed in the 
  macros are of same type.

Bhumika Goyal (5):
  Staging: rtl8723au: Use min macro instead of ternary operator
  Staging: rdma: Use min macro instead of ternary operator
  Staging: gdm724x: Use min instead of ternary operator
  Staging: lustre: Use min or max instead of ternary operator
  Staging: rts5208: Use min 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(-)

-- 
1.9.1



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

* [PATCH v2 1/5] Staging: rtl8723au: Use min macro instead of ternary operator
  2016-02-23 15:47 [PATCH v2 0/5] Staging: Replace ternary operators with macros min/max Bhumika Goyal
@ 2016-02-23 15:47 ` Bhumika Goyal
  2016-02-23 15:47 ` [PATCH v2 2/5] Staging: rdma: " Bhumika Goyal
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 13+ messages in thread
From: Bhumika Goyal @ 2016-02-23 15:47 UTC (permalink / raw)
  To: outreachy-kernel; +Cc: Bhumika Goyal

This patch replaces ternary operator with macro min as it shorter and
thus increases code readability. Macro min 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(x,y)
|
- x > y ? x : y
+ max(x,y)
)

Signed-off-by: Bhumika Goyal <bhumirks@gmail.com>
---
Changes in v2:
Use min() instead of min_t() as the values passed in the macro are of
same type.

 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..cf0daa1 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(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(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(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(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(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(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(16, key_len)));
 					memcpy(padapter->securitypriv.
 					       dot118021XGrptxmickey[key_index].
 					       skey, &keyparms->key[16], 8);
-- 
1.9.1



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

* [PATCH v2 2/5] Staging: rdma: Use min macro instead of ternary operator
  2016-02-23 15:47 [PATCH v2 0/5] Staging: Replace ternary operators with macros min/max Bhumika Goyal
  2016-02-23 15:47 ` [PATCH v2 1/5] Staging: rtl8723au: Use min macro instead of ternary operator Bhumika Goyal
@ 2016-02-23 15:47 ` Bhumika Goyal
  2016-02-23 15:47 ` [PATCH v2 3/5] Staging: gdm724x: Use min " Bhumika Goyal
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 13+ messages in thread
From: Bhumika Goyal @ 2016-02-23 15:47 UTC (permalink / raw)
  To: outreachy-kernel; +Cc: Bhumika Goyal

This patch replaces ternary operator with macro min as it shorter and
thus increases code readability. Macro min 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(x,y)
|
- x > y ? x : y
+ max(x,y)
)

Signed-off-by: Bhumika Goyal <bhumirks@gmail.com>
---
Changes in v2:
Use min() instead of min_t() as the values passed in the macro are of
same type.

 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..64bef6c2 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(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(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(send, dend);
 
 		/* shift up to SOP=1 space */
 		dest += SOP_DISTANCE;
-- 
1.9.1



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

* [PATCH v2 3/5] Staging: gdm724x: Use min instead of ternary operator
  2016-02-23 15:47 [PATCH v2 0/5] Staging: Replace ternary operators with macros min/max Bhumika Goyal
  2016-02-23 15:47 ` [PATCH v2 1/5] Staging: rtl8723au: Use min macro instead of ternary operator Bhumika Goyal
  2016-02-23 15:47 ` [PATCH v2 2/5] Staging: rdma: " Bhumika Goyal
@ 2016-02-23 15:47 ` Bhumika Goyal
  2016-02-23 15:47 ` [PATCH v2 4/5] Staging: lustre: Use min or max " Bhumika Goyal
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 13+ messages in thread
From: Bhumika Goyal @ 2016-02-23 15:47 UTC (permalink / raw)
  To: outreachy-kernel; +Cc: Bhumika Goyal

This patch replaces ternary operator with macro min as it shorter and
thus increases code readability. Macro min 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(x,y)
|
- x > y ? x : y
+ max(x,y)
)

Signed-off-by: Bhumika Goyal <bhumirks@gmail.com>
---
Changes in v2:
Use min() instead of min_t() as the values passed in the macro are of
same type.

 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..6bedd66 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(ret, 0);
 }
 
 static void release_usb(struct mux_dev *mux_dev)
-- 
1.9.1



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

* [PATCH v2 4/5] Staging: lustre: Use min or max instead of ternary operator
  2016-02-23 15:47 [PATCH v2 0/5] Staging: Replace ternary operators with macros min/max Bhumika Goyal
                   ` (2 preceding siblings ...)
  2016-02-23 15:47 ` [PATCH v2 3/5] Staging: gdm724x: Use min " Bhumika Goyal
@ 2016-02-23 15:47 ` Bhumika Goyal
  2016-02-26  6:18   ` [Outreachy kernel] " Greg KH
  2016-02-23 15:47 ` [PATCH v2 5/5] Staging: rts5208: Use min " Bhumika Goyal
  2016-02-26 10:04 ` [PATCH v3 0/5] Staging: Replace ternary operators with macros min/max Bhumika Goyal
  5 siblings, 1 reply; 13+ messages in thread
From: Bhumika Goyal @ 2016-02-23 15:47 UTC (permalink / raw)
  To: outreachy-kernel; +Cc: Bhumika Goyal

Replace ternary operators with macros min/max as they are
shorter and thus increases code readability. Macro min returns the
minimum and max returns maximum of the two compared values.
Made a semantic patch for changes:

@@
type T;
T x;
T y;
@@
(
- x < y ? x : y
+ min(x,y)
|
- x > y ? x : y
+ max(x,y)
)

Signed-off-by: Bhumika Goyal <bhumirks@gmail.com>
---
Changes in v2:
Use min()/max() instead of min_t()/max_t() as the values passed in the
macros are of same type.

 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..8254428 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(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(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..b48c23e 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(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..dc2996f 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(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] 13+ messages in thread

* [PATCH v2 5/5] Staging: rts5208: Use min instead of ternary operator
  2016-02-23 15:47 [PATCH v2 0/5] Staging: Replace ternary operators with macros min/max Bhumika Goyal
                   ` (3 preceding siblings ...)
  2016-02-23 15:47 ` [PATCH v2 4/5] Staging: lustre: Use min or max " Bhumika Goyal
@ 2016-02-23 15:47 ` Bhumika Goyal
  2016-02-26 10:04 ` [PATCH v3 0/5] Staging: Replace ternary operators with macros min/max Bhumika Goyal
  5 siblings, 0 replies; 13+ messages in thread
From: Bhumika Goyal @ 2016-02-23 15:47 UTC (permalink / raw)
  To: outreachy-kernel; +Cc: Bhumika Goyal

This patch replaces ternary operator with macro min as it shorter and
thus increases code readability. Macro min returns the minimum of the
two compared values.
Made a semantic patch for changes:

@@
type T;
T x;
T y;
@@
(
- x < y ? x : y
+ min(x,y)
|
- x > y ? x : y
+ max(x,y)
)

Signed-off-by: Bhumika Goyal <bhumirks@gmail.com>
---
Changes in v2:
Use min() instead of min_t() as the values passed in the macro are of
same type.

 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..1612610 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(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(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] 13+ messages in thread

* Re: [Outreachy kernel] [PATCH v2 4/5] Staging: lustre: Use min or max instead of ternary operator
  2016-02-23 15:47 ` [PATCH v2 4/5] Staging: lustre: Use min or max " Bhumika Goyal
@ 2016-02-26  6:18   ` Greg KH
  0 siblings, 0 replies; 13+ messages in thread
From: Greg KH @ 2016-02-26  6:18 UTC (permalink / raw)
  To: Bhumika Goyal; +Cc: outreachy-kernel

On Tue, Feb 23, 2016 at 09:17:19PM +0530, Bhumika Goyal wrote:
> Replace ternary operators with macros min/max as they are
> shorter and thus increases code readability. Macro min returns the
> minimum and max returns maximum of the two compared values.
> Made a semantic patch for changes:
> 
> @@
> type T;
> T x;
> T y;
> @@
> (
> - x < y ? x : y
> + min(x,y)
> |
> - x > y ? x : y
> + max(x,y)
> )
> 
> Signed-off-by: Bhumika Goyal <bhumirks@gmail.com>
> ---
> Changes in v2:
> Use min()/max() instead of min_t()/max_t() as the values passed in the
> macros are of same type.
> 
>  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..8254428 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(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(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..b48c23e 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(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..dc2996f 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(0, svcpt->scp_cpt));
>  
>  	if (new_seq > svcpt->scp_hist_seq) {
>  		/* This handles the initial case of scp_hist_seq == 0 or

Doesn't apply due to other changes in this code from other developers.
Please rebase and resend.

thanks,

greg k-h


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

* [PATCH v3 0/5] Staging: Replace ternary operators with macros min/max
  2016-02-23 15:47 [PATCH v2 0/5] Staging: Replace ternary operators with macros min/max Bhumika Goyal
                   ` (4 preceding siblings ...)
  2016-02-23 15:47 ` [PATCH v2 5/5] Staging: rts5208: Use min " Bhumika Goyal
@ 2016-02-26 10:04 ` Bhumika Goyal
  2016-02-26 10:04   ` [PATCH v3 1/5] Staging: rtl8723au: Use min macro instead of ternary operator Bhumika Goyal
                     ` (4 more replies)
  5 siblings, 5 replies; 13+ messages in thread
From: Bhumika Goyal @ 2016-02-26 10:04 UTC (permalink / raw)
  To: outreachy-kernel; +Cc: Bhumika Goyal

This patchset replaces ternary operators with macros min/max as
they are shorter and thus increases code readability. Macro min returns
the minimum and macro max returns maximum  of the two compared values.
Made a semantic patch for changes:

@@
type T;
T x;
T y;
@@
(
- x < y ? x : y
+ min(x,y)
|
- x > y ? x : y
+ max(x,y)
)

Changes in v2:
* Use min()/max() instead of min_t()/max_t() as the values passed in the
  macros are of same type. 
Changes in v3:
* No change.

Bhumika Goyal (5):
  Staging: rtl8723au: Use min macro instead of ternary operator
  Staging: rdma: Use min macro instead of ternary operator
  Staging: gdm724x: Use min instead of ternary operator
  Staging: lustre: Use min or max instead of ternary operator
  Staging: rts5208: Use min 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(-)

-- 
1.9.1



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

* [PATCH v3 1/5] Staging: rtl8723au: Use min macro instead of ternary operator
  2016-02-26 10:04 ` [PATCH v3 0/5] Staging: Replace ternary operators with macros min/max Bhumika Goyal
@ 2016-02-26 10:04   ` Bhumika Goyal
  2016-02-26 10:04   ` [PATCH v3 2/5] Staging: rdma: " Bhumika Goyal
                     ` (3 subsequent siblings)
  4 siblings, 0 replies; 13+ messages in thread
From: Bhumika Goyal @ 2016-02-26 10:04 UTC (permalink / raw)
  To: outreachy-kernel; +Cc: Bhumika Goyal

This patch replaces ternary operator with macro min as it shorter and
thus increases code readability. Macro min 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(x,y)
|
- x > y ? x : y
+ max(x,y)
)

Signed-off-by: Bhumika Goyal <bhumirks@gmail.com>
---
Changes in v2:
Use min() instead of min_t() as the values passed in the macro are of
same type.
Changes in v3:
* No change.
 
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..cf0daa1 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(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(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(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(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(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(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(16, key_len)));
 					memcpy(padapter->securitypriv.
 					       dot118021XGrptxmickey[key_index].
 					       skey, &keyparms->key[16], 8);
-- 
1.9.1



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

* [PATCH v3 2/5] Staging: rdma: Use min macro instead of ternary operator
  2016-02-26 10:04 ` [PATCH v3 0/5] Staging: Replace ternary operators with macros min/max Bhumika Goyal
  2016-02-26 10:04   ` [PATCH v3 1/5] Staging: rtl8723au: Use min macro instead of ternary operator Bhumika Goyal
@ 2016-02-26 10:04   ` Bhumika Goyal
  2016-02-26 10:04   ` [PATCH v3 3/5] Staging: gdm724x: Use min " Bhumika Goyal
                     ` (2 subsequent siblings)
  4 siblings, 0 replies; 13+ messages in thread
From: Bhumika Goyal @ 2016-02-26 10:04 UTC (permalink / raw)
  To: outreachy-kernel; +Cc: Bhumika Goyal

This patch replaces ternary operator with macro min as it shorter and
thus increases code readability. Macro min 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(x,y)
|
- x > y ? x : y
+ max(x,y)
)

Signed-off-by: Bhumika Goyal <bhumirks@gmail.com>
---
Changes in v2:
Use min() instead of min_t() as the values passed in the macro are of
same type.

Changes in v3:
* No change.

 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..64bef6c2 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(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(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(send, dend);
 
 		/* shift up to SOP=1 space */
 		dest += SOP_DISTANCE;
-- 
1.9.1



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

* [PATCH v3 3/5] Staging: gdm724x: Use min instead of ternary operator
  2016-02-26 10:04 ` [PATCH v3 0/5] Staging: Replace ternary operators with macros min/max Bhumika Goyal
  2016-02-26 10:04   ` [PATCH v3 1/5] Staging: rtl8723au: Use min macro instead of ternary operator Bhumika Goyal
  2016-02-26 10:04   ` [PATCH v3 2/5] Staging: rdma: " Bhumika Goyal
@ 2016-02-26 10:04   ` Bhumika Goyal
  2016-02-26 10:04   ` [PATCH v3 4/5] Staging: lustre: Use min or max " Bhumika Goyal
  2016-02-26 10:04   ` [PATCH v3 5/5] Staging: rts5208: Use min " Bhumika Goyal
  4 siblings, 0 replies; 13+ messages in thread
From: Bhumika Goyal @ 2016-02-26 10:04 UTC (permalink / raw)
  To: outreachy-kernel; +Cc: Bhumika Goyal

This patch replaces ternary operator with macro min as it shorter and
thus increases code readability. Macro min 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(x,y)
|
- x > y ? x : y
+ max(x,y)
)

Signed-off-by: Bhumika Goyal <bhumirks@gmail.com>
---
Changes in v2:
Use min() instead of min_t() as the values passed in the macro are of
same type.
Changes in v3:
No change

 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..6bedd66 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(ret, 0);
 }
 
 static void release_usb(struct mux_dev *mux_dev)
-- 
1.9.1



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

* [PATCH v3 4/5] Staging: lustre: Use min or max instead of ternary operator
  2016-02-26 10:04 ` [PATCH v3 0/5] Staging: Replace ternary operators with macros min/max Bhumika Goyal
                     ` (2 preceding siblings ...)
  2016-02-26 10:04   ` [PATCH v3 3/5] Staging: gdm724x: Use min " Bhumika Goyal
@ 2016-02-26 10:04   ` Bhumika Goyal
  2016-02-26 10:04   ` [PATCH v3 5/5] Staging: rts5208: Use min " Bhumika Goyal
  4 siblings, 0 replies; 13+ messages in thread
From: Bhumika Goyal @ 2016-02-26 10:04 UTC (permalink / raw)
  To: outreachy-kernel; +Cc: Bhumika Goyal

Replace ternary operators with macros min/max as they are
shorter and thus increases code readability. Macro min returns the
minimum and max returns maximum of the two compared values.
Made a semantic patch for changes:

@@
type T;
T x;
T y;
@@
(
- x < y ? x : y
+ min(x,y)
|
- x > y ? x : y
+ max(x,y)
)

Signed-off-by: Bhumika Goyal <bhumirks@gmail.com>
---
Changes in v2:
Use min()/max() instead of min_t()/max_t() as the values passed in the
macros are of same type.
Changes in v3:
No change

 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 0f06feb..c437631 100644
--- a/drivers/staging/lustre/lustre/include/lustre_disk.h
+++ b/drivers/staging/lustre/lustre/include/lustre_disk.h
@@ -337,14 +337,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(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(lcd->lcd_last_xid, lcd->lcd_last_close_xid));
 }
 
 >>>>>>> Staging: lustre: Use min_t and max_t instead of ternary operator
diff --git a/drivers/staging/lustre/lustre/osc/osc_request.c b/drivers/staging/lustre/lustre/osc/osc_request.c
index 10f262f..578e98a 100644
--- a/drivers/staging/lustre/lustre/osc/osc_request.c
+++ b/drivers/staging/lustre/lustre/osc/osc_request.c
@@ -1181,7 +1181,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(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 47be21a..9ef3b26 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/events.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/events.c
@@ -260,7 +260,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(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] 13+ messages in thread

* [PATCH v3 5/5] Staging: rts5208: Use min instead of ternary operator
  2016-02-26 10:04 ` [PATCH v3 0/5] Staging: Replace ternary operators with macros min/max Bhumika Goyal
                     ` (3 preceding siblings ...)
  2016-02-26 10:04   ` [PATCH v3 4/5] Staging: lustre: Use min or max " Bhumika Goyal
@ 2016-02-26 10:04   ` Bhumika Goyal
  4 siblings, 0 replies; 13+ messages in thread
From: Bhumika Goyal @ 2016-02-26 10:04 UTC (permalink / raw)
  To: outreachy-kernel; +Cc: Bhumika Goyal

This patch replaces ternary operator with macro min as it shorter and
thus increases code readability. Macro min returns the minimum of the
two compared values.
Made a semantic patch for changes:

@@
type T;
T x;
T y;
@@
(
- x < y ? x : y
+ min(x,y)
|
- x > y ? x : y
+ max(x,y)
)

Signed-off-by: Bhumika Goyal <bhumirks@gmail.com>
---
Changes in v2:
Use min() instead of min_t() as the values passed in the macro are of
same type.
Changes in v3:
No change

 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..1612610 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(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(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] 13+ messages in thread

end of thread, other threads:[~2016-02-26 10:05 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-23 15:47 [PATCH v2 0/5] Staging: Replace ternary operators with macros min/max Bhumika Goyal
2016-02-23 15:47 ` [PATCH v2 1/5] Staging: rtl8723au: Use min macro instead of ternary operator Bhumika Goyal
2016-02-23 15:47 ` [PATCH v2 2/5] Staging: rdma: " Bhumika Goyal
2016-02-23 15:47 ` [PATCH v2 3/5] Staging: gdm724x: Use min " Bhumika Goyal
2016-02-23 15:47 ` [PATCH v2 4/5] Staging: lustre: Use min or max " Bhumika Goyal
2016-02-26  6:18   ` [Outreachy kernel] " Greg KH
2016-02-23 15:47 ` [PATCH v2 5/5] Staging: rts5208: Use min " Bhumika Goyal
2016-02-26 10:04 ` [PATCH v3 0/5] Staging: Replace ternary operators with macros min/max Bhumika Goyal
2016-02-26 10:04   ` [PATCH v3 1/5] Staging: rtl8723au: Use min macro instead of ternary operator Bhumika Goyal
2016-02-26 10:04   ` [PATCH v3 2/5] Staging: rdma: " Bhumika Goyal
2016-02-26 10:04   ` [PATCH v3 3/5] Staging: gdm724x: Use min " Bhumika Goyal
2016-02-26 10:04   ` [PATCH v3 4/5] Staging: lustre: Use min or max " Bhumika Goyal
2016-02-26 10:04   ` [PATCH v3 5/5] Staging: rts5208: Use min " Bhumika Goyal

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.