Commit cc095f0a authored by Corey Minyard's avatar Corey Minyard

ipmi: Fix some error cleanup issues

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: default avatarCorey Minyard <cminyard@mvista.com>
Cc: stable@vger.kernel.org # 4.15
Cc: Laura Abbott <labbott@redhat.com>
Tested-by: default avatarBill Perkins <wmp@grnwood.net>
parent 243ac210
...@@ -232,6 +232,9 @@ struct smi_info { ...@@ -232,6 +232,9 @@ struct smi_info {
/* Default driver model device. */ /* Default driver model device. */
struct platform_device *pdev; struct platform_device *pdev;
/* Have we added the device group to the device? */
bool dev_group_added;
/* Counters and things for the proc filesystem. */ /* Counters and things for the proc filesystem. */
atomic_t stats[SI_NUM_STATS]; atomic_t stats[SI_NUM_STATS];
...@@ -2007,8 +2010,8 @@ int ipmi_si_add_smi(struct si_sm_io *io) ...@@ -2007,8 +2010,8 @@ int ipmi_si_add_smi(struct si_sm_io *io)
if (initialized) { if (initialized) {
rv = try_smi_init(new_smi); rv = try_smi_init(new_smi);
if (rv) { if (rv) {
mutex_unlock(&smi_infos_lock);
cleanup_one_si(new_smi); cleanup_one_si(new_smi);
mutex_unlock(&smi_infos_lock);
return rv; return rv;
} }
} }
...@@ -2167,6 +2170,7 @@ static int try_smi_init(struct smi_info *new_smi) ...@@ -2167,6 +2170,7 @@ static int try_smi_init(struct smi_info *new_smi)
rv); rv);
goto out_err_stop_timer; goto out_err_stop_timer;
} }
new_smi->dev_group_added = true;
rv = ipmi_register_smi(&handlers, rv = ipmi_register_smi(&handlers,
new_smi, new_smi,
...@@ -2220,7 +2224,10 @@ static int try_smi_init(struct smi_info *new_smi) ...@@ -2220,7 +2224,10 @@ static int try_smi_init(struct smi_info *new_smi)
return 0; return 0;
out_err_remove_attrs: 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); dev_set_drvdata(new_smi->io.dev, NULL);
out_err_stop_timer: out_err_stop_timer:
...@@ -2268,6 +2275,7 @@ static int try_smi_init(struct smi_info *new_smi) ...@@ -2268,6 +2275,7 @@ static int try_smi_init(struct smi_info *new_smi)
else else
platform_device_put(new_smi->pdev); platform_device_put(new_smi->pdev);
new_smi->pdev = NULL; new_smi->pdev = NULL;
new_smi->io.dev = NULL;
} }
kfree(init_name); kfree(init_name);
...@@ -2364,8 +2372,10 @@ static void cleanup_one_si(struct smi_info *to_clean) ...@@ -2364,8 +2372,10 @@ static void cleanup_one_si(struct smi_info *to_clean)
} }
} }
device_remove_group(to_clean->io.dev, &ipmi_si_dev_attr_group); if (to_clean->dev_group_added)
dev_set_drvdata(to_clean->io.dev, NULL); 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); list_del(&to_clean->link);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment