@@ -1846,7 +1846,21 @@ static void npc_parser_profile_init(struct rvu *rvu, int blkaddr)
1846
1846
npc_program_kpu_profile (rvu , blkaddr , idx , & rvu -> kpu .kpu [idx ]);
1847
1847
}
1848
1848
1849
- static int npc_mcam_rsrcs_init (struct rvu * rvu , int blkaddr )
1849
+ void npc_mcam_rsrcs_deinit (struct rvu * rvu )
1850
+ {
1851
+ struct npc_mcam * mcam = & rvu -> hw -> mcam ;
1852
+
1853
+ kfree (mcam -> bmap );
1854
+ kfree (mcam -> bmap_reverse );
1855
+ kfree (mcam -> entry2pfvf_map );
1856
+ kfree (mcam -> cntr2pfvf_map );
1857
+ kfree (mcam -> entry2cntr_map );
1858
+ kfree (mcam -> cntr_refcnt );
1859
+ kfree (mcam -> entry2target_pffunc );
1860
+ kfree (mcam -> counters .bmap );
1861
+ }
1862
+
1863
+ int npc_mcam_rsrcs_init (struct rvu * rvu , int blkaddr )
1850
1864
{
1851
1865
int nixlf_count = rvu_get_nixlf_count (rvu );
1852
1866
struct npc_mcam * mcam = & rvu -> hw -> mcam ;
@@ -1890,24 +1904,23 @@ static int npc_mcam_rsrcs_init(struct rvu *rvu, int blkaddr)
1890
1904
mcam -> pf_offset = mcam -> nixlf_offset + nixlf_count ;
1891
1905
1892
1906
/* Allocate bitmaps for managing MCAM entries */
1893
- mcam -> bmap = devm_kcalloc ( rvu -> dev , BITS_TO_LONGS (mcam -> bmap_entries ),
1894
- sizeof (long ), GFP_KERNEL );
1907
+ mcam -> bmap = kmalloc_array ( BITS_TO_LONGS (mcam -> bmap_entries ),
1908
+ sizeof (long ), GFP_KERNEL );
1895
1909
if (!mcam -> bmap )
1896
1910
return - ENOMEM ;
1897
1911
1898
- mcam -> bmap_reverse = devm_kcalloc (rvu -> dev ,
1899
- BITS_TO_LONGS (mcam -> bmap_entries ),
1900
- sizeof (long ), GFP_KERNEL );
1912
+ mcam -> bmap_reverse = kmalloc_array (BITS_TO_LONGS (mcam -> bmap_entries ),
1913
+ sizeof (long ), GFP_KERNEL );
1901
1914
if (!mcam -> bmap_reverse )
1902
- return - ENOMEM ;
1915
+ goto free_bmap ;
1903
1916
1904
1917
mcam -> bmap_fcnt = mcam -> bmap_entries ;
1905
1918
1906
1919
/* Alloc memory for saving entry to RVU PFFUNC allocation mapping */
1907
- mcam -> entry2pfvf_map = devm_kcalloc ( rvu -> dev , mcam -> bmap_entries ,
1908
- sizeof (u16 ), GFP_KERNEL );
1920
+ mcam -> entry2pfvf_map = kmalloc_array ( mcam -> bmap_entries ,
1921
+ sizeof (u16 ), GFP_KERNEL );
1909
1922
if (!mcam -> entry2pfvf_map )
1910
- return - ENOMEM ;
1923
+ goto free_bmap_reverse ;
1911
1924
1912
1925
/* Reserve 1/8th of MCAM entries at the bottom for low priority
1913
1926
* allocations and another 1/8th at the top for high priority
@@ -1926,31 +1939,31 @@ static int npc_mcam_rsrcs_init(struct rvu *rvu, int blkaddr)
1926
1939
*/
1927
1940
err = rvu_alloc_bitmap (& mcam -> counters );
1928
1941
if (err )
1929
- return err ;
1942
+ goto free_entry_map ;
1930
1943
1931
- mcam -> cntr2pfvf_map = devm_kcalloc ( rvu -> dev , mcam -> counters .max ,
1932
- sizeof (u16 ), GFP_KERNEL );
1944
+ mcam -> cntr2pfvf_map = kmalloc_array ( mcam -> counters .max ,
1945
+ sizeof (u16 ), GFP_KERNEL );
1933
1946
if (!mcam -> cntr2pfvf_map )
1934
- goto free_mem ;
1947
+ goto free_cntr_bmap ;
1935
1948
1936
1949
/* Alloc memory for MCAM entry to counter mapping and for tracking
1937
1950
* counter's reference count.
1938
1951
*/
1939
- mcam -> entry2cntr_map = devm_kcalloc ( rvu -> dev , mcam -> bmap_entries ,
1940
- sizeof (u16 ), GFP_KERNEL );
1952
+ mcam -> entry2cntr_map = kmalloc_array ( mcam -> bmap_entries ,
1953
+ sizeof (u16 ), GFP_KERNEL );
1941
1954
if (!mcam -> entry2cntr_map )
1942
- goto free_mem ;
1955
+ goto free_cntr_map ;
1943
1956
1944
- mcam -> cntr_refcnt = devm_kcalloc ( rvu -> dev , mcam -> counters .max ,
1945
- sizeof (u16 ), GFP_KERNEL );
1957
+ mcam -> cntr_refcnt = kmalloc_array ( mcam -> counters .max ,
1958
+ sizeof (u16 ), GFP_KERNEL );
1946
1959
if (!mcam -> cntr_refcnt )
1947
- goto free_mem ;
1960
+ goto free_entry_cntr_map ;
1948
1961
1949
1962
/* Alloc memory for saving target device of mcam rule */
1950
- mcam -> entry2target_pffunc = devm_kcalloc ( rvu -> dev , mcam -> total_entries ,
1951
- sizeof (u16 ), GFP_KERNEL );
1963
+ mcam -> entry2target_pffunc = kmalloc_array ( mcam -> total_entries ,
1964
+ sizeof (u16 ), GFP_KERNEL );
1952
1965
if (!mcam -> entry2target_pffunc )
1953
- goto free_mem ;
1966
+ goto free_cntr_refcnt ;
1954
1967
1955
1968
for (index = 0 ; index < mcam -> bmap_entries ; index ++ ) {
1956
1969
mcam -> entry2pfvf_map [index ] = NPC_MCAM_INVALID_MAP ;
@@ -1964,8 +1977,21 @@ static int npc_mcam_rsrcs_init(struct rvu *rvu, int blkaddr)
1964
1977
1965
1978
return 0 ;
1966
1979
1967
- free_mem :
1980
+ free_cntr_refcnt :
1981
+ kfree (mcam -> cntr_refcnt );
1982
+ free_entry_cntr_map :
1983
+ kfree (mcam -> entry2cntr_map );
1984
+ free_cntr_map :
1985
+ kfree (mcam -> cntr2pfvf_map );
1986
+ free_cntr_bmap :
1987
+ kfree (mcam -> counters .bmap );
1988
+ free_entry_map :
1989
+ kfree (mcam -> entry2pfvf_map );
1990
+ free_bmap_reverse :
1991
+ kfree (mcam -> bmap_reverse );
1992
+ free_bmap :
1968
1993
kfree (mcam -> counters .bmap );
1994
+
1969
1995
return - ENOMEM ;
1970
1996
}
1971
1997
@@ -2173,6 +2199,7 @@ void rvu_npc_freemem(struct rvu *rvu)
2173
2199
struct npc_mcam * mcam = & rvu -> hw -> mcam ;
2174
2200
2175
2201
kfree (pkind -> rsrc .bmap );
2202
+ npc_mcam_rsrcs_deinit (rvu );
2176
2203
kfree (mcam -> counters .bmap );
2177
2204
if (rvu -> kpu_prfl_addr )
2178
2205
iounmap (rvu -> kpu_prfl_addr );
0 commit comments