diff options
author | Corey Minyard <cminyard@mvista.com> | 2018-02-28 09:09:49 -0500 |
---|---|---|
committer | Corey Minyard <cminyard@mvista.com> | 2018-03-06 20:47:17 -0500 |
commit | cc095f0ac1f7c200e51a5c2a78a43c9f42049dbb (patch) | |
tree | cea28774af6227161791960af5b705b0999d9c88 | |
parent | 243ac21035176ac9692c1308a9f3b8f6a4e5d733 (diff) |
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: Corey Minyard <cminyard@mvista.com>
Cc: stable@vger.kernel.org # 4.15
Cc: Laura Abbott <labbott@redhat.com>
Tested-by: Bill Perkins <wmp@grnwood.net>
-rw-r--r-- | drivers/char/ipmi/ipmi_si_intf.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c index 5141ccf0b958..2b9f434775d4 100644 --- a/drivers/char/ipmi/ipmi_si_intf.c +++ b/drivers/char/ipmi/ipmi_si_intf.c | |||
@@ -232,6 +232,9 @@ struct smi_info { | |||
232 | /* Default driver model device. */ | 232 | /* Default driver model device. */ |
233 | struct platform_device *pdev; | 233 | struct platform_device *pdev; |
234 | 234 | ||
235 | /* Have we added the device group to the device? */ | ||
236 | bool dev_group_added; | ||
237 | |||
235 | /* Counters and things for the proc filesystem. */ | 238 | /* Counters and things for the proc filesystem. */ |
236 | atomic_t stats[SI_NUM_STATS]; | 239 | atomic_t stats[SI_NUM_STATS]; |
237 | 240 | ||
@@ -2007,8 +2010,8 @@ int ipmi_si_add_smi(struct si_sm_io *io) | |||
2007 | if (initialized) { | 2010 | if (initialized) { |
2008 | rv = try_smi_init(new_smi); | 2011 | rv = try_smi_init(new_smi); |
2009 | if (rv) { | 2012 | if (rv) { |
2010 | mutex_unlock(&smi_infos_lock); | ||
2011 | cleanup_one_si(new_smi); | 2013 | cleanup_one_si(new_smi); |
2014 | mutex_unlock(&smi_infos_lock); | ||
2012 | return rv; | 2015 | return rv; |
2013 | } | 2016 | } |
2014 | } | 2017 | } |
@@ -2167,6 +2170,7 @@ static int try_smi_init(struct smi_info *new_smi) | |||
2167 | rv); | 2170 | rv); |
2168 | goto out_err_stop_timer; | 2171 | goto out_err_stop_timer; |
2169 | } | 2172 | } |
2173 | new_smi->dev_group_added = true; | ||
2170 | 2174 | ||
2171 | rv = ipmi_register_smi(&handlers, | 2175 | rv = ipmi_register_smi(&handlers, |
2172 | new_smi, | 2176 | new_smi, |
@@ -2220,7 +2224,10 @@ static int try_smi_init(struct smi_info *new_smi) | |||
2220 | return 0; | 2224 | return 0; |
2221 | 2225 | ||
2222 | out_err_remove_attrs: | 2226 | out_err_remove_attrs: |
2223 | device_remove_group(new_smi->io.dev, &ipmi_si_dev_attr_group); | 2227 | if (new_smi->dev_group_added) { |
2228 | device_remove_group(new_smi->io.dev, &ipmi_si_dev_attr_group); | ||
2229 | new_smi->dev_group_added = false; | ||
2230 | } | ||
2224 | dev_set_drvdata(new_smi->io.dev, NULL); | 2231 | dev_set_drvdata(new_smi->io.dev, NULL); |
2225 | 2232 | ||
2226 | out_err_stop_timer: | 2233 | out_err_stop_timer: |
@@ -2268,6 +2275,7 @@ out_err: | |||
2268 | else | 2275 | else |
2269 | platform_device_put(new_smi->pdev); | 2276 | platform_device_put(new_smi->pdev); |
2270 | new_smi->pdev = NULL; | 2277 | new_smi->pdev = NULL; |
2278 | new_smi->io.dev = NULL; | ||
2271 | } | 2279 | } |
2272 | 2280 | ||
2273 | kfree(init_name); | 2281 | kfree(init_name); |
@@ -2364,8 +2372,10 @@ static void cleanup_one_si(struct smi_info *to_clean) | |||
2364 | } | 2372 | } |
2365 | } | 2373 | } |
2366 | 2374 | ||
2367 | device_remove_group(to_clean->io.dev, &ipmi_si_dev_attr_group); | 2375 | if (to_clean->dev_group_added) |
2368 | dev_set_drvdata(to_clean->io.dev, NULL); | 2376 | device_remove_group(to_clean->io.dev, &ipmi_si_dev_attr_group); |
2377 | if (to_clean->io.dev) | ||
2378 | dev_set_drvdata(to_clean->io.dev, NULL); | ||
2369 | 2379 | ||
2370 | list_del(&to_clean->link); | 2380 | list_del(&to_clean->link); |
2371 | 2381 | ||