Skip to contentSkip to conversation

usb: musb: cppi_dma.c: use DIV_ROUND_UP macro in cppi_next_(r|t)x_segment()

PATCH Superseded Ivan Safonov 2 participants 4 messages Feb 15, 2017 – Mar 27, 2017

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

PATCH 1/1 usb: musb: cppi_dma.c: use DIV_ROUND_UP macro in cppi_next_(r|t)x_segment()

DIV_ROUND_UP is bit useful than series of "/" and "%" operations. Replace "/%" sequence with DIV_ROUND_UP macro.

---
 drivers/usb/musb/cppi_dma.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/usb/musb/cppi_dma.c +4 -6
index 1ae48e6..d376188 100644
@@ -582,9 +582,9 @@ cppi_next_tx_segment(struct musb *musb, struct cppi_channel *tx)
 		maxpacket = length;
 		n_bds = 1;
 	} else {
-		n_bds = length / maxpacket;
-		if (!length || (length % maxpacket))
-			n_bds++;
+		n_bds = DIV_ROUND_UP(length, maxpacket);
+		if (length == 0)
+			n_bds = 1;
 		n_bds = min(n_bds, (unsigned) NUM_TXCHAN_BD);
 		length = min(n_bds * maxpacket, length);
 	}
@@ -790,9 +790,7 @@ cppi_next_rx_segment(struct musb *musb, struct cppi_channel *rx, int onepacket)
 			n_bds = 0xffff / maxpacket;
 			length = n_bds * maxpacket;
 		} else {
-			n_bds = length / maxpacket;
-			if (length % maxpacket)
-				n_bds++;
+			n_bds = DIV_ROUND_UP(length, maxpacket);
 		}
 		if (n_bds == 1)
 			onepacket = 1;
Signature · 1 line
2.10.2
maintainer
#1 lore raw
Quoted 13 lines · Ivan Safonov

DIV_ROUND_UP is bit useful than series of "/" and "%" operations. Replace "/%" sequence with DIV_ROUND_UP macro.

---
 drivers/usb/musb/cppi_dma.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/usb/musb/cppi_dma.c +0 -0
index 1ae48e6..d376188 100644

drivers/usb/musb/cppi_dma.c cppi_next_tx_segment(struct musb *musb, struct cppi_channel *tx) · line 587

Quoted 9 lines
drivers/usb/musb/cppi_dma.c +3 -3
@@ -582,9 +582,9 @@ cppi_next_tx_segment(struct musb *musb, struct cppi_channel *tx)
 		maxpacket = length;
 		n_bds = 1;
 	} else {
-		n_bds = length / maxpacket;
-		if (!length || (length % maxpacket))
-			n_bds++;
+		n_bds = DIV_ROUND_UP(length, maxpacket);
+		if (length == 0)
+			n_bds = 1;

Is it a little better logically if

+ if (length)
+ n_bds = DIV_ROUND_UP(length, maxpacket);
+ else
+ n_bds = 1;

or

+ n_bds = length ? DIV_ROUND_UP(length, maxpacket) : 1;

Regards,
-Bin.

#2 lore raw

PATCH v2 1/1 usb: musb: cppi_dma.c: use DIV_ROUND_UP macro in cppi_next_(r|t)x_segment()

DIV_ROUND_UP is bit useful than series of "/" and "%" operations. Replace "/%" sequence with DIV_ROUND_UP macro.

---
Changes in v2:
- little style fix

 drivers/usb/musb/cppi_dma.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/usb/musb/cppi_dma.c +5 -6
index c4fabe95..a13bd36 100644
@@ -582,9 +582,10 @@ cppi_next_tx_segment(struct musb *musb, struct cppi_channel *tx)
 		maxpacket = length;
 		n_bds = 1;
 	} else {
-		n_bds = length / maxpacket;
-		if (!length || (length % maxpacket))
-			n_bds++;
+		if (length)
+			n_bds = DIV_ROUND_UP(length, maxpacket);
+		else
+			n_bds = 1;
 		n_bds = min(n_bds, (unsigned) NUM_TXCHAN_BD);
 		length = min(n_bds * maxpacket, length);
 	}
@@ -790,9 +791,7 @@ cppi_next_rx_segment(struct musb *musb, struct cppi_channel *rx, int onepacket)
 			n_bds = 0xffff / maxpacket;
 			length = n_bds * maxpacket;
 		} else {
-			n_bds = length / maxpacket;
-			if (length % maxpacket)
-				n_bds++;
+			n_bds = DIV_ROUND_UP(length, maxpacket);
 		}
 		if (n_bds == 1)
 			onepacket = 1;
Signature · 1 line
2.10.2
maintainer Applied
#3 lore raw
Quoted 4 lines · Ivan Safonov

DIV_ROUND_UP is bit useful than series of "/" and "%" operations. Replace "/%" sequence with DIV_ROUND_UP macro.

Applied. Thanks.
-Bin.

Quoted 39 lines

---
Changes in v2:
- little style fix

 drivers/usb/musb/cppi_dma.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/usb/musb/cppi_dma.c +5 -6
index c4fabe95..a13bd36 100644
@@ -582,9 +582,10 @@ cppi_next_tx_segment(struct musb *musb, struct cppi_channel *tx)
 		maxpacket = length;
 		n_bds = 1;
 	} else {
-		n_bds = length / maxpacket;
-		if (!length || (length % maxpacket))
-			n_bds++;
+		if (length)
+			n_bds = DIV_ROUND_UP(length, maxpacket);
+		else
+			n_bds = 1;
 		n_bds = min(n_bds, (unsigned) NUM_TXCHAN_BD);
 		length = min(n_bds * maxpacket, length);
 	}
@@ -790,9 +791,7 @@ cppi_next_rx_segment(struct musb *musb, struct cppi_channel *rx, int onepacket)
 			n_bds = 0xffff / maxpacket;
 			length = n_bds * maxpacket;
 		} else {
-			n_bds = length / maxpacket;
-			if (length % maxpacket)
-				n_bds++;
+			n_bds = DIV_ROUND_UP(length, maxpacket);
 		}
 		if (n_bds == 1)
 			onepacket = 1;
Signature · 1 line
2.10.2