[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20180417155749.908755011@linuxfoundation.org>
Date: Tue, 17 Apr 2018 17:57:27 +0200
From: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
To: linux-kernel@...r.kernel.org
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
stable@...r.kernel.org, Corey Minyard <cminyard@...sta.com>,
Laura Abbott <labbott@...hat.com>,
Bill Perkins <wmp@...wood.net>
Subject: [PATCH 4.16 14/68] ipmi: Fix some error cleanup issues
4.16-stable review patch. If anyone has any objections, please let me know.
------------------
From: Corey Minyard <cminyard@...sta.com>
commit cc095f0ac1f7c200e51a5c2a78a43c9f42049dbb upstream.
device_remove_group() was called on any cleanup, even if the
device attrs had not been added yet. That can occur in certain
error scenarios, so add a flag to know if it has been added.
Also make sure we remove the dev if we added it ourselves.
Signed-off-by: Corey Minyard <cminyard@...sta.com>
Cc: stable@...r.kernel.org # 4.15
Cc: Laura Abbott <labbott@...hat.com>
Tested-by: Bill Perkins <wmp@...wood.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
---
drivers/char/ipmi/ipmi_si_intf.c | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
--- a/drivers/char/ipmi/ipmi_si_intf.c
+++ b/drivers/char/ipmi/ipmi_si_intf.c
@@ -252,6 +252,9 @@ struct smi_info {
/* Default driver model device. */
struct platform_device *pdev;
+ /* Have we added the device group to the device? */
+ bool dev_group_added;
+
/* Counters and things for the proc filesystem. */
atomic_t stats[SI_NUM_STATS];
@@ -2027,8 +2030,8 @@ int ipmi_si_add_smi(struct si_sm_io *io)
if (initialized) {
rv = try_smi_init(new_smi);
if (rv) {
- mutex_unlock(&smi_infos_lock);
cleanup_one_si(new_smi);
+ mutex_unlock(&smi_infos_lock);
return rv;
}
}
@@ -2187,6 +2190,7 @@ static int try_smi_init(struct smi_info
rv);
goto out_err_stop_timer;
}
+ new_smi->dev_group_added = true;
rv = ipmi_register_smi(&handlers,
new_smi,
@@ -2240,7 +2244,10 @@ static int try_smi_init(struct smi_info
return 0;
out_err_remove_attrs:
- device_remove_group(new_smi->io.dev, &ipmi_si_dev_attr_group);
+ if (new_smi->dev_group_added) {
+ device_remove_group(new_smi->io.dev, &ipmi_si_dev_attr_group);
+ new_smi->dev_group_added = false;
+ }
dev_set_drvdata(new_smi->io.dev, NULL);
out_err_stop_timer:
@@ -2288,6 +2295,7 @@ out_err:
else
platform_device_put(new_smi->pdev);
new_smi->pdev = NULL;
+ new_smi->io.dev = NULL;
}
kfree(init_name);
@@ -2384,8 +2392,10 @@ static void cleanup_one_si(struct smi_in
}
}
- device_remove_group(to_clean->io.dev, &ipmi_si_dev_attr_group);
- dev_set_drvdata(to_clean->io.dev, NULL);
+ if (to_clean->dev_group_added)
+ device_remove_group(to_clean->io.dev, &ipmi_si_dev_attr_group);
+ if (to_clean->io.dev)
+ dev_set_drvdata(to_clean->io.dev, NULL);
list_del(&to_clean->link);
Powered by blists - more mailing lists