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: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Mark Brown <broonie@kernel.org>, Sasha Levin <sashal@kernel.org>,
	alsa-devel@alsa-project.org, patches@opensource.cirrus.com
Subject: [PATCH AUTOSEL 4.19 12/25] ASoC: cs43130: handle errors in cs43130_probe() properly
Date: Mon, 24 May 2021 10:49:55 -0400	[thread overview]
Message-ID: <20210524145008.2499049-12-sashal@kernel.org> (raw)
In-Reply-To: <20210524145008.2499049-1-sashal@kernel.org>

From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

[ Upstream commit 2da441a6491d93eff8ffff523837fd621dc80389 ]

cs43130_probe() does not do any valid error checking of things it
initializes, OR what it does, it does not unwind properly if there are
errors.

Fix this up by moving the sysfs files to an attribute group so the
driver core will correctly add/remove them all at once and handle errors
with them, and correctly check for creating a new workqueue and
unwinding if that fails.

Cc: Mark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/r/20210503115736.2104747-58-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 sound/soc/codecs/cs43130.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/sound/soc/codecs/cs43130.c b/sound/soc/codecs/cs43130.c
index 80dc42197154..cf29dec28b5e 100644
--- a/sound/soc/codecs/cs43130.c
+++ b/sound/soc/codecs/cs43130.c
@@ -1738,6 +1738,14 @@ static DEVICE_ATTR(hpload_dc_r, 0444, cs43130_show_dc_r, NULL);
 static DEVICE_ATTR(hpload_ac_l, 0444, cs43130_show_ac_l, NULL);
 static DEVICE_ATTR(hpload_ac_r, 0444, cs43130_show_ac_r, NULL);
 
+static struct attribute *hpload_attrs[] = {
+	&dev_attr_hpload_dc_l.attr,
+	&dev_attr_hpload_dc_r.attr,
+	&dev_attr_hpload_ac_l.attr,
+	&dev_attr_hpload_ac_r.attr,
+};
+ATTRIBUTE_GROUPS(hpload);
+
 static struct reg_sequence hp_en_cal_seq[] = {
 	{CS43130_INT_MASK_4, CS43130_INT_MASK_ALL},
 	{CS43130_HP_MEAS_LOAD_1, 0},
@@ -2305,23 +2313,15 @@ static int cs43130_probe(struct snd_soc_component *component)
 
 	cs43130->hpload_done = false;
 	if (cs43130->dc_meas) {
-		ret = device_create_file(component->dev, &dev_attr_hpload_dc_l);
-		if (ret < 0)
-			return ret;
-
-		ret = device_create_file(component->dev, &dev_attr_hpload_dc_r);
-		if (ret < 0)
-			return ret;
-
-		ret = device_create_file(component->dev, &dev_attr_hpload_ac_l);
-		if (ret < 0)
-			return ret;
-
-		ret = device_create_file(component->dev, &dev_attr_hpload_ac_r);
-		if (ret < 0)
+		ret = sysfs_create_groups(&component->dev->kobj, hpload_groups);
+		if (ret)
 			return ret;
 
 		cs43130->wq = create_singlethread_workqueue("cs43130_hp");
+		if (!cs43130->wq) {
+			sysfs_remove_groups(&component->dev->kobj, hpload_groups);
+			return -ENOMEM;
+		}
 		INIT_WORK(&cs43130->work, cs43130_imp_meas);
 	}
 
-- 
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>,
	patches@opensource.cirrus.com
Subject: [PATCH AUTOSEL 4.19 12/25] ASoC: cs43130: handle errors in cs43130_probe() properly
Date: Mon, 24 May 2021 10:49:55 -0400	[thread overview]
Message-ID: <20210524145008.2499049-12-sashal@kernel.org> (raw)
In-Reply-To: <20210524145008.2499049-1-sashal@kernel.org>

From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

[ Upstream commit 2da441a6491d93eff8ffff523837fd621dc80389 ]

cs43130_probe() does not do any valid error checking of things it
initializes, OR what it does, it does not unwind properly if there are
errors.

Fix this up by moving the sysfs files to an attribute group so the
driver core will correctly add/remove them all at once and handle errors
with them, and correctly check for creating a new workqueue and
unwinding if that fails.

Cc: Mark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/r/20210503115736.2104747-58-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 sound/soc/codecs/cs43130.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/sound/soc/codecs/cs43130.c b/sound/soc/codecs/cs43130.c
index 80dc42197154..cf29dec28b5e 100644
--- a/sound/soc/codecs/cs43130.c
+++ b/sound/soc/codecs/cs43130.c
@@ -1738,6 +1738,14 @@ static DEVICE_ATTR(hpload_dc_r, 0444, cs43130_show_dc_r, NULL);
 static DEVICE_ATTR(hpload_ac_l, 0444, cs43130_show_ac_l, NULL);
 static DEVICE_ATTR(hpload_ac_r, 0444, cs43130_show_ac_r, NULL);
 
+static struct attribute *hpload_attrs[] = {
+	&dev_attr_hpload_dc_l.attr,
+	&dev_attr_hpload_dc_r.attr,
+	&dev_attr_hpload_ac_l.attr,
+	&dev_attr_hpload_ac_r.attr,
+};
+ATTRIBUTE_GROUPS(hpload);
+
 static struct reg_sequence hp_en_cal_seq[] = {
 	{CS43130_INT_MASK_4, CS43130_INT_MASK_ALL},
 	{CS43130_HP_MEAS_LOAD_1, 0},
@@ -2305,23 +2313,15 @@ static int cs43130_probe(struct snd_soc_component *component)
 
 	cs43130->hpload_done = false;
 	if (cs43130->dc_meas) {
-		ret = device_create_file(component->dev, &dev_attr_hpload_dc_l);
-		if (ret < 0)
-			return ret;
-
-		ret = device_create_file(component->dev, &dev_attr_hpload_dc_r);
-		if (ret < 0)
-			return ret;
-
-		ret = device_create_file(component->dev, &dev_attr_hpload_ac_l);
-		if (ret < 0)
-			return ret;
-
-		ret = device_create_file(component->dev, &dev_attr_hpload_ac_r);
-		if (ret < 0)
+		ret = sysfs_create_groups(&component->dev->kobj, hpload_groups);
+		if (ret)
 			return ret;
 
 		cs43130->wq = create_singlethread_workqueue("cs43130_hp");
+		if (!cs43130->wq) {
+			sysfs_remove_groups(&component->dev->kobj, hpload_groups);
+			return -ENOMEM;
+		}
 		INIT_WORK(&cs43130->work, cs43130_imp_meas);
 	}
 
-- 
2.30.2


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

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-24 14:49 [PATCH AUTOSEL 4.19 01/25] platform/x86: hp_accel: Avoid invoking _INI to speed up resume Sasha Levin
2021-05-24 14:49 ` [PATCH AUTOSEL 4.19 02/25] serial: max310x: unregister uart driver in case of failure and abort Sasha Levin
2021-05-24 14:49 ` [PATCH AUTOSEL 4.19 03/25] net: fujitsu: fix potential null-ptr-deref Sasha Levin
2021-05-24 14:49 ` [PATCH AUTOSEL 4.19 04/25] net: caif: remove BUG_ON(dev == NULL) in caif_xmit Sasha Levin
2021-05-24 14:49 ` [PATCH AUTOSEL 4.19 05/25] char: hpet: add checks after calling ioremap Sasha Levin
2021-05-24 14:49 ` [PATCH AUTOSEL 4.19 06/25] ALSA: sb8: Add a comment note regarding an unused pointer Sasha Levin
2021-05-24 14:49   ` Sasha Levin
2021-05-24 14:49 ` [PATCH AUTOSEL 4.19 07/25] isdn: mISDNinfineon: check/cleanup ioremap failure correctly in setup_io Sasha Levin
2021-05-24 14:49 ` [PATCH AUTOSEL 4.19 08/25] ath6kl: return error code in ath6kl_wmi_set_roam_lrssi_cmd() Sasha Levin
2021-05-24 14:49 ` [PATCH AUTOSEL 4.19 09/25] dmaengine: qcom_hidma: comment platform_driver_register call Sasha Levin
2021-05-24 14:49   ` Sasha Levin
2021-05-24 14:49 ` [PATCH AUTOSEL 4.19 10/25] libertas: register sysfs groups properly Sasha Levin
2021-05-24 14:49 ` [PATCH AUTOSEL 4.19 11/25] ASoC: rt5645: add error checking to rt5645_probe function Sasha Levin
2021-05-24 14:49   ` Sasha Levin
2021-05-24 14:49 ` Sasha Levin [this message]
2021-05-24 14:49   ` [PATCH AUTOSEL 4.19 12/25] ASoC: cs43130: handle errors in cs43130_probe() properly Sasha Levin
2021-05-24 14:49 ` [PATCH AUTOSEL 4.19 13/25] media: dvb: Add check on sp8870_readreg return Sasha Levin
2021-05-24 14:49 ` [PATCH AUTOSEL 4.19 14/25] media: gspca: mt9m111: Check write_bridge for timeout Sasha Levin
2021-05-24 14:49 ` [PATCH AUTOSEL 4.19 15/25] media: gspca: properly check for errors in po1030_probe() Sasha Levin
2021-05-24 14:49 ` [PATCH AUTOSEL 4.19 16/25] cdrom: gdrom: initialize global variable at init time Sasha Levin
2021-05-24 14:50 ` [PATCH AUTOSEL 4.19 17/25] scsi: BusLogic: Fix 64-bit system enumeration error for Buslogic Sasha Levin
2021-05-24 14:50 ` [PATCH AUTOSEL 4.19 18/25] openrisc: Define memory barrier mb Sasha Levin
2021-05-24 14:50   ` [OpenRISC] " Sasha Levin
2021-05-24 14:50 ` [PATCH AUTOSEL 4.19 19/25] btrfs: do not BUG_ON in link_to_fixup_dir Sasha Levin
2021-05-24 14:50 ` [PATCH AUTOSEL 4.19 20/25] platform/x86: hp-wireless: add AMD's hardware id to the supported list Sasha Levin
2021-05-24 14:50 ` [PATCH AUTOSEL 4.19 21/25] platform/x86: intel_punit_ipc: Append MODULE_DEVICE_TABLE for ACPI Sasha Levin
2021-05-24 14:50 ` [PATCH AUTOSEL 4.19 22/25] SMB3: incorrect file id in requests compounded with open Sasha Levin
2021-05-24 14:50 ` [PATCH AUTOSEL 4.19 23/25] drm/amd/display: Disconnect non-DP with no EDID Sasha Levin
2021-05-24 14:50   ` Sasha Levin
2021-05-24 14:50   ` Sasha Levin
2021-05-24 14:50 ` [PATCH AUTOSEL 4.19 24/25] drm/amd/amdgpu: fix refcount leak Sasha Levin
2021-05-24 14:50   ` Sasha Levin
2021-05-24 14:50   ` Sasha Levin
2021-05-24 14:50 ` [PATCH AUTOSEL 4.19 25/25] drm/amdgpu: Fix a use-after-free Sasha Levin
2021-05-24 14:50   ` Sasha Levin
2021-05-24 14:50   ` 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=20210524145008.2499049-12-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=patches@opensource.cirrus.com \
    --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.