Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

octeontx2-af: Fix error handling

This commit adds error handling and rollback logic to
rvu_mbox_handler_attach_resources() to properly clean up partially
attached resources when rvu_attach_block() fails.

Fixes: 746ea74241fa0 ("octeontx2-af: Add RVU block LF provisioning support")
Signed-off-by: Ratheesh Kannoth <rkannoth@marvell.com>
Link: https://patch.msgid.link/20260121033934.1900761-1-rkannoth@marvell.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Ratheesh Kannoth and committed by
Jakub Kicinski
19e4175e e8ca461f

+64 -22
+64 -22
drivers/net/ethernet/marvell/octeontx2/af/rvu.c
··· 1551 1551 return -ENODEV; 1552 1552 } 1553 1553 1554 - static void rvu_attach_block(struct rvu *rvu, int pcifunc, int blktype, 1555 - int num_lfs, struct rsrc_attach *attach) 1554 + static int rvu_attach_block(struct rvu *rvu, int pcifunc, int blktype, 1555 + int num_lfs, struct rsrc_attach *attach) 1556 1556 { 1557 1557 struct rvu_pfvf *pfvf = rvu_get_pfvf(rvu, pcifunc); 1558 1558 struct rvu_hwinfo *hw = rvu->hw; ··· 1562 1562 u64 cfg; 1563 1563 1564 1564 if (!num_lfs) 1565 - return; 1565 + return -EINVAL; 1566 1566 1567 1567 blkaddr = rvu_get_attach_blkaddr(rvu, blktype, pcifunc, attach); 1568 1568 if (blkaddr < 0) 1569 - return; 1569 + return -EFAULT; 1570 1570 1571 1571 block = &hw->block[blkaddr]; 1572 1572 if (!block->lf.bmap) 1573 - return; 1573 + return -ESRCH; 1574 1574 1575 1575 for (slot = 0; slot < num_lfs; slot++) { 1576 1576 /* Allocate the resource */ 1577 1577 lf = rvu_alloc_rsrc(&block->lf); 1578 1578 if (lf < 0) 1579 - return; 1579 + return -EFAULT; 1580 1580 1581 1581 cfg = (1ULL << 63) | (pcifunc << 8) | slot; 1582 1582 rvu_write64(rvu, blkaddr, block->lfcfg_reg | ··· 1587 1587 /* Set start MSIX vector for this LF within this PF/VF */ 1588 1588 rvu_set_msix_offset(rvu, pfvf, block, lf); 1589 1589 } 1590 + 1591 + return 0; 1590 1592 } 1591 1593 1592 1594 static int rvu_check_rsrc_availability(struct rvu *rvu, ··· 1726 1724 int err; 1727 1725 1728 1726 /* If first request, detach all existing attached resources */ 1729 - if (!attach->modify) 1730 - rvu_detach_rsrcs(rvu, NULL, pcifunc); 1727 + if (!attach->modify) { 1728 + err = rvu_detach_rsrcs(rvu, NULL, pcifunc); 1729 + if (err) 1730 + return err; 1731 + } 1731 1732 1732 1733 mutex_lock(&rvu->rsrc_lock); 1733 1734 1734 1735 /* Check if the request can be accommodated */ 1735 1736 err = rvu_check_rsrc_availability(rvu, attach, pcifunc); 1736 1737 if (err) 1737 - goto exit; 1738 + goto fail1; 1738 1739 1739 1740 /* Now attach the requested resources */ 1740 - if (attach->npalf) 1741 - rvu_attach_block(rvu, pcifunc, BLKTYPE_NPA, 1, attach); 1741 + if (attach->npalf) { 1742 + err = rvu_attach_block(rvu, pcifunc, BLKTYPE_NPA, 1, attach); 1743 + if (err) 1744 + goto fail1; 1745 + } 1742 1746 1743 - if (attach->nixlf) 1744 - rvu_attach_block(rvu, pcifunc, BLKTYPE_NIX, 1, attach); 1747 + if (attach->nixlf) { 1748 + err = rvu_attach_block(rvu, pcifunc, BLKTYPE_NIX, 1, attach); 1749 + if (err) 1750 + goto fail2; 1751 + } 1745 1752 1746 1753 if (attach->sso) { 1747 1754 /* RVU func doesn't know which exact LF or slot is attached ··· 1760 1749 */ 1761 1750 if (attach->modify) 1762 1751 rvu_detach_block(rvu, pcifunc, BLKTYPE_SSO); 1763 - rvu_attach_block(rvu, pcifunc, BLKTYPE_SSO, 1764 - attach->sso, attach); 1752 + err = rvu_attach_block(rvu, pcifunc, BLKTYPE_SSO, 1753 + attach->sso, attach); 1754 + if (err) 1755 + goto fail3; 1765 1756 } 1766 1757 1767 1758 if (attach->ssow) { 1768 1759 if (attach->modify) 1769 1760 rvu_detach_block(rvu, pcifunc, BLKTYPE_SSOW); 1770 - rvu_attach_block(rvu, pcifunc, BLKTYPE_SSOW, 1771 - attach->ssow, attach); 1761 + err = rvu_attach_block(rvu, pcifunc, BLKTYPE_SSOW, 1762 + attach->ssow, attach); 1763 + if (err) 1764 + goto fail4; 1772 1765 } 1773 1766 1774 1767 if (attach->timlfs) { 1775 1768 if (attach->modify) 1776 1769 rvu_detach_block(rvu, pcifunc, BLKTYPE_TIM); 1777 - rvu_attach_block(rvu, pcifunc, BLKTYPE_TIM, 1778 - attach->timlfs, attach); 1770 + err = rvu_attach_block(rvu, pcifunc, BLKTYPE_TIM, 1771 + attach->timlfs, attach); 1772 + if (err) 1773 + goto fail5; 1779 1774 } 1780 1775 1781 1776 if (attach->cptlfs) { 1782 1777 if (attach->modify && 1783 1778 rvu_attach_from_same_block(rvu, BLKTYPE_CPT, attach)) 1784 1779 rvu_detach_block(rvu, pcifunc, BLKTYPE_CPT); 1785 - rvu_attach_block(rvu, pcifunc, BLKTYPE_CPT, 1786 - attach->cptlfs, attach); 1780 + err = rvu_attach_block(rvu, pcifunc, BLKTYPE_CPT, 1781 + attach->cptlfs, attach); 1782 + if (err) 1783 + goto fail6; 1787 1784 } 1788 1785 1789 - exit: 1786 + mutex_unlock(&rvu->rsrc_lock); 1787 + return 0; 1788 + 1789 + fail6: 1790 + if (attach->timlfs) 1791 + rvu_detach_block(rvu, pcifunc, BLKTYPE_TIM); 1792 + 1793 + fail5: 1794 + if (attach->ssow) 1795 + rvu_detach_block(rvu, pcifunc, BLKTYPE_SSOW); 1796 + 1797 + fail4: 1798 + if (attach->sso) 1799 + rvu_detach_block(rvu, pcifunc, BLKTYPE_SSO); 1800 + 1801 + fail3: 1802 + if (attach->nixlf) 1803 + rvu_detach_block(rvu, pcifunc, BLKTYPE_NIX); 1804 + 1805 + fail2: 1806 + if (attach->npalf) 1807 + rvu_detach_block(rvu, pcifunc, BLKTYPE_NPA); 1808 + 1809 + fail1: 1790 1810 mutex_unlock(&rvu->rsrc_lock); 1791 1811 return err; 1792 1812 }