diff mbox series

[net-next,v2,2/2] netdev: Enforce index cap in netdev_get_tx_queue

Message ID 20230321150725.127229-2-nnac123@linux.ibm.com (mailing list archive)
State Accepted
Commit 1cc6571f562774f1d928dc8b3cff50829b86e970
Delegated to: Netdev Maintainers
Headers show
Series [net-next,v2,1/2] net: Catch invalid index in XPS mapping | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next, async
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 4299 this patch: 4299
netdev/cc_maintainers fail 4 maintainers not CCed: kuba@kernel.org edumazet@google.com pabeni@redhat.com davem@davemloft.net
netdev/build_clang success Errors and warnings before: 972 this patch: 972
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 4508 this patch: 4508
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 7 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Nick Child March 21, 2023, 3:07 p.m. UTC
When requesting a TX queue at a given index, warn on out-of-bounds
referencing if the index is greater than the allocated number of
queues.

Specifically, since this function is used heavily in the networking
stack use DEBUG_NET_WARN_ON_ONCE to avoid executing a new branch on
every packet.

Signed-off-by: Nick Child <nnac123@linux.ibm.com>
---
Changes since v1 (respond to Jakubs review):
 - send to net-next instead of net
 - use DEBUG_NET_WARN_ON_ONCE instead of a conditonal returning 1st queue

v1 - https://lore.kernel.org/netdev/20230320214942.38395e6e@kicinski-fedora-PC1C0HJN/

 include/linux/netdevice.h | 1 +
 1 file changed, 1 insertion(+)
diff mbox series

Patch

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 23b0d7eaaadd..838b7310a80b 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -2482,6 +2482,7 @@  static inline
 struct netdev_queue *netdev_get_tx_queue(const struct net_device *dev,
 					 unsigned int index)
 {
+	DEBUG_NET_WARN_ON_ONCE(index >= dev->num_tx_queues);
 	return &dev->_tx[index];
 }