diff options
Diffstat (limited to 'io-module/mtac_mfser.c')
-rw-r--r-- | io-module/mtac_mfser.c | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/io-module/mtac_mfser.c b/io-module/mtac_mfser.c index 5871bfe..207180f 100644 --- a/io-module/mtac_mfser.c +++ b/io-module/mtac_mfser.c @@ -190,6 +190,7 @@ static ssize_t mts_attr_store_mfser_mode(struct kobject *kobj, static int ap_mfser_attrs_size = 3; static bool mfser_setup(enum ap port) { + int port_index = port - 1; struct kobj_attribute *attr; char buf[32]; @@ -200,6 +201,10 @@ static bool mfser_setup(enum ap port) { return false; } + // mark the attribute indices we're using so we know what to clean up + port_info[port_index]->attrs_start = device_attrs_size; + port_info[port_index]->attrs_end = device_attrs_size + ap_mfser_attrs_size; + sprintf(buf, "serial-mode:%d", port); attr = create_attribute(buf, MTS_ATTR_MODE_RW); if (! attr) { @@ -234,12 +239,33 @@ static bool mfser_setup(enum ap port) { } static bool mfser_teardown(enum ap port) { + int i; + int port_index = port - 1; + log_info("unloading MFSER accessory card in port %d", port); + + // clean up allocated memory for attributes + for (i = port_info[port_index]->attrs_start; i < port_info[port_index]->attrs_end; i++) { + if (device_attrs[i]) { + if (device_attrs[i]->name) + kfree(device_attrs[i]->name); + + kfree(device_attrs[i]); + } + } + + port_info[port_index]->attrs_start = 0; + port_info[port_index]->attrs_end = 0; + return true; } -static struct ap_info mfser_info = { - .product_id = MTAC_MFSER_0_0, - .setup = &mfser_setup, - .teardown = &mfser_teardown -}; +bool set_mfser_info(struct ap_info* info) { + info->product_id = MTAC_MFSER_0_0; + info->setup = &mfser_setup; + info->teardown = &mfser_teardown; + info->attrs_start = 0; + info->attrs_end = 0; + + return true; +} |