summaryrefslogtreecommitdiff
path: root/io-module/mtac_gpiob.c
diff options
context:
space:
mode:
authorMike Fiore <mfiore@multitech.com>2014-09-25 14:03:36 -0500
committerMike Fiore <mfiore@multitech.com>2014-09-25 14:03:36 -0500
commitc83b0cf41999478d31c86fb50740d1fdf0fbb003 (patch)
treeab45043d74eda998a5dac1d270697731d8a40652 /io-module/mtac_gpiob.c
parenta21c24fa2486e4d4a3b25d0dcbf873ae62fdbcec (diff)
downloadmts-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_gpiob.c')
-rw-r--r--io-module/mtac_gpiob.c45
1 files changed, 39 insertions, 6 deletions
diff --git a/io-module/mtac_gpiob.c b/io-module/mtac_gpiob.c
index 728634d..f2cd9b2 100644
--- a/io-module/mtac_gpiob.c
+++ b/io-module/mtac_gpiob.c
@@ -395,6 +395,10 @@ static bool gpiob_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_gpiob_attrs_size;
+
// add digital inputs
for (i = 0; i < 4; i++) {
sprintf(buf, "din%d:%d", i, port);
@@ -506,18 +510,47 @@ static bool gpiob_setup(enum ap port) {
}
static bool gpiob_teardown(enum ap port) {
+ int i;
int port_index = port - 1;
- // do we need to clean up allocated memory here as well?
log_info("unloading GPIOB 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]);
+ }
+ }
+
+ // clean up allocated memory for SPI drivers
+ if (gpiob_spi_drivers[port_index][dout].driver.name)
+ kfree(gpiob_spi_drivers[port_index][dout].driver.name);
+ if (gpiob_spi_drivers[port_index][din].driver.name)
+ kfree(gpiob_spi_drivers[port_index][din].driver.name);
+ if (gpiob_spi_drivers[port_index][adc].driver.name)
+ kfree(gpiob_spi_drivers[port_index][adc].driver.name);
+
+ // unregister SPI drivers
spi_unregister_driver(&gpiob_spi_drivers[port_index][dout]);
spi_unregister_driver(&gpiob_spi_drivers[port_index][din]);
spi_unregister_driver(&gpiob_spi_drivers[port_index][adc]);
+
+ // reset attribute index markers
+ port_info[port_index]->attrs_start = 0;
+ port_info[port_index]->attrs_end = 0;
+
return true;
}
-static struct ap_info gpiob_info = {
- .product_id = MTAC_GPIOB_0_0,
- .setup = &gpiob_setup,
- .teardown = &gpiob_teardown
-};
+bool set_gpiob_info(struct ap_info* info) {
+ info->product_id = MTAC_GPIOB_0_0;
+ info->setup = &gpiob_setup;
+ info->teardown = &gpiob_teardown;
+ info->attrs_start = 0;
+ info->attrs_end = 0;
+
+ return true;
+}