net: hinic: Use devm_kasprintf()
authorChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Mon, 11 Sep 2023 19:50:52 +0000 (21:50 +0200)
committerDavid S. Miller <davem@davemloft.net>
Wed, 13 Sep 2023 11:21:09 +0000 (12:21 +0100)
Use devm_kasprintf() instead of hand writing it.
This is less verbose and less error prone.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/huawei/hinic/hinic_tx.c

index ad47ac51a139ced95895670cf7ed340d4c10bbf7..9b60966736db537ae87e2871a977975c4c6b919d 100644 (file)
@@ -861,7 +861,7 @@ int hinic_init_txq(struct hinic_txq *txq, struct hinic_sq *sq,
        struct hinic_qp *qp = container_of(sq, struct hinic_qp, sq);
        struct hinic_dev *nic_dev = netdev_priv(netdev);
        struct hinic_hwdev *hwdev = nic_dev->hwdev;
-       int err, irqname_len;
+       int err;
 
        txq->netdev = netdev;
        txq->sq = sq;
@@ -882,15 +882,13 @@ int hinic_init_txq(struct hinic_txq *txq, struct hinic_sq *sq,
                goto err_alloc_free_sges;
        }
 
-       irqname_len = snprintf(NULL, 0, "%s_txq%d", netdev->name, qp->q_id) + 1;
-       txq->irq_name = devm_kzalloc(&netdev->dev, irqname_len, GFP_KERNEL);
+       txq->irq_name = devm_kasprintf(&netdev->dev, GFP_KERNEL, "%s_txq%d",
+                                      netdev->name, qp->q_id);
        if (!txq->irq_name) {
                err = -ENOMEM;
                goto err_alloc_irqname;
        }
 
-       sprintf(txq->irq_name, "%s_txq%d", netdev->name, qp->q_id);
-
        err = hinic_hwdev_hw_ci_addr_set(hwdev, sq, CI_UPDATE_NO_PENDING,
                                         CI_UPDATE_NO_COALESC);
        if (err)