 bnxt_en: Fix memory corruption when FW resources change during ifdown · gregkh/linux@d00e989 · GitHub Skip to content Navigation Menu Toggle navigation Sign in Appearance settings Platform AI CODE CREATION GitHub Copilot Write better code with AI GitHub Spark Build and deploy intelligent apps GitHub Models Manage and compare prompts MCP Registry New Integrate external tools DEVELOPER WORKFLOWS Actions Automate any workflow Codespaces Instant dev environments Issues Plan and track work Code Review Manage code changes APPLICATION SECURITY GitHub Advanced Security Find and fix vulnerabilities Code security Secure your code as you build Secret protection  EXPLORE Why GitHub Documentation Blog Changelog Marketplace View all features Solutions BY COMPANY SIZE Enterprises Small and medium teams Startups Nonprofits BY USE CASE App Modernization DevSecOps DevOps CI/CD View all use cases BY INDUSTRY Healthcare Financial services Manufacturing Government View all industries View all solutions Resources EXPLORE BY TOPIC AI Software Development DevOps Security View all topics EXPLORE BY TYPE Customer stories Events &amp; webinars Ebooks &amp; reports Business insights GitHub Skills SUPPORT &amp; SERVICES Documentation Customer support Community forum Trust center Partners View all resources Open Source COMMUNITY GitHub Sponsors Fund open source developers PROGRAMS Security Lab Maintainer Community Accelerator GitHub Stars Archive Program REPOSITORIES Topics Trending Collections Enterprise ENTERPRISE SOLUTIONS Enterprise platform AI-powered developer platform AVAILABLE ADD-ONS GitHub Advanced Security Enterprise-grade security features Copilot for Business Enterprise-grade AI features Premium Support Enterprise-grade 24/7 support Pricing Search or jump to... Search code, repositories, users, issues, pull requests... --> Search Clear Search syntax tips Provide feedback --> We read every piece of feedback, and take your input very seriously.  Cancel Submit feedback Saved searches Use saved searches to filter your results more quickly --> Name Query To see all available qualifiers, see our documentation . Cancel Create saved search Sign in Sign up Appearance settings Resetting focus You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert {{ message }} gregkh / linux Public Notifications You must be signed in to change notification settings Fork 686 Star 644 Code Actions Security and quality 0 Insights Additional navigation options Code Actions Security and quality Insights Commit d00e989 Browse files Browse files sreekanthbrcm authored and gregkh committed bnxt_en: Fix memory corruption when FW resources change during ifdown [ Upstream commit 2747328 ] bnxt_set_dflt_rings() assumes that it is always called before any TC has been created. So it doesn't take bp-&gt;num_tc into account and assumes that it is always 0 or 1. In the FW resource or capability change scenario, the FW will return flags in bnxt_hwrm_if_change() that will cause the driver to reinitialize and call bnxt_cancel_reservations(). This will lead to bnxt_init_dflt_ring_mode() calling bnxt_set_dflt_rings() and bp-&gt;num_tc may be greater than 1. This will cause bp-&gt;tx_ring[] to be sized too small and cause memory corruption in bnxt_alloc_cp_rings(). Fix it by properly scaling the TX rings by bp-&gt;num_tc in the code paths mentioned above. Add 2 helper functions to determine bp-&gt;tx_nr_rings and bp-&gt;tx_nr_rings_per_tc. Fixes: ec5d31e ("bnxt_en: Handle firmware reset status during IF_UP.") Reviewed-by: Kalesh AP &lt;kalesh-anakkur.purayil@broadcom.com&gt; Reviewed-by: Andy Gospodarek &lt;andrew.gospodarek@broadcom.com&gt; Signed-off-by: Sreekanth Reddy &lt;sreekanth.reddy@broadcom.com&gt; Signed-off-by: Michael Chan &lt;michael.chan@broadcom.com&gt; Link: https://patch.msgid.link/20250825175927.459987-2-michael.chan@broadcom.com Signed-off-by: Jakub Kicinski &lt;kuba@kernel.org&gt; Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt; 1 parent 3d6a89f commit d00e989 Copy full SHA for d00e989 1 file changed + 16 - 5 Lines changed: 16 additions &amp; 5 deletions File tree Expand file tree Collapse file tree Open diff view settings Filter options drivers/net/ethernet/broadcom/bnxt bnxt.c Expand file tree Collapse file tree Open diff view settings Collapse file ‎ drivers/net/ethernet/broadcom/bnxt/bnxt.c ‎ Copy file name to clipboard Expand all lines: drivers/net/ethernet/broadcom/bnxt/bnxt.c + 16 - 5 Lines changed: 16 additions &amp; 5 deletions Original file line number Diff line number Diff line change @@ -12241,6 +12241,17 @@ static int bnxt_set_xps_mapping(struct bnxt *bp) 12241 12241 return rc ; 12242 12242 } 12243 12243 12244 + static int bnxt_tx_nr_rings ( struct bnxt * bp ) 12245 + { 12246 + return bp -&gt; num_tc ? bp -&gt; tx_nr_rings_per_tc * bp -&gt; num_tc : 12247 + bp -&gt; tx_nr_rings_per_tc ; 12248 + } 12249 + 12250 + static int bnxt_tx_nr_rings_per_tc ( struct bnxt * bp ) 12251 + { 12252 + return bp -&gt; num_tc ? bp -&gt; tx_nr_rings / bp -&gt; num_tc : bp -&gt; tx_nr_rings ; 12253 + } 12254 + 12244 12255 static int __bnxt_open_nic ( struct bnxt * bp , bool irq_re_init , bool link_re_init ) 12245 12256 { 12246 12257 int rc = 0 ; @@ -15676,7 +15687,7 @@ static void bnxt_trim_dflt_sh_rings(struct bnxt *bp) 15676 15687 bp -&gt; cp_nr_rings = min_t ( int , bp -&gt; tx_nr_rings_per_tc , bp -&gt; rx_nr_rings ); 15677 15688 bp -&gt; rx_nr_rings = bp -&gt; cp_nr_rings ; 15678 15689 bp -&gt; tx_nr_rings_per_tc = bp -&gt; cp_nr_rings ; 15679 - bp -&gt; tx_nr_rings = bp -&gt; tx_nr_rings_per_tc ; 15690 + bp -&gt; tx_nr_rings = bnxt_tx_nr_rings ( bp ) ; 15680 15691 } 15681 15692 15682 15693 static int bnxt_set_dflt_rings ( struct bnxt * bp , bool sh ) @@ -15708,7 +15719,7 @@ static int bnxt_set_dflt_rings(struct bnxt *bp, bool sh) 15708 15719 bnxt_trim_dflt_sh_rings ( bp ); 15709 15720 else 15710 15721 bp -&gt; cp_nr_rings = bp -&gt; tx_nr_rings_per_tc + bp -&gt; rx_nr_rings ; 15711 - bp -&gt; tx_nr_rings = bp -&gt; tx_nr_rings_per_tc ; 15722 + bp -&gt; tx_nr_rings = bnxt_tx_nr_rings ( bp ) ; 15712 15723 15713 15724 avail_msix = bnxt_get_max_func_irqs ( bp ) - bp -&gt; cp_nr_rings ; 15714 15725 if ( avail_msix &gt;= BNXT_MIN_ROCE_CP_RINGS ) { @@ -15721,7 +15732,7 @@ static int bnxt_set_dflt_rings(struct bnxt *bp, bool sh) 15721 15732 rc = __bnxt_reserve_rings ( bp ); 15722 15733 if ( rc &amp;&amp; rc != - ENODEV ) 15723 15734 netdev_warn ( bp -&gt; dev , &quot;Unable to reserve tx rings\n&quot; ); 15724 - bp -&gt; tx_nr_rings_per_tc = bp -&gt; tx_nr_rings ; 15735 + bp -&gt; tx_nr_rings_per_tc = bnxt_tx_nr_rings_per_tc ( bp ) ; 15725 15736 if ( sh ) 15726 15737 bnxt_trim_dflt_sh_rings ( bp ); 15727 15738 @@ -15730,7 +15741,7 @@ static int bnxt_set_dflt_rings(struct bnxt *bp, bool sh) 15730 15741 rc = __bnxt_reserve_rings ( bp ); 15731 15742 if ( rc &amp;&amp; rc != - ENODEV ) 15732 15743 netdev_warn ( bp -&gt; dev , &quot;2nd rings reservation failed.\n&quot; ); 15733 - bp -&gt; tx_nr_rings_per_tc = bp -&gt; tx_nr_rings ; 15744 + bp -&gt; tx_nr_rings_per_tc = bnxt_tx_nr_rings_per_tc ( bp ) ; 15734 15745 } 15735 15746 if ( BNXT_CHIP_TYPE_NITRO_A0 ( bp )) { 15736 15747 bp -&gt; rx_nr_rings ++ ; @@ -15764,7 +15775,7 @@ static int bnxt_init_dflt_ring_mode(struct bnxt *bp) 15764 15775 if ( rc ) 15765 15776 goto init_dflt_ring_err ; 15766 15777 15767 - bp -&gt; tx_nr_rings_per_tc = bp -&gt; tx_nr_rings ; 15778 + bp -&gt; tx_nr_rings_per_tc = bnxt_tx_nr_rings_per_tc ( bp ) ; 15768 15779 15769 15780 bnxt_set_dflt_rfs ( bp ); 15770 15781 0 commit comments Comments 0 ( 0 ) Footer &copy; 2026 GitHub,&nbsp;Inc. Footer navigation Terms Privacy Security Status Community Docs Contact Manage cookies Do not share my personal information You can’t perform that action at this time. 