From 070a40e3cdde3e7f8b7bbf7ab0f6792e8c3bdb13 Mon Sep 17 00:00:00 2001 From: Kirill Kapranov Date: Mon, 30 Aug 2021 23:28:54 +0300 Subject: [PATCH] kernel:sai: Fix resources leak Signed-off-by: Kirill Kapranov --- recipes-kernel/linux/compulab/imx8mm.inc | 3 + .../0042-snd-Fix-resource-management.patch | 200 ++++++++++++++++++ .../0043-config-Fix-build-time-warnings.patch | 47 ++++ 3 files changed, 250 insertions(+) create mode 100644 recipes-kernel/linux/compulab/imx8mm/0042-snd-Fix-resource-management.patch create mode 100644 recipes-kernel/linux/compulab/imx8mm/0043-config-Fix-build-time-warnings.patch diff --git a/recipes-kernel/linux/compulab/imx8mm.inc b/recipes-kernel/linux/compulab/imx8mm.inc index a1e7a4d..5dfd000 100644 --- a/recipes-kernel/linux/compulab/imx8mm.inc +++ b/recipes-kernel/linux/compulab/imx8mm.inc @@ -40,5 +40,8 @@ SRC_URI_append = " \ file://0039-ucm-Enable-wm8731-audiocodec.patch \ file://0040-ucm-imx8m-mini-Fix-iwlwifi.patch \ file://0041-drm-Panel-fix.patch \ + file://0042-snd-Fix-resource-management.patch \ + file://0043-config-Fix-build-time-warnings.patch \ file://defconfig \ " + diff --git a/recipes-kernel/linux/compulab/imx8mm/0042-snd-Fix-resource-management.patch b/recipes-kernel/linux/compulab/imx8mm/0042-snd-Fix-resource-management.patch new file mode 100644 index 0000000..84c632d --- /dev/null +++ b/recipes-kernel/linux/compulab/imx8mm/0042-snd-Fix-resource-management.patch @@ -0,0 +1,200 @@ +From bce17b857063545b4393c51771398812a57b431d Mon Sep 17 00:00:00 2001 +From: Kirill Kapranov +Date: Mon, 30 Aug 2021 22:51:15 +0300 +Subject: [PATCH 42/43] snd: Fix resource management + +Allocation of the memory and creating sysfs group shall be undone in case of +error. This prevents memory leak; also this rids system log of unnecessary +pollution caused by attempts of sysfs group recreation. + +Signed-off-by: Kirill Kapranov +--- + sound/soc/fsl/fsl_sai.c | 55 ++++++++++++++++++++++++++++++--------------- + sound/soc/fsl/imx-pcm-dma.c | 9 +++++--- + 2 files changed, 43 insertions(+), 21 deletions(-) + +diff --git a/sound/soc/fsl/fsl_sai.c b/sound/soc/fsl/fsl_sai.c +index 68f69fb03eec..128283d541d8 100644 +--- a/sound/soc/fsl/fsl_sai.c ++++ b/sound/soc/fsl/fsl_sai.c +@@ -1297,17 +1297,20 @@ static int fsl_sai_read_dlcfg(struct platform_device *pdev, char *pn, + static int fsl_sai_probe(struct platform_device *pdev) + { + struct device_node *np = pdev->dev.of_node; +- struct fsl_sai *sai; ++ struct fsl_sai *sai = NULL; + struct regmap *gpr; + struct resource *res; + void __iomem *base; + char tmp[8]; + int irq, ret, i; + int index; ++ bool sysfs_initialized = false; + + sai = devm_kzalloc(&pdev->dev, sizeof(*sai), GFP_KERNEL); +- if (!sai) +- return -ENOMEM; ++ if (!sai) { ++ ret = -ENOMEM; ++ goto general_finish; ++ } + + sai->pdev = pdev; + sai->soc_data = of_device_get_match_data(&pdev->dev); +@@ -1316,8 +1319,10 @@ static int fsl_sai_probe(struct platform_device *pdev) + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + base = devm_ioremap_resource(&pdev->dev, res); +- if (IS_ERR(base)) +- return PTR_ERR(base); ++ if (IS_ERR(base)) { ++ ret = PTR_ERR(base); ++ goto err_mem_free; ++ } + + if (sai->soc_data->reg_offset == 8) { + fsl_sai_regmap_config.reg_defaults = fsl_sai_reg_defaults_ofs8; +@@ -1330,7 +1335,8 @@ static int fsl_sai_probe(struct platform_device *pdev) + NULL, base, &fsl_sai_regmap_config); + if (IS_ERR(sai->regmap)) { + dev_err(&pdev->dev, "regmap init failed\n"); +- return PTR_ERR(sai->regmap); ++ ret = PTR_ERR(sai->regmap); ++ goto err_mem_free; + } + + /* No error out for old DTB cases but only mark the clock NULL */ +@@ -1338,8 +1344,8 @@ static int fsl_sai_probe(struct platform_device *pdev) + if (IS_ERR(sai->bus_clk)) { + dev_err(&pdev->dev, "failed to get bus clock: %ld\n", + PTR_ERR(sai->bus_clk)); +- return PTR_ERR(sai->bus_clk); +- sai->bus_clk = NULL; ++ ret = PTR_ERR(sai->bus_clk); ++ goto err_mem_free; + } + + for (i = 0; i < FSL_SAI_MCLK_MAX; i++) { +@@ -1367,14 +1373,14 @@ static int fsl_sai_probe(struct platform_device *pdev) + ret = fsl_sai_read_dlcfg(pdev, "fsl,dataline", &sai->pcm_dl_cfg, + sai->soc_data->dataline); + if (ret < 0) +- return ret; ++ goto err_mem_free; + + sai->pcm_dl_cfg_cnt = ret; + + ret = fsl_sai_read_dlcfg(pdev, "fsl,dataline,dsd", &sai->dsd_dl_cfg, + sai->soc_data->dataline); + if (ret < 0) +- return ret; ++ goto err_mem_free; + + sai->dsd_dl_cfg_cnt = ret; + +@@ -1393,14 +1399,16 @@ static int fsl_sai_probe(struct platform_device *pdev) + } + + irq = platform_get_irq(pdev, 0); +- if (irq < 0) +- return irq; ++ if (irq < 0) { ++ ret = irq; ++ goto err_mem_free; ++ } + + ret = devm_request_irq(&pdev->dev, irq, fsl_sai_isr, IRQF_SHARED, + np->name, sai); + if (ret) { + dev_err(&pdev->dev, "failed to claim irq %u\n", irq); +- return ret; ++ goto err_mem_free; + } + + memcpy(&sai->cpu_dai_drv, &fsl_sai_dai_template, +@@ -1417,7 +1425,8 @@ static int fsl_sai_probe(struct platform_device *pdev) + of_find_property(np, "fsl,sai-asynchronous", NULL)) { + /* error out if both synchronous and asynchronous are present */ + dev_err(&pdev->dev, "invalid binding for synchronous mode\n"); +- return -EINVAL; ++ ret = -EINVAL; ++ goto err_mem_free; + } + + if (of_find_property(np, "fsl,sai-synchronous-rx", NULL)) { +@@ -1438,12 +1447,15 @@ static int fsl_sai_probe(struct platform_device *pdev) + gpr = syscon_regmap_lookup_by_compatible("fsl,imx6ul-iomuxc-gpr"); + if (IS_ERR(gpr)) { + dev_err(&pdev->dev, "cannot find iomuxc registers\n"); +- return PTR_ERR(gpr); ++ ret = PTR_ERR(gpr); ++ goto err_mem_free; + } + + index = of_alias_get_id(np, "sai"); +- if (index < 0) +- return index; ++ if (index < 0) { ++ ret = index; ++ goto err_mem_free; ++ } + + regmap_update_bits(gpr, IOMUXC_GPR1, MCLK_DIR(index), + MCLK_DIR(index)); +@@ -1489,6 +1501,8 @@ static int fsl_sai_probe(struct platform_device *pdev) + + if (sysfs_create_group(&pdev->dev.kobj, fsl_sai_get_dev_attribute_group(sai->monitor_spdif))) + dev_err(&pdev->dev, "fail to create sys group\n"); ++ else ++ sysfs_initialized = true; + } + + pm_runtime_put_sync(&pdev->dev); +@@ -1509,11 +1523,16 @@ static int fsl_sai_probe(struct platform_device *pdev) + goto err_pm_disable; + } + +- return ret; ++ goto general_finish; + + err_pm_disable: + pm_runtime_disable(&pdev->dev); + ++ if(sysfs_initialized) ++ sysfs_remove_group(&pdev->dev.kobj, fsl_sai_get_dev_attribute_group(sai->monitor_spdif)); ++err_mem_free: ++ devm_kfree(&pdev->dev, sai); ++general_finish: + return ret; + } + +diff --git a/sound/soc/fsl/imx-pcm-dma.c b/sound/soc/fsl/imx-pcm-dma.c +index 04a9bc749016..25ef5e0e6681 100644 +--- a/sound/soc/fsl/imx-pcm-dma.c ++++ b/sound/soc/fsl/imx-pcm-dma.c +@@ -37,6 +37,7 @@ static const struct snd_dmaengine_pcm_config imx_dmaengine_pcm_config = { + int imx_pcm_dma_init(struct platform_device *pdev, size_t size) + { + struct snd_dmaengine_pcm_config *config; ++ int ret; + + config = devm_kzalloc(&pdev->dev, + sizeof(struct snd_dmaengine_pcm_config), GFP_KERNEL); +@@ -44,9 +45,11 @@ int imx_pcm_dma_init(struct platform_device *pdev, size_t size) + return -ENOMEM; + *config = imx_dmaengine_pcm_config; + +- return devm_snd_dmaengine_pcm_register(&pdev->dev, +- config, +- SND_DMAENGINE_PCM_FLAG_COMPAT); ++ ret = devm_snd_dmaengine_pcm_register(&pdev->dev, config, ++ SND_DMAENGINE_PCM_FLAG_COMPAT); ++ if(ret) ++ devm_kfree(&pdev->dev, config); ++ return ret; + } + EXPORT_SYMBOL_GPL(imx_pcm_dma_init); + +-- +2.11.0 + diff --git a/recipes-kernel/linux/compulab/imx8mm/0043-config-Fix-build-time-warnings.patch b/recipes-kernel/linux/compulab/imx8mm/0043-config-Fix-build-time-warnings.patch new file mode 100644 index 0000000..a62be86 --- /dev/null +++ b/recipes-kernel/linux/compulab/imx8mm/0043-config-Fix-build-time-warnings.patch @@ -0,0 +1,47 @@ +From f882a3bcacb5237316cb6a4408237d226847db45 Mon Sep 17 00:00:00 2001 +From: Kirill Kapranov +Date: Mon, 30 Aug 2021 23:18:26 +0300 +Subject: [PATCH 43/43] config: Fix build-time warnings + +Signed-off-by: Kirill Kapranov +--- + arch/arm64/boot/dts/compulab/Makefile | 2 +- + arch/arm64/configs/ucm-imx8m-mini_defconfig | 6 +++--- + 2 files changed, 4 insertions(+), 4 deletions(-) + +diff --git a/arch/arm64/boot/dts/compulab/Makefile b/arch/arm64/boot/dts/compulab/Makefile +index 160781dbf53a..a4c0a24157dc 100644 +--- a/arch/arm64/boot/dts/compulab/Makefile ++++ b/arch/arm64/boot/dts/compulab/Makefile +@@ -1,5 +1,5 @@ + dtb-$(CONFIG_ARCH_MXC) += ucm-imx8m-mini.dtb + +-always := $(dtb-y) ++always-y := $(dtb-y) + subdir-y := $(dts-dirs) + clean-files := *.dtb +diff --git a/arch/arm64/configs/ucm-imx8m-mini_defconfig b/arch/arm64/configs/ucm-imx8m-mini_defconfig +index 5f75b54ca245..0182fa452715 100644 +--- a/arch/arm64/configs/ucm-imx8m-mini_defconfig ++++ b/arch/arm64/configs/ucm-imx8m-mini_defconfig +@@ -524,14 +524,14 @@ CONFIG_SND_SOC_IMX_MQS=y + CONFIG_SND_SOC_IMX_SPDIF=y + CONFIG_SND_SOC_IMX_AUDMIX=y + CONFIG_SND_SOC_IMX_PDM_MIC=y +-CONFIG_SND_SOC_IMX_DSP=y ++CONFIG_SND_SOC_IMX_DSP=n + CONFIG_SND_SOC_IMX_CDNHDMI=y + CONFIG_SND_SOC_IMX_XCVR=y + CONFIG_SND_SOC_SOF_TOPLEVEL=y + CONFIG_SND_SOC_SOF_OF=m + CONFIG_SND_SOC_SOF_IMX_TOPLEVEL=y +-CONFIG_SND_SOC_SOF_IMX8_SUPPORT=m +-CONFIG_SND_SOC_SOF_IMX8M_SUPPORT=m ++CONFIG_SND_SOC_SOF_IMX8_SUPPORT=y ++CONFIG_SND_SOC_SOF_IMX8M_SUPPORT=y + CONFIG_SND_SOC_SPDIF=m + CONFIG_SND_SOC_WM8731=y + CONFIG_SND_SIMPLE_CARD=y +-- +2.11.0 +