Skip to contentSkip to conversation

staging: fbtft: replace ternary operator with min macro

PATCH Superseded Alison Schofield 2 participants 3 messages Feb 24, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: fbtft: 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/fbtft/fb_ra8875.c | 2 +-
 drivers/staging/fbtft/fbtft-bus.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/staging/fbtft/fb_ra8875.c +1 -1
index b167c50..0585e0b 100644
@@ -277,7 +277,7 @@ static int write_vmem16_bus8(struct fbtft_par *par, size_t offset, size_t len)
 		startbyte_size = 1;
 
 	while (remain) {
-		to_copy = remain > tx_array_size ? tx_array_size : remain;
+		to_copy = min(tx_array_size, remain);
 		dev_dbg(par->info->device, "    to_copy=%zu, remain=%zu\n",
 			to_copy, remain - to_copy);
 
drivers/staging/fbtft/fbtft-bus.c +2 -2
index 58449ad8..b31f111 100644
@@ -157,7 +157,7 @@ int fbtft_write_vmem16_bus8(struct fbtft_par *par, size_t offset, size_t len)
 	}
 
 	while (remain) {
-		to_copy = remain > tx_array_size ? tx_array_size : remain;
+		to_copy = min(tx_array_size, remain);
 		dev_dbg(par->info->device, "    to_copy=%zu, remain=%zu\n",
 						to_copy, remain - to_copy);
 
@@ -201,7 +201,7 @@ int fbtft_write_vmem16_bus9(struct fbtft_par *par, size_t offset, size_t len)
 	tx_array_size = par->txbuf.len / 2;
 
 	while (remain) {
-		to_copy = remain > tx_array_size ? tx_array_size : remain;
+		to_copy = min(tx_array_size, remain);
 		dev_dbg(par->info->device, "    to_copy=%zu, remain=%zu\n",
 						to_copy, remain - to_copy);
 
Signature · 1 line
2.1.4
#1 lore raw
Quoted 5 lines · Alison Schofield

Use macro min() to get the minimum of two values for brevity and readability.

Found using Coccinelle:
@ type T; T x; T y; @@

The first @ is missing.

julia

Quoted 59 lines

(
- x < y ? x : y
+ min(x,y)
|
- x > y ? x : y
+ max(x,y)
)

---
 drivers/staging/fbtft/fb_ra8875.c | 2 +-
 drivers/staging/fbtft/fbtft-bus.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/staging/fbtft/fb_ra8875.c +1 -1
index b167c50..0585e0b 100644
@@ -277,7 +277,7 @@ static int write_vmem16_bus8(struct fbtft_par *par, size_t offset, size_t len)
 		startbyte_size = 1;
 
 	while (remain) {
-		to_copy = remain > tx_array_size ? tx_array_size : remain;
+		to_copy = min(tx_array_size, remain);
 		dev_dbg(par->info->device, "    to_copy=%zu, remain=%zu\n",
 			to_copy, remain - to_copy);
 
drivers/staging/fbtft/fbtft-bus.c +2 -2
index 58449ad8..b31f111 100644
@@ -157,7 +157,7 @@ int fbtft_write_vmem16_bus8(struct fbtft_par *par, size_t offset, size_t len)
 	}
 
 	while (remain) {
-		to_copy = remain > tx_array_size ? tx_array_size : remain;
+		to_copy = min(tx_array_size, remain);
 		dev_dbg(par->info->device, "    to_copy=%zu, remain=%zu\n",
 						to_copy, remain - to_copy);
 
@@ -201,7 +201,7 @@ int fbtft_write_vmem16_bus9(struct fbtft_par *par, size_t offset, size_t len)
 	tx_array_size = par->txbuf.len / 2;
 
 	while (remain) {
-		to_copy = remain > tx_array_size ? tx_array_size : remain;
+		to_copy = min(tx_array_size, remain);
 		dev_dbg(par->info->device, "    to_copy=%zu, remain=%zu\n",
 						to_copy, remain - to_copy);
 
Signature · 8 lines
2.1.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/20160224064843.GA17889%40d830.WORKGROUP.
For more options, visit https://groups.google.com/d/optout.
#2 lore raw

PATCH v2 1/1 staging: fbtft: replace ternary operator with min macro

In reply to Alison Schofield

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)
)

---
Change in v2:
- corrected Coccinelle script

 drivers/staging/fbtft/fb_ra8875.c | 2 +-
 drivers/staging/fbtft/fbtft-bus.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/staging/fbtft/fb_ra8875.c +1 -1
index b167c50..0585e0b 100644
@@ -277,7 +277,7 @@ static int write_vmem16_bus8(struct fbtft_par *par, size_t offset, size_t len)
 		startbyte_size = 1;
 
 	while (remain) {
-		to_copy = remain > tx_array_size ? tx_array_size : remain;
+		to_copy = min(tx_array_size, remain);
 		dev_dbg(par->info->device, "    to_copy=%zu, remain=%zu\n",
 			to_copy, remain - to_copy);
 
drivers/staging/fbtft/fbtft-bus.c +2 -2
index 58449ad8..b31f111 100644
@@ -157,7 +157,7 @@ int fbtft_write_vmem16_bus8(struct fbtft_par *par, size_t offset, size_t len)
 	}
 
 	while (remain) {
-		to_copy = remain > tx_array_size ? tx_array_size : remain;
+		to_copy = min(tx_array_size, remain);
 		dev_dbg(par->info->device, "    to_copy=%zu, remain=%zu\n",
 						to_copy, remain - to_copy);
 
@@ -201,7 +201,7 @@ int fbtft_write_vmem16_bus9(struct fbtft_par *par, size_t offset, size_t len)
 	tx_array_size = par->txbuf.len / 2;
 
 	while (remain) {
-		to_copy = remain > tx_array_size ? tx_array_size : remain;
+		to_copy = min(tx_array_size, remain);
 		dev_dbg(par->info->device, "    to_copy=%zu, remain=%zu\n",
 						to_copy, remain - to_copy);
 
Signature · 1 line
2.1.4