summaryrefslogtreecommitdiff
path: root/io-module/mtac_lora.c
diff options
context:
space:
mode:
Diffstat (limited to 'io-module/mtac_lora.c')
-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]);