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

Configure Feed

Select the types of activity you want to include in your feed.

ASoC: SOF: topology: use kzalloc_flex

Simplify allocation by using a flexible array member.

Add __counted_by for extra runtime analysis.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Link: https://patch.msgid.link/20260326023053.53493-1-rosenp@gmail.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Rosen Penev and committed by
Mark Brown
d3d75c76 aa173b70

+3 -13
+1 -1
sound/soc/sof/sof-audio.h
··· 411 411 struct snd_sof_tuple *tuples; 412 412 int num_tuples; 413 413 struct snd_soc_dai_link *link; 414 - struct snd_soc_tplg_hw_config *hw_configs; 415 414 int num_hw_configs; 416 415 int default_hw_cfg_id; 417 416 int type; 418 417 struct list_head list; 418 + struct snd_soc_tplg_hw_config hw_configs[] __counted_by(num_hw_configs); 419 419 }; 420 420 421 421 /* ASoC SOF DAPM widget */
+2 -12
sound/soc/sof/topology.c
··· 1908 1908 return -EINVAL; 1909 1909 } 1910 1910 1911 - slink = kzalloc_obj(*slink); 1911 + slink = kzalloc_flex(*slink, hw_configs, le32_to_cpu(cfg->num_hw_configs)); 1912 1912 if (!slink) 1913 1913 return -ENOMEM; 1914 1914 1915 1915 slink->num_hw_configs = le32_to_cpu(cfg->num_hw_configs); 1916 - slink->hw_configs = kmemdup_array(cfg->hw_config, 1917 - slink->num_hw_configs, sizeof(*slink->hw_configs), 1918 - GFP_KERNEL); 1919 - if (!slink->hw_configs) { 1920 - kfree(slink); 1921 - return -ENOMEM; 1922 - } 1916 + memcpy(slink->hw_configs, cfg->hw_config, le32_to_cpu(cfg->num_hw_configs) * sizeof(*slink->hw_configs)); 1923 1917 1924 1918 slink->default_hw_cfg_id = le32_to_cpu(cfg->default_hw_config_id); 1925 1919 slink->link = link; ··· 1926 1932 private->array, le32_to_cpu(private->size)); 1927 1933 if (ret < 0) { 1928 1934 dev_err(scomp->dev, "Failed tp parse common DAI link tokens\n"); 1929 - kfree(slink->hw_configs); 1930 1935 kfree(slink); 1931 1936 return ret; 1932 1937 } ··· 1996 2003 /* allocate memory for tuples array */ 1997 2004 slink->tuples = kzalloc_objs(*slink->tuples, num_tuples); 1998 2005 if (!slink->tuples) { 1999 - kfree(slink->hw_configs); 2000 2006 kfree(slink); 2001 2007 return -ENOMEM; 2002 2008 } ··· 2053 2061 2054 2062 err: 2055 2063 kfree(slink->tuples); 2056 - kfree(slink->hw_configs); 2057 2064 kfree(slink); 2058 2065 2059 2066 return ret; ··· 2069 2078 2070 2079 kfree(slink->tuples); 2071 2080 list_del(&slink->list); 2072 - kfree(slink->hw_configs); 2073 2081 kfree(slink); 2074 2082 dobj->private = NULL; 2075 2083