[net-next] hinic: Use devm_kasprintf instead of hard coding it
diff mbox series

Message ID 20190613195412.1702-1-christophe.jaillet@wanadoo.fr
State Accepted
Delegated to: David Miller
Headers show
Series
  • [net-next] hinic: Use devm_kasprintf instead of hard coding it
Related show

Commit Message

Christophe JAILLET June 13, 2019, 7:54 p.m. UTC
'devm_kasprintf' is less verbose than:
   snprintf(NULL, 0, ...);
   devm_kzalloc(...);
   sprintf
so use it instead.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/net/ethernet/huawei/hinic/hinic_rx.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

Comments

Christophe JAILLET June 14, 2019, 12:11 p.m. UTC | #1
Hi,

I got a:

<aviad.krawczyk@huawei.com>: host huawei.com[103.218.216.136] said: 550
5.1.1 Error: invalid recipients is found from 80.12.242.127

However, MAINTAINERS has:
   HUAWEI ETHERNET DRIVER
   M:	Aviad Krawczyk <aviad.krawczyk@huawei.com>
   L:	netdev@vger.kernel.org
   S:	Supported
   F:	Documentation/networking/hinic.txt
   F:	drivers/net/ethernet/huawei/hinic/

I don't know how this should be fixed (neither if it should be...), so if s.o. knows, please do.

Best regards,
Christophe Jaillet

Le 13/06/2019 à 21:54, Christophe JAILLET a écrit :
> 'devm_kasprintf' is less verbose than:
>     snprintf(NULL, 0, ...);
>     devm_kzalloc(...);
>     sprintf
> so use it instead.
>
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
>   drivers/net/ethernet/huawei/hinic/hinic_rx.c | 8 +++-----
>   1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/net/ethernet/huawei/hinic/hinic_rx.c b/drivers/net/ethernet/huawei/hinic/hinic_rx.c
> index 9b4082557ad5..95b09fd110d3 100644
> --- a/drivers/net/ethernet/huawei/hinic/hinic_rx.c
> +++ b/drivers/net/ethernet/huawei/hinic/hinic_rx.c
> @@ -493,7 +493,7 @@ int hinic_init_rxq(struct hinic_rxq *rxq, struct hinic_rq *rq,
>   		   struct net_device *netdev)
>   {
>   	struct hinic_qp *qp = container_of(rq, struct hinic_qp, rq);
> -	int err, pkts, irqname_len;
> +	int err, pkts;
>   
>   	rxq->netdev = netdev;
>   	rxq->rq = rq;
> @@ -502,13 +502,11 @@ int hinic_init_rxq(struct hinic_rxq *rxq, struct hinic_rq *rq,
>   
>   	rxq_stats_init(rxq);
>   
> -	irqname_len = snprintf(NULL, 0, "hinic_rxq%d", qp->q_id) + 1;
> -	rxq->irq_name = devm_kzalloc(&netdev->dev, irqname_len, GFP_KERNEL);
> +	rxq->irq_name = devm_kasprintf(&netdev->dev, GFP_KERNEL,
> +				       "hinic_rxq%d", qp->q_id);
>   	if (!rxq->irq_name)
>   		return -ENOMEM;
>   
> -	sprintf(rxq->irq_name, "hinic_rxq%d", qp->q_id);
> -
>   	pkts = rx_alloc_pkts(rxq);
>   	if (!pkts) {
>   		err = -ENOMEM;
Julia Lawall June 14, 2019, 12:21 p.m. UTC | #2
On Fri, 14 Jun 2019, Christophe JAILLET wrote:

> Hi,
>
> I got a:
>
> <aviad.krawczyk@huawei.com>: host huawei.com[103.218.216.136] said: 550
> 5.1.1 Error: invalid recipients is found from 80.12.242.127
>
> However, MAINTAINERS has:
>   HUAWEI ETHERNET DRIVER
>   M:	Aviad Krawczyk <aviad.krawczyk@huawei.com>
>   L:	netdev@vger.kernel.org
>   S:	Supported
>   F:	Documentation/networking/hinic.txt
>   F:	drivers/net/ethernet/huawei/hinic/
>
> I don't know how this should be fixed (neither if it should be...), so if s.o.
> knows, please do.

Maybe this person would know, since he is also from Huawei and has signed
off on a patch by Aviad Krawczyk:

cde66f24c3bf42123647c5233447c5790d92557f
Signed-off-by: Zhao Chen <zhaochen6@huawei.com>

julia

>
> Best regards,
> Christophe Jaillet
>
> Le 13/06/2019 à 21:54, Christophe JAILLET a écrit :
> > 'devm_kasprintf' is less verbose than:
> >     snprintf(NULL, 0, ...);
> >     devm_kzalloc(...);
> >     sprintf
> > so use it instead.
> >
> > Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> > ---
> >   drivers/net/ethernet/huawei/hinic/hinic_rx.c | 8 +++-----
> >   1 file changed, 3 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/net/ethernet/huawei/hinic/hinic_rx.c
> > b/drivers/net/ethernet/huawei/hinic/hinic_rx.c
> > index 9b4082557ad5..95b09fd110d3 100644
> > --- a/drivers/net/ethernet/huawei/hinic/hinic_rx.c
> > +++ b/drivers/net/ethernet/huawei/hinic/hinic_rx.c
> > @@ -493,7 +493,7 @@ int hinic_init_rxq(struct hinic_rxq *rxq, struct
> > hinic_rq *rq,
> >   		   struct net_device *netdev)
> >   {
> >   	struct hinic_qp *qp = container_of(rq, struct hinic_qp, rq);
> > -	int err, pkts, irqname_len;
> > +	int err, pkts;
> >     	rxq->netdev = netdev;
> >   	rxq->rq = rq;
> > @@ -502,13 +502,11 @@ int hinic_init_rxq(struct hinic_rxq *rxq, struct
> > hinic_rq *rq,
> >     	rxq_stats_init(rxq);
> >   -	irqname_len = snprintf(NULL, 0, "hinic_rxq%d", qp->q_id) + 1;
> > -	rxq->irq_name = devm_kzalloc(&netdev->dev, irqname_len, GFP_KERNEL);
> > +	rxq->irq_name = devm_kasprintf(&netdev->dev, GFP_KERNEL,
> > +				       "hinic_rxq%d", qp->q_id);
> >   	if (!rxq->irq_name)
> >   		return -ENOMEM;
> >   -	sprintf(rxq->irq_name, "hinic_rxq%d", qp->q_id);
> > -
> >   	pkts = rx_alloc_pkts(rxq);
> >   	if (!pkts) {
> >   		err = -ENOMEM;
>
>
>
David Miller June 15, 2019, 8:38 p.m. UTC | #3
From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Date: Thu, 13 Jun 2019 21:54:12 +0200

> 'devm_kasprintf' is less verbose than:
>    snprintf(NULL, 0, ...);
>    devm_kzalloc(...);
>    sprintf
> so use it instead.
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Applied.

Patch
diff mbox series

diff --git a/drivers/net/ethernet/huawei/hinic/hinic_rx.c b/drivers/net/ethernet/huawei/hinic/hinic_rx.c
index 9b4082557ad5..95b09fd110d3 100644
--- a/drivers/net/ethernet/huawei/hinic/hinic_rx.c
+++ b/drivers/net/ethernet/huawei/hinic/hinic_rx.c
@@ -493,7 +493,7 @@  int hinic_init_rxq(struct hinic_rxq *rxq, struct hinic_rq *rq,
 		   struct net_device *netdev)
 {
 	struct hinic_qp *qp = container_of(rq, struct hinic_qp, rq);
-	int err, pkts, irqname_len;
+	int err, pkts;
 
 	rxq->netdev = netdev;
 	rxq->rq = rq;
@@ -502,13 +502,11 @@  int hinic_init_rxq(struct hinic_rxq *rxq, struct hinic_rq *rq,
 
 	rxq_stats_init(rxq);
 
-	irqname_len = snprintf(NULL, 0, "hinic_rxq%d", qp->q_id) + 1;
-	rxq->irq_name = devm_kzalloc(&netdev->dev, irqname_len, GFP_KERNEL);
+	rxq->irq_name = devm_kasprintf(&netdev->dev, GFP_KERNEL,
+				       "hinic_rxq%d", qp->q_id);
 	if (!rxq->irq_name)
 		return -ENOMEM;
 
-	sprintf(rxq->irq_name, "hinic_rxq%d", qp->q_id);
-
 	pkts = rx_alloc_pkts(rxq);
 	if (!pkts) {
 		err = -ENOMEM;