diff mbox series

mt76: usb: reduce code indentation in mt76u_alloc_tx

Message ID 2ead6e0fc3222faa772a37d55736c03041c90a1f.1551534029.git.lorenzo@kernel.org (mailing list archive)
State Changes Requested
Delegated to: Felix Fietkau
Headers show
Series mt76: usb: reduce code indentation in mt76u_alloc_tx | expand

Commit Message

Lorenzo Bianconi March 2, 2019, 1:50 p.m. UTC
Improve code readability reducing code indentation in
mt76u_alloc_tx

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 drivers/net/wireless/mediatek/mt76/usb.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

Comments

Joe Perches March 2, 2019, 8:30 p.m. UTC | #1
On Sat, 2019-03-02 at 14:50 +0100, Lorenzo Bianconi wrote:
> Improve code readability reducing code indentation in
> mt76u_alloc_tx

Trivial note below:

> diff --git a/drivers/net/wireless/mediatek/mt76/usb.c b/drivers/net/wireless/mediatek/mt76/usb.c
[]
> @@ -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);

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

diff --git a/drivers/net/wireless/mediatek/mt76/usb.c b/drivers/net/wireless/mediatek/mt76/usb.c
index ae6ada370597..fc87ae223f8d 100644
--- a/drivers/net/wireless/mediatek/mt76/usb.c
+++ b/drivers/net/wireless/mediatek/mt76/usb.c
@@ -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;
Lorenzo Bianconi March 4, 2019, 11:41 a.m. UTC | #2
> On Sat, 2019-03-02 at 14:50 +0100, Lorenzo Bianconi wrote:
> > Improve code readability reducing code indentation in
> > mt76u_alloc_tx
> 
> Trivial note below:
> 
> > diff --git a/drivers/net/wireless/mediatek/mt76/usb.c b/drivers/net/wireless/mediatek/mt76/usb.c
> []
> > @@ -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);
> 
> 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(-)
> 
> diff --git a/drivers/net/wireless/mediatek/mt76/usb.c b/drivers/net/wireless/mediatek/mt76/usb.c
> index ae6ada370597..fc87ae223f8d 100644
> --- a/drivers/net/wireless/mediatek/mt76/usb.c
> +++ b/drivers/net/wireless/mediatek/mt76/usb.c
> @@ -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;
> 

ack, I will post a v2, thx

Regards,
Lorenzo

>
diff mbox series

Patch

diff --git a/drivers/net/wireless/mediatek/mt76/usb.c b/drivers/net/wireless/mediatek/mt76/usb.c
index 4c1abd492405..c30878d2dc5c 100644
--- a/drivers/net/wireless/mediatek/mt76/usb.c
+++ b/drivers/net/wireless/mediatek/mt76/usb.c
@@ -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;