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

octeontx2-af: Initialize maps.

kmalloc_array() without __GFP_ZERO flag does not initialize
memory to zero. This causes issues. Use kcalloc() for maps and
bitmap_zalloc() for bitmaps.

Fixes: dd7842878633 ("octeontx2-af: Add new devlink param to configure maximum usable NIX block LFs")
Signed-off-by: Ratheesh Kannoth <rkannoth@marvell.com>
Reviewed-by: Brett Creeley <bcreeley@amd.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://lore.kernel.org/r/20240206024000.1070260-1-rkannoth@marvell.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

authored by

Ratheesh Kannoth and committed by
Paolo Abeni
db010ff6 03fa49a3

+15 -16
+15 -16
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c
··· 1850 1850 { 1851 1851 struct npc_mcam *mcam = &rvu->hw->mcam; 1852 1852 1853 - kfree(mcam->bmap); 1854 - kfree(mcam->bmap_reverse); 1853 + bitmap_free(mcam->bmap); 1854 + bitmap_free(mcam->bmap_reverse); 1855 1855 kfree(mcam->entry2pfvf_map); 1856 1856 kfree(mcam->cntr2pfvf_map); 1857 1857 kfree(mcam->entry2cntr_map); ··· 1904 1904 mcam->pf_offset = mcam->nixlf_offset + nixlf_count; 1905 1905 1906 1906 /* Allocate bitmaps for managing MCAM entries */ 1907 - mcam->bmap = kmalloc_array(BITS_TO_LONGS(mcam->bmap_entries), 1908 - sizeof(long), GFP_KERNEL); 1907 + mcam->bmap = bitmap_zalloc(mcam->bmap_entries, GFP_KERNEL); 1909 1908 if (!mcam->bmap) 1910 1909 return -ENOMEM; 1911 1910 1912 - mcam->bmap_reverse = kmalloc_array(BITS_TO_LONGS(mcam->bmap_entries), 1913 - sizeof(long), GFP_KERNEL); 1911 + mcam->bmap_reverse = bitmap_zalloc(mcam->bmap_entries, GFP_KERNEL); 1914 1912 if (!mcam->bmap_reverse) 1915 1913 goto free_bmap; 1916 1914 1917 1915 mcam->bmap_fcnt = mcam->bmap_entries; 1918 1916 1919 1917 /* Alloc memory for saving entry to RVU PFFUNC allocation mapping */ 1920 - mcam->entry2pfvf_map = kmalloc_array(mcam->bmap_entries, 1921 - sizeof(u16), GFP_KERNEL); 1918 + mcam->entry2pfvf_map = kcalloc(mcam->bmap_entries, sizeof(u16), 1919 + GFP_KERNEL); 1920 + 1922 1921 if (!mcam->entry2pfvf_map) 1923 1922 goto free_bmap_reverse; 1924 1923 ··· 1940 1941 if (err) 1941 1942 goto free_entry_map; 1942 1943 1943 - mcam->cntr2pfvf_map = kmalloc_array(mcam->counters.max, 1944 - sizeof(u16), GFP_KERNEL); 1944 + mcam->cntr2pfvf_map = kcalloc(mcam->counters.max, sizeof(u16), 1945 + GFP_KERNEL); 1945 1946 if (!mcam->cntr2pfvf_map) 1946 1947 goto free_cntr_bmap; 1947 1948 1948 1949 /* Alloc memory for MCAM entry to counter mapping and for tracking 1949 1950 * counter's reference count. 1950 1951 */ 1951 - mcam->entry2cntr_map = kmalloc_array(mcam->bmap_entries, 1952 - sizeof(u16), GFP_KERNEL); 1952 + mcam->entry2cntr_map = kcalloc(mcam->bmap_entries, sizeof(u16), 1953 + GFP_KERNEL); 1953 1954 if (!mcam->entry2cntr_map) 1954 1955 goto free_cntr_map; 1955 1956 1956 - mcam->cntr_refcnt = kmalloc_array(mcam->counters.max, 1957 - sizeof(u16), GFP_KERNEL); 1957 + mcam->cntr_refcnt = kcalloc(mcam->counters.max, sizeof(u16), 1958 + GFP_KERNEL); 1958 1959 if (!mcam->cntr_refcnt) 1959 1960 goto free_entry_cntr_map; 1960 1961 ··· 1987 1988 free_entry_map: 1988 1989 kfree(mcam->entry2pfvf_map); 1989 1990 free_bmap_reverse: 1990 - kfree(mcam->bmap_reverse); 1991 + bitmap_free(mcam->bmap_reverse); 1991 1992 free_bmap: 1992 - kfree(mcam->bmap); 1993 + bitmap_free(mcam->bmap); 1993 1994 1994 1995 return -ENOMEM; 1995 1996 }