All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Phillip Potter <phil@philpotter.co.uk>,
	Mark Brown <broonie@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Sasha Levin <sashal@kernel.org>,
	alsa-devel@alsa-project.org
Subject: [PATCH AUTOSEL 5.4 27/52] ASoC: rt5645: add error checking to rt5645_probe function
Date: Mon, 24 May 2021 10:48:37 -0400	[thread overview]
Message-ID: <20210524144903.2498518-27-sashal@kernel.org> (raw)
In-Reply-To: <20210524144903.2498518-1-sashal@kernel.org>

From: Phillip Potter <phil@philpotter.co.uk>

[ Upstream commit 5e70b8e22b64eed13d5bbebcb5911dae65bf8c6b ]

Check for return value from various snd_soc_dapm_* calls, as many of
them can return errors and this should be handled. Also, reintroduce
the allocation failure check for rt5645->eq_param as well. Make all
areas where return values are checked lead to the end of the function
in the case of an error. Finally, introduce a comment explaining how
resources here are actually eventually cleaned up by the caller.

Cc: Mark Brown <broonie@kernel.org>
Signed-off-by: Phillip Potter <phil@philpotter.co.uk>
Link: https://lore.kernel.org/r/20210503115736.2104747-56-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 sound/soc/codecs/rt5645.c | 48 +++++++++++++++++++++++++++++++--------
 1 file changed, 39 insertions(+), 9 deletions(-)

diff --git a/sound/soc/codecs/rt5645.c b/sound/soc/codecs/rt5645.c
index 44e88d0dbb7a..e9e1993e8d74 100644
--- a/sound/soc/codecs/rt5645.c
+++ b/sound/soc/codecs/rt5645.c
@@ -3376,30 +3376,44 @@ static int rt5645_probe(struct snd_soc_component *component)
 {
 	struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
 	struct rt5645_priv *rt5645 = snd_soc_component_get_drvdata(component);
+	int ret = 0;
 
 	rt5645->component = component;
 
 	switch (rt5645->codec_type) {
 	case CODEC_TYPE_RT5645:
-		snd_soc_dapm_new_controls(dapm,
+		ret = snd_soc_dapm_new_controls(dapm,
 			rt5645_specific_dapm_widgets,
 			ARRAY_SIZE(rt5645_specific_dapm_widgets));
-		snd_soc_dapm_add_routes(dapm,
+		if (ret < 0)
+			goto exit;
+
+		ret = snd_soc_dapm_add_routes(dapm,
 			rt5645_specific_dapm_routes,
 			ARRAY_SIZE(rt5645_specific_dapm_routes));
+		if (ret < 0)
+			goto exit;
+
 		if (rt5645->v_id < 3) {
-			snd_soc_dapm_add_routes(dapm,
+			ret = snd_soc_dapm_add_routes(dapm,
 				rt5645_old_dapm_routes,
 				ARRAY_SIZE(rt5645_old_dapm_routes));
+			if (ret < 0)
+				goto exit;
 		}
 		break;
 	case CODEC_TYPE_RT5650:
-		snd_soc_dapm_new_controls(dapm,
+		ret = snd_soc_dapm_new_controls(dapm,
 			rt5650_specific_dapm_widgets,
 			ARRAY_SIZE(rt5650_specific_dapm_widgets));
-		snd_soc_dapm_add_routes(dapm,
+		if (ret < 0)
+			goto exit;
+
+		ret = snd_soc_dapm_add_routes(dapm,
 			rt5650_specific_dapm_routes,
 			ARRAY_SIZE(rt5650_specific_dapm_routes));
+		if (ret < 0)
+			goto exit;
 		break;
 	}
 
@@ -3407,9 +3421,17 @@ static int rt5645_probe(struct snd_soc_component *component)
 
 	/* for JD function */
 	if (rt5645->pdata.jd_mode) {
-		snd_soc_dapm_force_enable_pin(dapm, "JD Power");
-		snd_soc_dapm_force_enable_pin(dapm, "LDO2");
-		snd_soc_dapm_sync(dapm);
+		ret = snd_soc_dapm_force_enable_pin(dapm, "JD Power");
+		if (ret < 0)
+			goto exit;
+
+		ret = snd_soc_dapm_force_enable_pin(dapm, "LDO2");
+		if (ret < 0)
+			goto exit;
+
+		ret = snd_soc_dapm_sync(dapm);
+		if (ret < 0)
+			goto exit;
 	}
 
 	if (rt5645->pdata.long_name)
@@ -3419,7 +3441,15 @@ static int rt5645_probe(struct snd_soc_component *component)
 		RT5645_HWEQ_NUM, sizeof(struct rt5645_eq_param_s),
 		GFP_KERNEL);
 
-	return 0;
+	if (!rt5645->eq_param)
+		ret = -ENOMEM;
+exit:
+	/*
+	 * If there was an error above, everything will be cleaned up by the
+	 * caller if we return an error here.  This will be done with a later
+	 * call to rt5645_remove().
+	 */
+	return ret;
 }
 
 static void rt5645_remove(struct snd_soc_component *component)
-- 
2.30.2


WARNING: multiple messages have this Message-ID (diff)
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Sasha Levin <sashal@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	alsa-devel@alsa-project.org, Mark Brown <broonie@kernel.org>,
	Phillip Potter <phil@philpotter.co.uk>
Subject: [PATCH AUTOSEL 5.4 27/52] ASoC: rt5645: add error checking to rt5645_probe function
Date: Mon, 24 May 2021 10:48:37 -0400	[thread overview]
Message-ID: <20210524144903.2498518-27-sashal@kernel.org> (raw)
In-Reply-To: <20210524144903.2498518-1-sashal@kernel.org>

From: Phillip Potter <phil@philpotter.co.uk>

[ Upstream commit 5e70b8e22b64eed13d5bbebcb5911dae65bf8c6b ]

Check for return value from various snd_soc_dapm_* calls, as many of
them can return errors and this should be handled. Also, reintroduce
the allocation failure check for rt5645->eq_param as well. Make all
areas where return values are checked lead to the end of the function
in the case of an error. Finally, introduce a comment explaining how
resources here are actually eventually cleaned up by the caller.

Cc: Mark Brown <broonie@kernel.org>
Signed-off-by: Phillip Potter <phil@philpotter.co.uk>
Link: https://lore.kernel.org/r/20210503115736.2104747-56-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 sound/soc/codecs/rt5645.c | 48 +++++++++++++++++++++++++++++++--------
 1 file changed, 39 insertions(+), 9 deletions(-)

diff --git a/sound/soc/codecs/rt5645.c b/sound/soc/codecs/rt5645.c
index 44e88d0dbb7a..e9e1993e8d74 100644
--- a/sound/soc/codecs/rt5645.c
+++ b/sound/soc/codecs/rt5645.c
@@ -3376,30 +3376,44 @@ static int rt5645_probe(struct snd_soc_component *component)
 {
 	struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
 	struct rt5645_priv *rt5645 = snd_soc_component_get_drvdata(component);
+	int ret = 0;
 
 	rt5645->component = component;
 
 	switch (rt5645->codec_type) {
 	case CODEC_TYPE_RT5645:
-		snd_soc_dapm_new_controls(dapm,
+		ret = snd_soc_dapm_new_controls(dapm,
 			rt5645_specific_dapm_widgets,
 			ARRAY_SIZE(rt5645_specific_dapm_widgets));
-		snd_soc_dapm_add_routes(dapm,
+		if (ret < 0)
+			goto exit;
+
+		ret = snd_soc_dapm_add_routes(dapm,
 			rt5645_specific_dapm_routes,
 			ARRAY_SIZE(rt5645_specific_dapm_routes));
+		if (ret < 0)
+			goto exit;
+
 		if (rt5645->v_id < 3) {
-			snd_soc_dapm_add_routes(dapm,
+			ret = snd_soc_dapm_add_routes(dapm,
 				rt5645_old_dapm_routes,
 				ARRAY_SIZE(rt5645_old_dapm_routes));
+			if (ret < 0)
+				goto exit;
 		}
 		break;
 	case CODEC_TYPE_RT5650:
-		snd_soc_dapm_new_controls(dapm,
+		ret = snd_soc_dapm_new_controls(dapm,
 			rt5650_specific_dapm_widgets,
 			ARRAY_SIZE(rt5650_specific_dapm_widgets));
-		snd_soc_dapm_add_routes(dapm,
+		if (ret < 0)
+			goto exit;
+
+		ret = snd_soc_dapm_add_routes(dapm,
 			rt5650_specific_dapm_routes,
 			ARRAY_SIZE(rt5650_specific_dapm_routes));
+		if (ret < 0)
+			goto exit;
 		break;
 	}
 
@@ -3407,9 +3421,17 @@ static int rt5645_probe(struct snd_soc_component *component)
 
 	/* for JD function */
 	if (rt5645->pdata.jd_mode) {
-		snd_soc_dapm_force_enable_pin(dapm, "JD Power");
-		snd_soc_dapm_force_enable_pin(dapm, "LDO2");
-		snd_soc_dapm_sync(dapm);
+		ret = snd_soc_dapm_force_enable_pin(dapm, "JD Power");
+		if (ret < 0)
+			goto exit;
+
+		ret = snd_soc_dapm_force_enable_pin(dapm, "LDO2");
+		if (ret < 0)
+			goto exit;
+
+		ret = snd_soc_dapm_sync(dapm);
+		if (ret < 0)
+			goto exit;
 	}
 
 	if (rt5645->pdata.long_name)
@@ -3419,7 +3441,15 @@ static int rt5645_probe(struct snd_soc_component *component)
 		RT5645_HWEQ_NUM, sizeof(struct rt5645_eq_param_s),
 		GFP_KERNEL);
 
-	return 0;
+	if (!rt5645->eq_param)
+		ret = -ENOMEM;
+exit:
+	/*
+	 * If there was an error above, everything will be cleaned up by the
+	 * caller if we return an error here.  This will be done with a later
+	 * call to rt5645_remove().
+	 */
+	return ret;
 }
 
 static void rt5645_remove(struct snd_soc_component *component)
-- 
2.30.2


  parent reply	other threads:[~2021-05-24 15:04 UTC|newest]

Thread overview: 78+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-24 14:48 [PATCH AUTOSEL 5.4 01/52] platform/x86: hp_accel: Avoid invoking _INI to speed up resume Sasha Levin
2021-05-24 14:48 ` [PATCH AUTOSEL 5.4 02/52] gpio: cadence: Add missing MODULE_DEVICE_TABLE Sasha Levin
2021-05-24 14:48 ` [PATCH AUTOSEL 5.4 03/52] Revert "media: usb: gspca: add a missed check for goto_low_power" Sasha Levin
2021-05-24 14:48 ` [PATCH AUTOSEL 5.4 04/52] Revert "ALSA: sb: fix a missing check of snd_ctl_add" Sasha Levin
2021-05-24 14:48   ` Sasha Levin
2021-05-24 14:48 ` [PATCH AUTOSEL 5.4 05/52] Revert "serial: max310x: pass return value of spi_register_driver" Sasha Levin
2021-05-24 14:48 ` [PATCH AUTOSEL 5.4 06/52] serial: max310x: unregister uart driver in case of failure and abort Sasha Levin
2021-05-24 14:48 ` [PATCH AUTOSEL 5.4 07/52] Revert "net: fujitsu: fix a potential NULL pointer dereference" Sasha Levin
2021-05-24 14:48 ` [PATCH AUTOSEL 5.4 08/52] net: fujitsu: fix potential null-ptr-deref Sasha Levin
2021-05-24 14:48 ` [PATCH AUTOSEL 5.4 09/52] Revert "net/smc: fix a NULL pointer dereference" Sasha Levin
2021-05-24 14:48 ` [PATCH AUTOSEL 5.4 10/52] net: caif: remove BUG_ON(dev == NULL) in caif_xmit Sasha Levin
2021-05-24 14:48 ` [PATCH AUTOSEL 5.4 11/52] Revert "char: hpet: fix a missing check of ioremap" Sasha Levin
2021-05-24 14:48 ` [PATCH AUTOSEL 5.4 12/52] char: hpet: add checks after calling ioremap Sasha Levin
2021-05-24 14:48 ` [PATCH AUTOSEL 5.4 13/52] Revert "ALSA: gus: add a check of the status of snd_ctl_add" Sasha Levin
2021-05-24 14:48   ` Sasha Levin
2021-05-24 14:48 ` [PATCH AUTOSEL 5.4 14/52] ALSA: sb8: Add a comment note regarding an unused pointer Sasha Levin
2021-05-24 14:48   ` Sasha Levin
2021-05-24 14:48 ` [PATCH AUTOSEL 5.4 15/52] Revert "ALSA: usx2y: Fix potential NULL pointer dereference" Sasha Levin
2021-05-24 14:48   ` Sasha Levin
2021-05-24 14:48 ` [PATCH AUTOSEL 5.4 16/52] Revert "isdn: mISDNinfineon: fix " Sasha Levin
2021-05-24 14:48 ` [PATCH AUTOSEL 5.4 17/52] isdn: mISDNinfineon: check/cleanup ioremap failure correctly in setup_io Sasha Levin
2021-05-24 14:48 ` [PATCH AUTOSEL 5.4 18/52] Revert "ath6kl: return error code in ath6kl_wmi_set_roam_lrssi_cmd()" Sasha Levin
2021-05-24 14:48 ` [PATCH AUTOSEL 5.4 19/52] ath6kl: return error code in ath6kl_wmi_set_roam_lrssi_cmd() Sasha Levin
2021-05-24 14:48 ` [PATCH AUTOSEL 5.4 20/52] Revert "isdn: mISDN: Fix potential NULL pointer dereference of kzalloc" Sasha Levin
2021-05-24 14:48 ` [PATCH AUTOSEL 5.4 21/52] isdn: mISDN: correctly handle ph_info allocation failure in hfcsusb_ph_info Sasha Levin
2021-05-24 14:48 ` [PATCH AUTOSEL 5.4 22/52] Revert "dmaengine: qcom_hidma: Check for driver register failure" Sasha Levin
2021-05-24 14:48   ` Sasha Levin
2021-05-24 14:48 ` [PATCH AUTOSEL 5.4 23/52] dmaengine: qcom_hidma: comment platform_driver_register call Sasha Levin
2021-05-24 14:48   ` Sasha Levin
2021-05-24 14:48 ` [PATCH AUTOSEL 5.4 24/52] Revert "libertas: add checks for the return value of sysfs_create_group" Sasha Levin
2021-05-24 14:48 ` [PATCH AUTOSEL 5.4 25/52] libertas: register sysfs groups properly Sasha Levin
2021-05-24 14:48 ` [PATCH AUTOSEL 5.4 26/52] Revert "ASoC: rt5645: fix a NULL pointer dereference" Sasha Levin
2021-05-24 14:48   ` Sasha Levin
2021-05-24 14:48 ` Sasha Levin [this message]
2021-05-24 14:48   ` [PATCH AUTOSEL 5.4 27/52] ASoC: rt5645: add error checking to rt5645_probe function Sasha Levin
2021-05-24 14:48 ` [PATCH AUTOSEL 5.4 28/52] Revert "ASoC: cs43130: fix a NULL pointer dereference" Sasha Levin
2021-05-24 14:48   ` Sasha Levin
2021-05-24 14:48 ` [PATCH AUTOSEL 5.4 29/52] ASoC: cs43130: handle errors in cs43130_probe() properly Sasha Levin
2021-05-24 14:48   ` Sasha Levin
2021-05-24 14:48 ` [PATCH AUTOSEL 5.4 30/52] Revert "media: dvb: Add check on sp8870_readreg" Sasha Levin
2021-05-24 14:48 ` [PATCH AUTOSEL 5.4 31/52] media: dvb: Add check on sp8870_readreg return Sasha Levin
2021-05-24 14:48 ` [PATCH AUTOSEL 5.4 32/52] Revert "media: gspca: mt9m111: Check write_bridge for timeout" Sasha Levin
2021-05-24 14:48 ` [PATCH AUTOSEL 5.4 33/52] media: gspca: mt9m111: Check write_bridge for timeout Sasha Levin
2021-05-24 14:48 ` [PATCH AUTOSEL 5.4 34/52] Revert "media: gspca: Check the return value of write_bridge for timeout" Sasha Levin
2021-05-24 14:48 ` [PATCH AUTOSEL 5.4 35/52] media: gspca: properly check for errors in po1030_probe() Sasha Levin
2021-05-24 14:48 ` [PATCH AUTOSEL 5.4 36/52] Revert "net: liquidio: fix a NULL pointer dereference" Sasha Levin
2021-05-24 14:48 ` [PATCH AUTOSEL 5.4 37/52] net: liquidio: Add missing null pointer checks Sasha Levin
2021-05-24 14:48 ` [PATCH AUTOSEL 5.4 38/52] Revert "brcmfmac: add a check for the status of usb_register" Sasha Levin
2021-05-24 14:48 ` [PATCH AUTOSEL 5.4 39/52] brcmfmac: properly check for bus register errors Sasha Levin
2021-05-25  6:38   ` Arend van Spriel
2021-05-25  6:43     ` Greg Kroah-Hartman
2021-05-25  7:04       ` Arend Van Spriel
2021-05-25  7:11         ` Greg Kroah-Hartman
2021-05-25  7:23         ` Arend van Spriel
2021-05-25  7:26           ` Greg Kroah-Hartman
2021-05-25  7:40             ` Arend van Spriel
2021-05-24 14:48 ` [PATCH AUTOSEL 5.4 40/52] cdrom: gdrom: initialize global variable at init time Sasha Levin
2021-05-24 14:48 ` [PATCH AUTOSEL 5.4 41/52] btrfs: return whole extents in fiemap Sasha Levin
2021-05-24 14:48 ` [PATCH AUTOSEL 5.4 42/52] scsi: BusLogic: Fix 64-bit system enumeration error for Buslogic Sasha Levin
2021-05-24 14:48 ` [PATCH AUTOSEL 5.4 43/52] openrisc: Define memory barrier mb Sasha Levin
2021-05-24 14:48   ` [OpenRISC] " Sasha Levin
2021-05-24 14:48 ` [PATCH AUTOSEL 5.4 44/52] btrfs: do not BUG_ON in link_to_fixup_dir Sasha Levin
2021-05-24 14:48 ` [PATCH AUTOSEL 5.4 45/52] platform/x86: hp-wireless: add AMD's hardware id to the supported list Sasha Levin
2021-05-24 14:48 ` [PATCH AUTOSEL 5.4 46/52] platform/x86: intel_punit_ipc: Append MODULE_DEVICE_TABLE for ACPI Sasha Levin
2021-05-24 14:48 ` [PATCH AUTOSEL 5.4 47/52] platform/x86: touchscreen_dmi: Add info for the Mediacom Winpad 7.0 W700 tablet Sasha Levin
2021-05-24 14:48 ` [PATCH AUTOSEL 5.4 48/52] SMB3: incorrect file id in requests compounded with open Sasha Levin
2021-05-24 14:48 ` [PATCH AUTOSEL 5.4 49/52] drm/amd/display: Disconnect non-DP with no EDID Sasha Levin
2021-05-24 14:48   ` Sasha Levin
2021-05-24 14:48   ` Sasha Levin
2021-05-24 14:49 ` [PATCH AUTOSEL 5.4 50/52] drm/amd/amdgpu: fix refcount leak Sasha Levin
2021-05-24 14:49   ` Sasha Levin
2021-05-24 14:49   ` Sasha Levin
2021-05-24 14:49 ` [PATCH AUTOSEL 5.4 51/52] drm/amdgpu: Fix a use-after-free Sasha Levin
2021-05-24 14:49   ` Sasha Levin
2021-05-24 14:49   ` Sasha Levin
2021-05-24 14:49 ` [PATCH AUTOSEL 5.4 52/52] drm/amd/amdgpu: fix a potential deadlock in gpu reset Sasha Levin
2021-05-24 14:49   ` Sasha Levin
2021-05-24 14:49   ` Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210524144903.2498518-27-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=phil@philpotter.co.uk \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.