From 45dcc2f2b0bdd239760dab48363a57dabd4da113 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bossart Date: Tue, 11 Dec 2018 18:11:49 -0600 Subject: [PATCH 01/17] ASoC: SOF: Intel: hda-dai: fix compilation with W=1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit sound/soc/sof/intel/hda-dai.c: In function ‘hda_link_hw_free’: sound/soc/sof/intel/hda-dai.c:213:22: warning: variable ‘sdev’ set but not used [-Wunused-but-set-variable] struct snd_sof_dev *sdev; ^~~~ Signed-off-by: Pierre-Louis Bossart --- sound/soc/sof/intel/hda-dai.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/sound/soc/sof/intel/hda-dai.c b/sound/soc/sof/intel/hda-dai.c index 801d45e0218e8e..ae7258450f3d2c 100644 --- a/sound/soc/sof/intel/hda-dai.c +++ b/sound/soc/sof/intel/hda-dai.c @@ -210,7 +210,6 @@ static int hda_link_hw_free(struct snd_pcm_substream *substream, unsigned int stream_tag; struct hdac_bus *bus; struct hdac_ext_link *link; - struct snd_sof_dev *sdev; struct hdac_stream *hstream; struct hdac_ext_stream *stream; struct snd_soc_pcm_runtime *rtd; @@ -234,7 +233,6 @@ static int hda_link_hw_free(struct snd_pcm_substream *substream, link_dev->link_prepared = 0; } else { /* release all hda streams when dai link is unloaded */ - sdev = snd_soc_component_get_drvdata(dai->component); pcm_substream.stream = SNDRV_PCM_STREAM_PLAYBACK; stream = snd_soc_dai_get_dma_data(dai, &pcm_substream); if (stream) { From a837064871ec55b4dd21c04ab12cb561b0f0e8b4 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bossart Date: Tue, 11 Dec 2018 18:16:04 -0600 Subject: [PATCH 02/17] ASoC: SOF: debug: fix issue with W=1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit sound/soc/sof/debug.c: In function ‘sof_dfsentry_read’: sound/soc/sof/debug.c:62:10: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits] if (ret < 0) Defining a 'ret' variable as size_t was borderline criminal in the first place... Signed-off-by: Pierre-Louis Bossart --- sound/soc/sof/debug.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/sound/soc/sof/debug.c b/sound/soc/sof/debug.c index 67f6cf79b72947..e5a951ef9829f2 100644 --- a/sound/soc/sof/debug.c +++ b/sound/soc/sof/debug.c @@ -31,7 +31,8 @@ static ssize_t sof_dfsentry_read(struct file *file, char __user *buffer, int size; u32 *buf; loff_t pos = *ppos; - size_t ret; + size_t size_ret; + int ret; size = dfse->size; @@ -60,17 +61,17 @@ static ssize_t sof_dfsentry_read(struct file *file, char __user *buffer, */ ret = pm_runtime_put_sync_autosuspend(sdev->dev); if (ret < 0) - dev_warn(sdev->dev, "warn: debugFS failed to autosuspend %zd\n", + dev_warn(sdev->dev, "warn: debugFS failed to autosuspend %d\n", ret); /* copy to userspace */ - ret = copy_to_user(buffer, buf, count); + size_ret = copy_to_user(buffer, buf, count); kfree(buf); /* update count & position if copy succeeded */ - if (ret == count) + if (size_ret == count) return -EFAULT; - count -= ret; + count -= size_ret; *ppos = pos + count; return count; From 1bbd9e269358cce48967131836b93758df818cd6 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bossart Date: Tue, 11 Dec 2018 18:20:15 -0600 Subject: [PATCH 03/17] ASoC: SOF: topology: fix issues with W=1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit sound/soc/sof/topology.c: In function ‘sof_control_load_volume’: sound/soc/sof/topology.c:261:28: warning: variable ‘cdata’ set but not used [-Wunused-but-set-variable] struct sof_ipc_ctrl_data *cdata; ^~~~~ sound/soc/sof/topology.c: In function ‘snd_sof_load_topology’: sound/soc/sof/topology.c:2711:27: warning: variable ‘hdr’ set but not used [-Wunused-but-set-variable] struct snd_soc_tplg_hdr *hdr; ^~~ Signed-off-by: Pierre-Louis Bossart --- sound/soc/sof/topology.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/sound/soc/sof/topology.c b/sound/soc/sof/topology.c index 06e94809aa3586..b09db12d829844 100644 --- a/sound/soc/sof/topology.c +++ b/sound/soc/sof/topology.c @@ -258,7 +258,6 @@ static int sof_control_load_volume(struct snd_soc_component *scomp, struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp); struct snd_soc_tplg_mixer_control *mc = (struct snd_soc_tplg_mixer_control *)hdr; - struct sof_ipc_ctrl_data *cdata; /* validate topology data */ if (le32_to_cpu(mc->num_channels) > SND_SOC_TPLG_MAX_CHAN) @@ -269,7 +268,6 @@ static int sof_control_load_volume(struct snd_soc_component *scomp, sizeof(struct sof_ipc_ctrl_value_chan) * le32_to_cpu(mc->num_channels); scontrol->control_data = kzalloc(scontrol->size, GFP_KERNEL); - cdata = scontrol->control_data; if (!scontrol->control_data) return -ENOMEM; @@ -2708,7 +2706,6 @@ EXPORT_SYMBOL(snd_sof_init_topology); int snd_sof_load_topology(struct snd_sof_dev *sdev, const char *file) { const struct firmware *fw; - struct snd_soc_tplg_hdr *hdr; int ret; if (sdev->tplg_loaded) { @@ -2725,7 +2722,6 @@ int snd_sof_load_topology(struct snd_sof_dev *sdev, const char *file) return ret; } - hdr = (struct snd_soc_tplg_hdr *)fw->data; ret = snd_soc_tplg_component_load(sdev->component, &sof_tplg_ops, fw, SND_SOC_TPLG_INDEX_ALL); From 0358e22079e77ba9c660e546c6b1226cce24698f Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bossart Date: Tue, 11 Dec 2018 18:25:43 -0600 Subject: [PATCH 04/17] ASoC: SOF: core: feedback from Andy Shevchenko Constants with _MS suffix simplification of search loop Signed-off-by: Pierre-Louis Bossart --- sound/soc/sof/core.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/sound/soc/sof/core.c b/sound/soc/sof/core.c index 480e4a3110ddf6..3ff1bc45ceda1b 100644 --- a/sound/soc/sof/core.c +++ b/sound/soc/sof/core.c @@ -15,8 +15,8 @@ #include "ops.h" /* SOF defaults if not provided by the platform in ms */ -#define TIMEOUT_DEFAULT_IPC 5 -#define TIMEOUT_DEFAULT_BOOT 100 +#define TIMEOUT_DEFAULT_IPC_MS 5 +#define TIMEOUT_DEFAULT_BOOT_MS 100 /* * Generic object lookup APIs. @@ -107,10 +107,7 @@ struct snd_sof_dai *snd_sof_find_dai(struct snd_sof_dev *sdev, struct snd_sof_dai *dai = NULL; list_for_each_entry(dai, &sdev->dai_list, list) { - if (!dai->name) - continue; - - if (strcmp(name, dai->name) == 0) + if (dai->name && (strcmp(name, dai->name) == 0)) return dai; } @@ -259,11 +256,11 @@ static int sof_probe(struct platform_device *pdev) /* set default timeouts if none provided */ if (plat_data->desc->ipc_timeout == 0) - sdev->ipc_timeout = TIMEOUT_DEFAULT_IPC; + sdev->ipc_timeout = TIMEOUT_DEFAULT_IPC_MS; else sdev->ipc_timeout = plat_data->desc->ipc_timeout; if (plat_data->desc->boot_timeout == 0) - sdev->boot_timeout = TIMEOUT_DEFAULT_BOOT; + sdev->boot_timeout = TIMEOUT_DEFAULT_BOOT_MS; else sdev->boot_timeout = plat_data->desc->boot_timeout; From 8c8e79912a1cfa8d4222b1834a753cbc93855b0f Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bossart Date: Tue, 11 Dec 2018 18:30:57 -0600 Subject: [PATCH 05/17] ASoC: SOF: remove .shutdown callback Not used, remove for now Signed-off-by: Pierre-Louis Bossart --- sound/soc/sof/core.c | 5 ----- sound/soc/sof/sof-acpi-dev.c | 6 ------ sound/soc/sof/sof-pci-dev.c | 6 ------ sound/soc/sof/sof-priv.h | 1 - 4 files changed, 18 deletions(-) diff --git a/sound/soc/sof/core.c b/sound/soc/sof/core.c index 3ff1bc45ceda1b..003ae3961c4f15 100644 --- a/sound/soc/sof/core.c +++ b/sound/soc/sof/core.c @@ -374,11 +374,6 @@ static int sof_remove(struct platform_device *pdev) return 0; } -void snd_sof_shutdown(struct device *dev) -{ -} -EXPORT_SYMBOL(snd_sof_shutdown); - static struct platform_driver sof_driver = { .driver = { .name = "sof-audio", diff --git a/sound/soc/sof/sof-acpi-dev.c b/sound/soc/sof/sof-acpi-dev.c index 52de8ac8ede0e8..78038916032873 100644 --- a/sound/soc/sof/sof-acpi-dev.c +++ b/sound/soc/sof/sof-acpi-dev.c @@ -221,11 +221,6 @@ static int sof_acpi_probe(struct platform_device *pdev) return ret; } -static void sof_acpi_shutdown(struct platform_device *pdev) -{ - snd_sof_shutdown(&pdev->dev); -} - static int sof_acpi_remove(struct platform_device *pdev) { struct sof_platform_priv *priv = dev_get_drvdata(&pdev->dev); @@ -257,7 +252,6 @@ MODULE_DEVICE_TABLE(acpi, sof_acpi_match); static struct platform_driver snd_sof_acpi_driver = { .probe = sof_acpi_probe, .remove = sof_acpi_remove, - .shutdown = sof_acpi_shutdown, .driver = { .name = "sof-audio-acpi", .pm = &sof_acpi_pm, diff --git a/sound/soc/sof/sof-pci-dev.c b/sound/soc/sof/sof-pci-dev.c index 449ff9cbc793aa..f36f011087dce8 100644 --- a/sound/soc/sof/sof-pci-dev.c +++ b/sound/soc/sof/sof-pci-dev.c @@ -283,11 +283,6 @@ static int sof_pci_probe(struct pci_dev *pci, return ret; } -static void sof_pci_shutdown(struct pci_dev *pci) -{ - snd_sof_shutdown(&pci->dev); -} - static void sof_pci_remove(struct pci_dev *pci) { struct sof_platform_priv *priv = pci_get_drvdata(pci); @@ -351,7 +346,6 @@ static struct pci_driver snd_sof_pci_driver = { .id_table = sof_pci_ids, .probe = sof_pci_probe, .remove = sof_pci_remove, - .shutdown = sof_pci_shutdown, .driver = { .pm = &sof_pci_pm, }, diff --git a/sound/soc/sof/sof-priv.h b/sound/soc/sof/sof-priv.h index f3c609320a3bb2..6efea9696adfdb 100644 --- a/sound/soc/sof/sof-priv.h +++ b/sound/soc/sof/sof-priv.h @@ -396,7 +396,6 @@ struct sof_platform_priv { /* * Device Level. */ -void snd_sof_shutdown(struct device *dev); int snd_sof_runtime_suspend(struct device *dev); int snd_sof_runtime_resume(struct device *dev); int snd_sof_resume(struct device *dev); From 363dc9a57d9555864f242da22a279b2607ae0c64 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bossart Date: Tue, 11 Dec 2018 18:34:16 -0600 Subject: [PATCH 06/17] ASoC: SOF: add _MS suffix to SND_SOF_SUSPEND_DELAY Feedback from Andy Shevchenko Signed-off-by: Pierre-Louis Bossart --- sound/soc/sof/pcm.c | 2 +- sound/soc/sof/sof-acpi-dev.c | 2 +- sound/soc/sof/sof-pci-dev.c | 2 +- sound/soc/sof/sof-priv.h | 2 +- sound/soc/sof/sof-spi-dev.c | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/sound/soc/sof/pcm.c b/sound/soc/sof/pcm.c index 1b01383a380dba..a6b11217ee509e 100644 --- a/sound/soc/sof/pcm.c +++ b/sound/soc/sof/pcm.c @@ -703,7 +703,7 @@ static int sof_pcm_probe(struct snd_soc_component *component) /* enable runtime PM with auto suspend */ pm_runtime_set_autosuspend_delay(component->dev, - SND_SOF_SUSPEND_DELAY); + SND_SOF_SUSPEND_DELAY_MS); pm_runtime_use_autosuspend(component->dev); pm_runtime_enable(component->dev); diff --git a/sound/soc/sof/sof-acpi-dev.c b/sound/soc/sof/sof-acpi-dev.c index 78038916032873..5c388e7f07d7d1 100644 --- a/sound/soc/sof/sof-acpi-dev.c +++ b/sound/soc/sof/sof-acpi-dev.c @@ -214,7 +214,7 @@ static int sof_acpi_probe(struct platform_device *pdev) } /* allow runtime_pm */ - pm_runtime_set_autosuspend_delay(dev, SND_SOF_SUSPEND_DELAY); + pm_runtime_set_autosuspend_delay(dev, SND_SOF_SUSPEND_DELAY_MS); pm_runtime_use_autosuspend(dev); pm_runtime_allow(dev); diff --git a/sound/soc/sof/sof-pci-dev.c b/sound/soc/sof/sof-pci-dev.c index f36f011087dce8..4c03ba30411468 100644 --- a/sound/soc/sof/sof-pci-dev.c +++ b/sound/soc/sof/sof-pci-dev.c @@ -263,7 +263,7 @@ static int sof_pci_probe(struct pci_dev *pci, } /* allow runtime_pm */ - pm_runtime_set_autosuspend_delay(dev, SND_SOF_SUSPEND_DELAY); + pm_runtime_set_autosuspend_delay(dev, SND_SOF_SUSPEND_DELAY_MS); pm_runtime_use_autosuspend(dev); /* diff --git a/sound/soc/sof/sof-priv.h b/sound/soc/sof/sof-priv.h index 6efea9696adfdb..a5f8f2d2baa9fc 100644 --- a/sound/soc/sof/sof-priv.h +++ b/sound/soc/sof/sof-priv.h @@ -33,7 +33,7 @@ #define SND_SOF_BARS 8 /* time in ms for runtime suspend delay */ -#define SND_SOF_SUSPEND_DELAY 2000 +#define SND_SOF_SUSPEND_DELAY_MS 2000 /* DMA buffer size for trace */ #define DMA_BUF_SIZE_FOR_TRACE (PAGE_SIZE * 16) diff --git a/sound/soc/sof/sof-spi-dev.c b/sound/soc/sof/sof-spi-dev.c index 372a5d1ed00e75..1eda25a68703c2 100644 --- a/sound/soc/sof/sof-spi-dev.c +++ b/sound/soc/sof/sof-spi-dev.c @@ -147,7 +147,7 @@ static int sof_spi_probe(struct spi_device *spi) spi->irq = irq; /* allow runtime_pm */ - pm_runtime_set_autosuspend_delay(dev, SND_SOF_SUSPEND_DELAY); + pm_runtime_set_autosuspend_delay(dev, SND_SOF_SUSPEND_DELAY_MS); pm_runtime_use_autosuspend(dev); pm_runtime_allow(dev); From 7d4bc8a3c2b0610be048bdec5fcdd2564c453f81 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bossart Date: Tue, 11 Dec 2018 18:38:00 -0600 Subject: [PATCH 07/17] ASoC: SOF: test for NULL before platform_device_unregister Unclear if platform_device_register_data can return NULL, err on the side of caution Signed-off-by: Pierre-Louis Bossart --- sound/soc/sof/core.c | 2 +- sound/soc/sof/intel/hda.c | 2 +- sound/soc/sof/sof-acpi-dev.c | 2 +- sound/soc/sof/sof-pci-dev.c | 2 +- sound/soc/sof/sof-spi-dev.c | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/sound/soc/sof/core.c b/sound/soc/sof/core.c index 003ae3961c4f15..efa58d78b5b31d 100644 --- a/sound/soc/sof/core.c +++ b/sound/soc/sof/core.c @@ -362,7 +362,7 @@ static int sof_remove(struct platform_device *pdev) struct snd_sof_dev *sdev = dev_get_drvdata(&pdev->dev); struct snd_sof_pdata *pdata = sdev->pdata; - if (pdata && !IS_ERR(pdata->pdev_mach)) + if (pdata && !IS_ERR_OR_NULL(pdata->pdev_mach)) platform_device_unregister(pdata->pdev_mach); snd_soc_unregister_component(&pdev->dev); diff --git a/sound/soc/sof/intel/hda.c b/sound/soc/sof/intel/hda.c index b726e270821027..fcefc1ab498d88 100644 --- a/sound/soc/sof/intel/hda.c +++ b/sound/soc/sof/intel/hda.c @@ -661,7 +661,7 @@ int hda_dsp_remove(struct snd_sof_dev *sdev) snd_hdac_ext_bus_device_remove(bus); #endif - if (sdev->hda && (!IS_ERR(sdev->hda->dmic_dev))) + if (sdev->hda && (!IS_ERR_OR_NULL(sdev->hda->dmic_dev))) platform_device_unregister(sdev->hda->dmic_dev); /* disable DSP IRQ */ diff --git a/sound/soc/sof/sof-acpi-dev.c b/sound/soc/sof/sof-acpi-dev.c index 5c388e7f07d7d1..ad9902bc706217 100644 --- a/sound/soc/sof/sof-acpi-dev.c +++ b/sound/soc/sof/sof-acpi-dev.c @@ -226,7 +226,7 @@ static int sof_acpi_remove(struct platform_device *pdev) struct sof_platform_priv *priv = dev_get_drvdata(&pdev->dev); struct snd_sof_pdata *sof_pdata = priv->sof_pdata; - if (!IS_ERR(priv->pdev_pcm)) + if (!IS_ERR_OR_NULL(priv->pdev_pcm)) platform_device_unregister(priv->pdev_pcm); release_firmware(sof_pdata->fw); diff --git a/sound/soc/sof/sof-pci-dev.c b/sound/soc/sof/sof-pci-dev.c index 4c03ba30411468..cf7976fb4335b2 100644 --- a/sound/soc/sof/sof-pci-dev.c +++ b/sound/soc/sof/sof-pci-dev.c @@ -289,7 +289,7 @@ static void sof_pci_remove(struct pci_dev *pci) struct snd_sof_pdata *sof_pdata = priv->sof_pdata; /* unregister sof-audio platform driver */ - if (!IS_ERR(priv->pdev_pcm)) + if (!IS_ERR_OR_NULL(priv->pdev_pcm)) platform_device_unregister(priv->pdev_pcm); /* release firmware */ diff --git a/sound/soc/sof/sof-spi-dev.c b/sound/soc/sof/sof-spi-dev.c index 1eda25a68703c2..3bb284c2bffeea 100644 --- a/sound/soc/sof/sof-spi-dev.c +++ b/sound/soc/sof/sof-spi-dev.c @@ -159,7 +159,7 @@ static int sof_spi_remove(struct spi_device *spi) struct sof_platform_priv *priv = spi_get_drvdata(spi); struct snd_sof_pdata *sof_pdata = priv->sof_pdata; - if (!IS_ERR(priv->pdev_pcm)) + if (!IS_ERR_OR_NULL(priv->pdev_pcm)) platform_device_unregister(priv->pdev_pcm); release_firmware(sof_pdata->fw); From afebc51f5c610e26b874a4f74201d0c8608d90b9 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bossart Date: Tue, 11 Dec 2018 18:43:03 -0600 Subject: [PATCH 08/17] ASoC: SOF: use PLATFORM_DEVID_NONE for platform_device_register_data Suggested by Andy Shevchenko Signed-off-by: Pierre-Louis Bossart --- sound/soc/sof/core.c | 2 +- sound/soc/sof/intel/hda.c | 3 ++- sound/soc/sof/utils.c | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/sound/soc/sof/core.c b/sound/soc/sof/core.c index efa58d78b5b31d..46c9962c7bba59 100644 --- a/sound/soc/sof/core.c +++ b/sound/soc/sof/core.c @@ -330,7 +330,7 @@ static int sof_probe(struct platform_device *pdev) /* register machine driver, pass machine info as pdata */ plat_data->pdev_mach = platform_device_register_data(sdev->dev, drv_name, - -1, mach, size); + PLATFORM_DEVID_NONE, mach, size); if (IS_ERR(plat_data->pdev_mach)) { ret = PTR_ERR(plat_data->pdev_mach); diff --git a/sound/soc/sof/intel/hda.c b/sound/soc/sof/intel/hda.c index fcefc1ab498d88..14942829ff16aa 100644 --- a/sound/soc/sof/intel/hda.c +++ b/sound/soc/sof/intel/hda.c @@ -458,7 +458,8 @@ int hda_dsp_probe(struct snd_sof_dev *sdev) hdev->desc = chip; hdev->dmic_dev = platform_device_register_data(&pci->dev, "dmic-codec", - -1, NULL, 0); + PLATFORM_DEVID_NONE, + NULL, 0); if (IS_ERR(hdev->dmic_dev)) { dev_err(&pci->dev, "error: failed to create DMIC device\n"); return PTR_ERR(hdev->dmic_dev); diff --git a/sound/soc/sof/utils.c b/sound/soc/sof/utils.c index bf66e14bc258b1..ccaf58d8c2264d 100644 --- a/sound/soc/sof/utils.c +++ b/sound/soc/sof/utils.c @@ -55,7 +55,8 @@ int sof_create_platform_device(struct sof_platform_priv *priv) struct device *dev = sof_pdata->dev; priv->pdev_pcm = - platform_device_register_data(dev, "sof-audio", -1, + platform_device_register_data(dev, "sof-audio", + PLATFORM_DEVID_NONE, sof_pdata, sizeof(*sof_pdata)); if (IS_ERR(priv->pdev_pcm)) { dev_err(dev, "error: cannot register device sof-audio. Error %d\n", From f56b1ff2acf1b8308790e180d6c81a6e9c216c7c Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bossart Date: Tue, 11 Dec 2018 18:59:19 -0600 Subject: [PATCH 09/17] ASoC: SOF: use min when checking two or three values Maybe there are other cases where this is needed Signed-off-by: Pierre-Louis Bossart --- sound/soc/sof/control.c | 5 ++--- sound/soc/sof/debug.c | 5 ++--- sound/soc/sof/trace.c | 5 ++--- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/sound/soc/sof/control.c b/sound/soc/sof/control.c index 2000f62e931b6e..3587f9f26a7473 100644 --- a/sound/soc/sof/control.c +++ b/sound/soc/sof/control.c @@ -297,7 +297,7 @@ int snd_sof_bytes_ext_put(struct snd_kcontrol *kcontrol, /* The maximum length that can be copied is limited by IPC max * length and topology defined length for ext bytes control. */ - max_size = (be->max < max_size) ? be->max : max_size; + max_size = min(be->max, max_size); if (header.length > max_size) { dev_err(sdev->dev, "error: Bytes data size %d exceeds max %d.\n", header.length, max_size); @@ -392,8 +392,7 @@ int snd_sof_bytes_ext_get(struct snd_kcontrol *kcontrol, /* Prevent read of other kernel data or possibly corrupt response */ data_size = cdata->data->size + sizeof(const struct sof_abi_hdr); - max_size = (size < max_size) ? size : max_size; - max_size = (be->max < max_size) ? be->max : max_size; + max_size = min3(be->max, max_size, (int)size); if (data_size > max_size) { dev_err(sdev->dev, "error: user data size %d exceeds max size %d.\n", data_size, max_size); diff --git a/sound/soc/sof/debug.c b/sound/soc/sof/debug.c index e5a951ef9829f2..2224d086566535 100644 --- a/sound/soc/sof/debug.c +++ b/sound/soc/sof/debug.c @@ -41,11 +41,10 @@ static ssize_t sof_dfsentry_read(struct file *file, char __user *buffer, return -EINVAL; if (pos >= size || !count) return 0; - if (count > size - pos) - count = size - pos; + count = min(count, (size_t)(size - pos)); /* intermediate buffer size must be u32 multiple */ - size = (count + 3) & ~3; + size = round_up(count, 4); buf = kzalloc(size, GFP_KERNEL); if (!buf) return -ENOMEM; diff --git a/sound/soc/sof/trace.c b/sound/soc/sof/trace.c index 9871a174f9ca11..c268b560b12f07 100644 --- a/sound/soc/sof/trace.c +++ b/sound/soc/sof/trace.c @@ -75,8 +75,7 @@ static ssize_t sof_dfsentry_trace_read(struct file *file, char __user *buffer, lpos_64 = lpos; lpos = do_div(lpos_64, buffer_size); - if (count > buffer_size - lpos) - count = buffer_size - lpos; + count = min(count, (size_t)(buffer_size - lpos)); /* get available count based on current host offset */ avail = sof_wait_trace_avail(sdev, lpos, buffer_size); @@ -86,7 +85,7 @@ static ssize_t sof_dfsentry_trace_read(struct file *file, char __user *buffer, } /* make sure count is <= avail */ - count = avail > count ? count : avail; + count = min(avail, count); /* copy available trace data to debugfs */ rem = copy_to_user(buffer, dfse->buf + lpos, count); From 0974e3e0fd78731b9d605fcc2a870c7acc0d75e8 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bossart Date: Tue, 11 Dec 2018 19:01:31 -0600 Subject: [PATCH 10/17] ASoC: SOF: ipc: use MS instead of MSEC SI units people. Signed-off-by: Pierre-Louis Bossart --- sound/soc/sof/ipc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sound/soc/sof/ipc.c b/sound/soc/sof/ipc.c index 918cd7b732ddf0..2fd2ad4249c93b 100644 --- a/sound/soc/sof/ipc.c +++ b/sound/soc/sof/ipc.c @@ -15,10 +15,10 @@ #include "ops.h" /* - * IPC message default size and timeout (msecs). + * IPC message default size and timeout (ms). * TODO: allow platforms to set size and timeout. */ -#define IPC_TIMEOUT_MSECS 300 +#define IPC_TIMEOUT_MS 300 #define IPC_EMPTY_LIST_SIZE 8 static void ipc_trace_message(struct snd_sof_dev *sdev, u32 msg_id); @@ -202,7 +202,7 @@ static int tx_wait_done(struct snd_sof_ipc *ipc, struct snd_sof_ipc_msg *msg, /* wait for DSP IPC completion */ ret = wait_event_timeout(msg->waitq, msg->ipc_complete, - msecs_to_jiffies(IPC_TIMEOUT_MSECS)); + msecs_to_jiffies(IPC_TIMEOUT_MS)); spin_lock_irqsave(&sdev->ipc_lock, flags); From 5c3688c9868267aa3eb931ecb38978bd59c0e252 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bossart Date: Tue, 11 Dec 2018 19:03:05 -0600 Subject: [PATCH 11/17] ASoC: SOF: ipc: don't check for empty list before list_for_each_entry Feedback from Andy Shevchenko Signed-off-by: Pierre-Louis Bossart --- sound/soc/sof/ipc.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/sound/soc/sof/ipc.c b/sound/soc/sof/ipc.c index 2fd2ad4249c93b..1b4b6abb0e7051 100644 --- a/sound/soc/sof/ipc.c +++ b/sound/soc/sof/ipc.c @@ -312,15 +312,11 @@ static struct snd_sof_ipc_msg *sof_ipc_reply_find_msg(struct snd_sof_ipc *ipc, header = SOF_IPC_MESSAGE_ID(header); - if (list_empty(&ipc->reply_list)) - goto err; - list_for_each_entry(msg, &ipc->reply_list, list) { if (SOF_IPC_MESSAGE_ID(msg->header) == header) return msg; } -err: dev_err(sdev->dev, "error: rx list empty but received 0x%x\n", header); return NULL; From 3c67076492f6c8d2053cc0033e1617077c002aa3 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bossart Date: Tue, 11 Dec 2018 19:04:56 -0600 Subject: [PATCH 12/17] ASoC: SOF: ipc: indentations and style Feedback from Andy Shevchenko. Keep indent on for subparts of the log Signed-off-by: Pierre-Louis Bossart --- sound/soc/sof/ipc.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/sound/soc/sof/ipc.c b/sound/soc/sof/ipc.c index 1b4b6abb0e7051..0fdd72a801f73f 100644 --- a/sound/soc/sof/ipc.c +++ b/sound/soc/sof/ipc.c @@ -721,10 +721,10 @@ int snd_sof_ipc_valid(struct snd_sof_dev *sdev) struct sof_ipc_fw_version *v = &ready->version; dev_info(sdev->dev, - " Firmware info: version %d:%d:%d-%s\n", v->major, v->minor, + "Firmware info: version %d:%d:%d-%s\n", v->major, v->minor, v->micro, v->tag); dev_info(sdev->dev, - " Firmware: ABI %d:%d:%d Kernel ABI %d:%d:%d\n", + "Firmware: ABI %d:%d:%d Kernel ABI %d:%d:%d\n", SOF_ABI_VERSION_MAJOR(v->abi_version), SOF_ABI_VERSION_MINOR(v->abi_version), SOF_ABI_VERSION_PATCH(v->abi_version), @@ -737,15 +737,14 @@ int snd_sof_ipc_valid(struct snd_sof_dev *sdev) if (ready->debug.bits.build) { dev_info(sdev->dev, - " Firmware debug build %d on %s-%s - options:\n" - " GDB: %s\n" - " lock debug: %s\n" - " lock vdebug: %s\n", + "Firmware debug build %d on %s-%s - options:\n" + " GDB: %s\n" + " lock debug: %s\n" + " lock vdebug: %s\n", v->build, v->date, v->time, ready->debug.bits.gdb ? "enabled" : "disabled", ready->debug.bits.locks ? "enabled" : "disabled", - ready->debug.bits.locks_verbose ? - "enabled" : "disabled"); + ready->debug.bits.locks_verbose ? "enabled" : "disabled"); } /* copy the fw_version into debugfs at first boot */ From ba6e6c3eaed6a14851cbcb53d89a94b0832aebe0 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bossart Date: Tue, 11 Dec 2018 19:16:51 -0600 Subject: [PATCH 13/17] ASoC: SOF: ops: simplify PCI access remove change variable, use return false/true instead Feedback from Andy Shevchenko Signed-off-by: Pierre-Louis Bossart --- sound/soc/sof/ops.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/sound/soc/sof/ops.c b/sound/soc/sof/ops.c index 41143fd9777212..778b0aadf34539 100644 --- a/sound/soc/sof/ops.c +++ b/sound/soc/sof/ops.c @@ -14,7 +14,6 @@ int snd_sof_pci_update_bits_unlocked(struct snd_sof_dev *sdev, u32 offset, u32 mask, u32 value) { - bool change; unsigned int old, new; u32 ret = ~0; /* explicit init to remove uninitialized use warnings */ @@ -25,14 +24,14 @@ int snd_sof_pci_update_bits_unlocked(struct snd_sof_dev *sdev, u32 offset, old = ret; new = (old & (~mask)) | (value & mask); - change = (old != new); - if (change) { - pci_write_config_dword(sdev->pci, offset, new); - dev_dbg(sdev->dev, "Debug PCIW: %8.8x at %8.8x\n", value, - offset); - } + if (old == new) + return false; - return change; + pci_write_config_dword(sdev->pci, offset, new); + dev_dbg(sdev->dev, "Debug PCIW: %8.8x at %8.8x\n", value, + offset); + + return true; } EXPORT_SYMBOL(snd_sof_pci_update_bits_unlocked); @@ -52,7 +51,6 @@ EXPORT_SYMBOL(snd_sof_pci_update_bits); int snd_sof_dsp_update_bits_unlocked(struct snd_sof_dev *sdev, u32 bar, u32 offset, u32 mask, u32 value) { - bool change; unsigned int old, new; u32 ret; @@ -61,29 +59,30 @@ int snd_sof_dsp_update_bits_unlocked(struct snd_sof_dev *sdev, u32 bar, old = ret; new = (old & (~mask)) | (value & mask); - change = (old != new); - if (change) - snd_sof_dsp_write(sdev, bar, offset, new); + if (old == new) + return false; - return change; + snd_sof_dsp_write(sdev, bar, offset, new); + + return true; } EXPORT_SYMBOL(snd_sof_dsp_update_bits_unlocked); int snd_sof_dsp_update_bits64_unlocked(struct snd_sof_dev *sdev, u32 bar, u32 offset, u64 mask, u64 value) { - bool change; u64 old, new; old = snd_sof_dsp_read64(sdev, bar, offset); new = (old & (~mask)) | (value & mask); - change = (old != new); - if (change) - snd_sof_dsp_write64(sdev, bar, offset, new); + if (old == new) + return false; - return change; + snd_sof_dsp_write64(sdev, bar, offset, new); + + return true; } EXPORT_SYMBOL(snd_sof_dsp_update_bits64_unlocked); From 69f16976af7700aa2c5a6e0651876ea13d8098b8 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bossart Date: Tue, 11 Dec 2018 19:20:07 -0600 Subject: [PATCH 14/17] ASoC: SOF: ops: improve readability remove new line, even if it makes checkpatch unhappy Feedback from Andy Shevchenko Signed-off-by: Pierre-Louis Bossart --- sound/soc/sof/ops.c | 3 +-- sound/soc/sof/ops.h | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/sound/soc/sof/ops.c b/sound/soc/sof/ops.c index 778b0aadf34539..1eb759c6569c76 100644 --- a/sound/soc/sof/ops.c +++ b/sound/soc/sof/ops.c @@ -164,8 +164,7 @@ int snd_sof_dsp_register_poll(struct snd_sof_dev *sdev, u32 bar, u32 offset, timeout /= 10; for (time = timeout; time > 0; time--) { - if ((snd_sof_dsp_read(sdev, bar, offset) & mask) == - target) + if ((snd_sof_dsp_read(sdev, bar, offset) & mask) == target) break; usleep_range(5000, 10000); diff --git a/sound/soc/sof/ops.h b/sound/soc/sof/ops.h index 405e39155645a9..fc4868712af9ae 100644 --- a/sound/soc/sof/ops.h +++ b/sound/soc/sof/ops.h @@ -157,8 +157,7 @@ static inline void snd_sof_dsp_write64(struct snd_sof_dev *sdev, u32 bar, u32 offset, u64 value) { if (sdev->ops->write64) - sdev->ops->write64(sdev, - sdev->bar[bar] + offset, value); + sdev->ops->write64(sdev, sdev->bar[bar] + offset, value); } static inline u32 snd_sof_dsp_read(struct snd_sof_dev *sdev, u32 bar, From bccd6c0fdffe399d1bfcad1b98d32594c8c58ad9 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bossart Date: Tue, 11 Dec 2018 19:22:08 -0600 Subject: [PATCH 15/17] ASoC: SOF: loader.c: remove unused variable Feedback from Andy Shevchenko Signed-off-by: Pierre-Louis Bossart --- sound/soc/sof/loader.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sound/soc/sof/loader.c b/sound/soc/sof/loader.c index dbadd8c521e605..70b3038e3e2b59 100644 --- a/sound/soc/sof/loader.c +++ b/sound/soc/sof/loader.c @@ -18,8 +18,6 @@ static int get_ext_windows(struct snd_sof_dev *sdev, struct sof_ipc_ext_data_hdr *ext_hdr) { struct sof_ipc_window *w = (struct sof_ipc_window *)ext_hdr; - - int ret = 0; size_t size; if (w->num_windows == 0 || w->num_windows > SOF_IPC_MAX_ELEMS) @@ -32,7 +30,7 @@ static int get_ext_windows(struct snd_sof_dev *sdev, if (!sdev->info_window) return -ENOMEM; - return ret; + return 0; } /* parse the extended FW boot data structures from FW boot message */ From 1c1c079949f7d26f30afb7807527c33ed86cfd36 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bossart Date: Tue, 11 Dec 2018 19:44:38 -0600 Subject: [PATCH 16/17] ASoC: SOF: spi: fix error with W=1 remove spi_pm, will be added back when needed Signed-off-by: Pierre-Louis Bossart --- sound/soc/sof/sof-spi-dev.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/sound/soc/sof/sof-spi-dev.c b/sound/soc/sof/sof-spi-dev.c index 3bb284c2bffeea..81d79bcee10f4d 100644 --- a/sound/soc/sof/sof-spi-dev.c +++ b/sound/soc/sof/sof-spi-dev.c @@ -22,13 +22,6 @@ #include "hw-spi.h" #include "ops.h" -static const struct dev_pm_ops spi_pm = { - SET_SYSTEM_SLEEP_PM_OPS(snd_sof_suspend, snd_sof_resume) - SET_RUNTIME_PM_OPS(snd_sof_runtime_suspend, snd_sof_runtime_resume, - NULL) - .suspend_late = snd_sof_suspend_late, -}; - /* FIXME: replace with some meaningful values */ static struct snd_soc_acpi_mach spi_machines[] = { { From 729fb1704e03f618965070249640b6d3bb6c9f4b Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bossart Date: Wed, 12 Dec 2018 11:16:58 -0600 Subject: [PATCH 17/17] ASoC: SOF: sof.h: move gpio to int Apparently cannot be unsigned int Signed-off-by: Pierre-Louis Bossart --- include/sound/sof.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/sound/sof.h b/include/sound/sof.h index 4ed6e23791412e..c69d636a0c30a9 100644 --- a/include/sound/sof.h +++ b/include/sound/sof.h @@ -42,7 +42,7 @@ struct snd_sof_pdata { const struct sof_dev_desc *desc; /* SPI data */ - unsigned int gpio; + int gpio; unsigned int active; /* machine */