diff options
author | Mike Fiore <mfiore@multitech.com> | 2014-09-25 14:03:36 -0500 |
---|---|---|
committer | Mike Fiore <mfiore@multitech.com> | 2014-09-25 14:03:36 -0500 |
commit | c83b0cf41999478d31c86fb50740d1fdf0fbb003 (patch) | |
tree | ab45043d74eda998a5dac1d270697731d8a40652 /io-module/mtac_mfser.c | |
parent | a21c24fa2486e4d4a3b25d0dcbf873ae62fdbcec (diff) | |
download | mts-io-c83b0cf41999478d31c86fb50740d1fdf0fbb003.tar.gz mts-io-c83b0cf41999478d31c86fb50740d1fdf0fbb003.tar.bz2 mts-io-c83b0cf41999478d31c86fb50740d1fdf0fbb003.zip |
mts-io: clean up memory allocated for accessory cards on module unload or setup failure
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; +} |