Commit 00e984cb authored by Gerhard Engleder's avatar Gerhard Engleder Committed by Jakub Kicinski

tsnep: Fix tsnep_request_irq() format-overflow warning

Compiler warns about a possible format-overflow in tsnep_request_irq():
drivers/net/ethernet/engleder/tsnep_main.c:884:55: warning: 'sprintf' may write a terminating nul past the end of the destination [-Wformat-overflow=]
                         sprintf(queue->name, "%s-rx-%d", name,
                                                       ^
drivers/net/ethernet/engleder/tsnep_main.c:881:55: warning: 'sprintf' may write a terminating nul past the end of the destination [-Wformat-overflow=]
                         sprintf(queue->name, "%s-tx-%d", name,
                                                       ^
drivers/net/ethernet/engleder/tsnep_main.c:878:49: warning: '-txrx-' directive writing 6 bytes into a region of size between 5 and 25 [-Wformat-overflow=]
                         sprintf(queue->name, "%s-txrx-%d", name,
                                                 ^~~~~~

Actually overflow cannot happen. Name is limited to IFNAMSIZ, because
netdev_name() is called during ndo_open(). queue_index is single char,
because less than 10 queues are supported.

Fix warning with snprintf(). Additionally increase buffer to 32 bytes,
because those 7 additional bytes were unused anyway.
Reported-by: default avatarkernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202310182028.vmDthIUa-lkp@intel.com/Signed-off-by: default avatarGerhard Engleder <gerhard@engleder-embedded.com>
Reviewed-by: default avatarJacob Keller <jacob.e.keller@intel.com>
Link: https://lore.kernel.org/r/20231023183856.58373-1-gerhard@engleder-embedded.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent fcc017e3
...@@ -143,7 +143,7 @@ struct tsnep_rx { ...@@ -143,7 +143,7 @@ struct tsnep_rx {
struct tsnep_queue { struct tsnep_queue {
struct tsnep_adapter *adapter; struct tsnep_adapter *adapter;
char name[IFNAMSIZ + 9]; char name[IFNAMSIZ + 16];
struct tsnep_tx *tx; struct tsnep_tx *tx;
struct tsnep_rx *rx; struct tsnep_rx *rx;
......
...@@ -1830,14 +1830,14 @@ static int tsnep_request_irq(struct tsnep_queue *queue, bool first) ...@@ -1830,14 +1830,14 @@ static int tsnep_request_irq(struct tsnep_queue *queue, bool first)
dev = queue->adapter; dev = queue->adapter;
} else { } else {
if (queue->tx && queue->rx) if (queue->tx && queue->rx)
sprintf(queue->name, "%s-txrx-%d", name, snprintf(queue->name, sizeof(queue->name), "%s-txrx-%d",
queue->rx->queue_index); name, queue->rx->queue_index);
else if (queue->tx) else if (queue->tx)
sprintf(queue->name, "%s-tx-%d", name, snprintf(queue->name, sizeof(queue->name), "%s-tx-%d",
queue->tx->queue_index); name, queue->tx->queue_index);
else else
sprintf(queue->name, "%s-rx-%d", name, snprintf(queue->name, sizeof(queue->name), "%s-rx-%d",
queue->rx->queue_index); name, queue->rx->queue_index);
handler = tsnep_irq_txrx; handler = tsnep_irq_txrx;
dev = queue; dev = queue;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment