summaryrefslogtreecommitdiff
path: root/io-module
diff options
context:
space:
mode:
authorJohn Klug <john.klug@multitech.com>2016-09-26 11:34:33 -0500
committerJohn Klug <john.klug@multitech.com>2016-09-26 11:34:33 -0500
commit7a1ed1a7788c76630723d9f0f49f3862ca6fb300 (patch)
tree14c4dc9266a903accb77cff5ea512b1c9594d0a0 /io-module
parent3ddd85624735a0c730672a5bc440adffecc7725c (diff)
downloadmts-io-7a1ed1a7788c76630723d9f0f49f3862ca6fb300.tar.gz
mts-io-7a1ed1a7788c76630723d9f0f49f3862ca6fb300.tar.bz2
mts-io-7a1ed1a7788c76630723d9f0f49f3862ca6fb300.zip
Fix lora cleanup code for error cases.
Diffstat (limited to 'io-module')
-rw-r--r--io-module/mtac_lora.c36
1 files changed, 20 insertions, 16 deletions
diff --git a/io-module/mtac_lora.c b/io-module/mtac_lora.c
index 8616d21..3668f67 100644
--- a/io-module/mtac_lora.c
+++ b/io-module/mtac_lora.c
@@ -82,6 +82,7 @@ static bool lora_setup(enum ap port) {
lora_hw_version = MTAC_LORA_1_0;
else {
log_error("Unknown hw-version in port %d", port);
+ kfree(attrs);
return false;
}
@@ -91,6 +92,7 @@ static bool lora_setup(enum ap port) {
attr = create_attribute(buf, MTS_ATTR_MODE_RW);
if (! attr) {
log_error("failed to create attribute [%s] for LORA in port %d", buf, port);
+ kfree(attrs);
return false;
}
attr->show = mts_attr_show_ap_gpio_pin;
@@ -99,14 +101,15 @@ static bool lora_setup(enum ap port) {
}
// add attributes for eeprom contents
- if (! ap_add_product_info_attributes(port, lora_hw_version, attrs, &index)) {
+ ret = ap_add_product_info_attributes(port, lora_hw_version, attrs, &index);
+ attrs[index] = NULL;
+ ap_attr_groups[port_index].attrs = attrs;
+
+ if (!ret) {
log_error("failed to add product info attributes for LORA in port %d", port);
return false;
}
- attrs[index] = NULL;
-
- ap_attr_groups[port_index].attrs = attrs;
if (sysfs_create_group(ap_subdirs[port_index], &ap_attr_groups[port_index])) {
log_error("sysfs_create_group failed for LORA in port %d", port);
return false;
@@ -121,19 +124,20 @@ static bool lora_teardown(enum ap port) {
struct attribute **attrs = ap_attr_groups[port_index].attrs;
log_info("unloading LORA accessory card in port %d", port);
-
- // clean up allocated memory for attributes
- for (i = 0; i < ap_lora_attrs_size; i++) {
- if (attrs[i]) {
- if (attrs[i]->name)
- kfree(attrs[i]->name);
-
- kfree(attrs[i]);
- }
+
+ if(attrs) {
+ // clean up allocated memory for attributes
+ for (i = 0; i < ap_lora_attrs_size; i++) {
+ if (attrs[i]) {
+ if (attrs[i]->name)
+ kfree(attrs[i]->name);
+
+ kfree(attrs[i]);
+ }
+ }
+
+ kfree(attrs);
}
-
- kfree(attrs);
-
// clean up our "apX/" kobject if it exists
if (ap_subdirs[port_index]) {
kobject_put(ap_subdirs[port_index]);