Skip to contentSkip to conversation

mt76: usb: reduce code indentation in mt76u_alloc_tx

PATCH Superseded Lorenzo Bianconi 3 participants 3 messages Mar 2, 2019 – Mar 4, 2019 1 message not in the archive

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Lorenzo Bianconi

author maintainer
#1 lore raw

PATCH 1/1 mt76: usb: reduce code indentation in mt76u_alloc_tx

Improve code readability reducing code indentation in mt76u_alloc_tx

---
 drivers/net/wireless/mediatek/mt76/usb.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/net/wireless/mediatek/mt76/usb.c +9 -8
index 4c1abd492405..c30878d2dc5c 100644
@@ -787,6 +787,7 @@ static int mt76u_alloc_tx(struct mt76_dev *dev)
 {
 	struct mt76u_buf *buf;
 	struct mt76_queue *q;
+	size_t size;
 	int i, j;
 
 	for (i = 0; i < IEEE80211_NUM_ACS; i++) {
@@ -810,15 +811,15 @@ static int mt76u_alloc_tx(struct mt76_dev *dev)
 			if (!buf->urb)
 				return -ENOMEM;
 
-			if (dev->usb.sg_en) {
-				size_t size = MT_SG_MAX_SIZE *
-					      sizeof(struct scatterlist);
+			if (!dev->usb.sg_en)
+				continue;
 
-				buf->urb->sg = devm_kzalloc(dev->dev, size,
-							    GFP_KERNEL);
-				if (!buf->urb->sg)
-					return -ENOMEM;
-			}
+			size = MT_SG_MAX_SIZE * sizeof(struct scatterlist);
+
+			buf->urb->sg = devm_kzalloc(dev->dev, size,
+						    GFP_KERNEL);
+			if (!buf->urb->sg)
+				return -ENOMEM;
 		}
 	}
 	return 0;
Signature · 1 line
2.20.1
#2 lore raw
Quoted 2 lines · Lorenzo Bianconi

Improve code readability reducing code indentation in mt76u_alloc_tx

Trivial note below:

drivers/net/wireless/mediatek/mt76/usb.c

Quoted 1 line
drivers/net/wireless/mediatek/mt76/usb.c +0 -0

[]

Quoted 17 lines
drivers/net/wireless/mediatek/mt76/usb.c +3 -3
@@ -787,6 +787,7 @@ static int mt76u_alloc_tx(struct mt76_dev *dev)
 {
 	struct mt76u_buf *buf;
 	struct mt76_queue *q;
+	size_t size;
 	int i, j;
 
 	for (i = 0; i < IEEE80211_NUM_ACS; i++) {
@@ -810,15 +811,15 @@ static int mt76u_alloc_tx(struct mt76_dev *dev)
 			if (!buf->urb)
 				return -ENOMEM;
 
-			if (dev->usb.sg_en) {
-				size_t size = MT_SG_MAX_SIZE *
-					      sizeof(struct scatterlist);
+			if (!dev->usb.sg_en)
+				continue;

drivers/net/wireless/mediatek/mt76/usb.c static int mt76u_alloc_tx(struct mt76_dev *dev) · line 820

Quoted 10 lines
drivers/net/wireless/mediatek/mt76/usb.c +4 -5
 
-				buf->urb->sg = devm_kzalloc(dev->dev, size,
-							    GFP_KERNEL);
-				if (!buf->urb->sg)
-					return -ENOMEM;
-			}
+			size = MT_SG_MAX_SIZE * sizeof(struct scatterlist);
+
+			buf->urb->sg = devm_kzalloc(dev->dev, size,
+						    GFP_KERNEL);

Perhaps eliminate size and use devm_kcalloc instead like the allocation immediately above this.

---
 drivers/net/wireless/mediatek/mt76/usb.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/net/wireless/mediatek/mt76/usb.c +9 -9
index ae6ada370597..fc87ae223f8d 100644
@@ -806,15 +806,15 @@ static int mt76u_alloc_tx(struct mt76_dev *dev)
 			if (!buf->urb)
 				return -ENOMEM;
 
-			if (dev->usb.sg_en) {
-				size_t size = MT_SG_MAX_SIZE *
-					      sizeof(struct scatterlist);
-
-				buf->urb->sg = devm_kzalloc(dev->dev, size,
-							    GFP_KERNEL);
-				if (!buf->urb->sg)
-					return -ENOMEM;
-			}
+			if (!dev->usb.sg_en)
+				continue;
+
+			buf->urb->sg = devm_kcalloc(dev->dev,
+						    MT_SG_MAX_SIZE,
+						    sizeof(*buf->urb->sg),
+						    GFP_KERNEL);
+			if (!buf->urb->sg)
+				return -ENOMEM;
 		}
 	}
 	return 0;
#3 lore raw
Quoted 62 lines · Lorenzo Bianconi
Quoted 2 lines

Improve code readability reducing code indentation in mt76u_alloc_tx

Trivial note below:

drivers/net/wireless/mediatek/mt76/usb.c

Quoted 1 line
drivers/net/wireless/mediatek/mt76/usb.c +0 -0

[]

Quoted 17 lines
drivers/net/wireless/mediatek/mt76/usb.c +3 -3
@@ -787,6 +787,7 @@ static int mt76u_alloc_tx(struct mt76_dev *dev)
 {
 	struct mt76u_buf *buf;
 	struct mt76_queue *q;
+	size_t size;
 	int i, j;
 
 	for (i = 0; i < IEEE80211_NUM_ACS; i++) {
@@ -810,15 +811,15 @@ static int mt76u_alloc_tx(struct mt76_dev *dev)
 			if (!buf->urb)
 				return -ENOMEM;
 
-			if (dev->usb.sg_en) {
-				size_t size = MT_SG_MAX_SIZE *
-					      sizeof(struct scatterlist);
+			if (!dev->usb.sg_en)
+				continue;

drivers/net/wireless/mediatek/mt76/usb.c static int mt76u_alloc_tx(struct mt76_dev *dev) · line 820

Quoted 10 lines
drivers/net/wireless/mediatek/mt76/usb.c +4 -5
 
-				buf->urb->sg = devm_kzalloc(dev->dev, size,
-							    GFP_KERNEL);
-				if (!buf->urb->sg)
-					return -ENOMEM;
-			}
+			size = MT_SG_MAX_SIZE * sizeof(struct scatterlist);
+
+			buf->urb->sg = devm_kzalloc(dev->dev, size,
+						    GFP_KERNEL);

Perhaps eliminate size and use devm_kcalloc instead like the allocation immediately above this.

---
 drivers/net/wireless/mediatek/mt76/usb.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/net/wireless/mediatek/mt76/usb.c +2 -9
index ae6ada370597..fc87ae223f8d 100644
@@ -806,15 +806,15 @@ static int mt76u_alloc_tx(struct mt76_dev *dev)
 			if (!buf->urb)
 				return -ENOMEM;
 
-			if (dev->usb.sg_en) {
-				size_t size = MT_SG_MAX_SIZE *
-					      sizeof(struct scatterlist);
-
-				buf->urb->sg = devm_kzalloc(dev->dev, size,
-							    GFP_KERNEL);
-				if (!buf->urb->sg)
-					return -ENOMEM;
-			}
+			if (!dev->usb.sg_en)
+				continue;

drivers/net/wireless/mediatek/mt76/usb.c static int mt76u_alloc_tx(struct mt76_dev *dev) · line 820

Quoted 10 lines
drivers/net/wireless/mediatek/mt76/usb.c +7 -0
+
+			buf->urb->sg = devm_kcalloc(dev->dev,
+						    MT_SG_MAX_SIZE,
+						    sizeof(*buf->urb->sg),
+						    GFP_KERNEL);
+			if (!buf->urb->sg)
+				return -ENOMEM;
 		}
 	}
 	return 0;

ack, I will post a v2, thx

Regards,
Lorenzo

Quoted 1 line