From 672a21b3815cb6ebafa636067b5fd0bc9fd9460a Mon Sep 17 00:00:00 2001 From: Mykyta Dorokhin Date: Mon, 5 Sep 2016 11:14:51 +0300 Subject: Fix build issues in case NUM_AP is 0. --- io-module/mts_io.c | 93 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 49 insertions(+), 44 deletions(-) diff --git a/io-module/mts_io.c b/io-module/mts_io.c index 2454821..deb2d92 100644 --- a/io-module/mts_io.c +++ b/io-module/mts_io.c @@ -74,18 +74,6 @@ static struct mts_id_eeprom_layout id_eeprom; #define NUM_AP 0 #endif -#if NUM_AP > 0 -/* accessory card EEPROMs */ -extern uint8_t mts_ap_eeprom[NUM_AP][512]; -static struct mts_ap_eeprom_layout ap_eeprom[NUM_AP]; -/* kobject pointers for the apX subdirectories that correspond to the accessory ports */ -static struct kobject *ap_subdirs[NUM_AP]; -/* attribute groups for the accessory ports*/ -static struct attribute_group ap_attr_groups[NUM_AP]; -#endif - -static struct ap_info* port_info[NUM_AP]; - static struct platform_device *mts_io_platform_device; static struct attribute_group *attr_group; static struct gpio_pin *gpio_pins; @@ -100,20 +88,13 @@ static struct timer_list radio_reset_timer; static volatile int radio_reset_timer_is_start = 0; static struct timer_list radio_reset_available_timer; static volatile int radio_reset_available_timer_is_start = 0; -static time_t time_now_secs(); +static time_t time_now_secs(void); static void radio_reset_available_timer_callback(unsigned long data); static void radio_reset_timer_callback(unsigned long data); /* generic GPIO support */ #include "gpio.c" -/* accessory card support */ -#include "mtac.c" -#include "mtac_gpiob.c" -#include "mtac_mfser.c" -#include "mtac_eth.c" -#include "mtac_lora.c" - /* reset button handling */ #define RESET_CHECK_PER_SEC 8 #define RESET_INTERVAL (HZ / RESET_CHECK_PER_SEC) @@ -333,7 +314,7 @@ static DEVICE_ATTR_MTS(dev_attr_radio_power, "radio-power", mts_attr_show_gpio_pin, mts_attr_store_gpio_pin); /* backoff-timers */ -static time_t time_now_secs() +static time_t time_now_secs(void) { struct timespec ts = current_kernel_time(); return ts.tv_sec; @@ -457,7 +438,6 @@ static ssize_t mts_attr_store_radio_reset_backoffs_index(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { int value; - int err; if (sscanf(buf, "%d", &value) != 1) { return -EINVAL; @@ -644,6 +624,25 @@ static DEVICE_ATTR_RO_MTS(dev_attr_eth_mac, "mac-eth", /* include per-device pins and attributes */ #include "mtcdt.c" +#if NUM_AP > 0 + +/* accessory card EEPROMs */ +extern uint8_t mts_ap_eeprom[NUM_AP][512]; +static struct mts_ap_eeprom_layout ap_eeprom[NUM_AP]; +/* kobject pointers for the apX subdirectories that correspond to the accessory ports */ +static struct kobject *ap_subdirs[NUM_AP]; +/* attribute groups for the accessory ports*/ +static struct attribute_group ap_attr_groups[NUM_AP]; +/* info for accessory port (contains function pointers for setup and teardown and and useful info) */ +static struct ap_info* port_info[NUM_AP]; + +/* accessory card support */ +#include "mtac.c" +#include "mtac_gpiob.c" +#include "mtac_mfser.c" +#include "mtac_eth.c" +#include "mtac_lora.c" + static bool load_port(int port) { int port_index = port - 1; memcpy(&ap_eeprom[port_index], mts_ap_eeprom[port_index], sizeof(mts_ap_eeprom[port_index])); @@ -727,14 +726,32 @@ static bool load_port(int port) { static void init_accessory_ports(void) { - int i; - for (i = 1; i <= NUM_AP; i++) { - if (! load_port(i)) { - log_error("failed to load accessory card in port %d", i); - } - } + int port_index; + + for (port_index = 0; port_index < NUM_AP; port_index++) { + port_info[port_index] = NULL; + if (! load_port(port_index+1)) { + log_error("failed to load accessory card in port %d", port_index); + } + } } +static void teardown_accessory_ports(void) +{ + int port_index; + + for (port_index = 0; port_index < NUM_AP; port_index++) { + if (port_info[port_index]) { + port_info[port_index]->teardown(port_index+1); + kfree(port_info[port_index]); + } + } +} +#else /* NUM_AP > 0 */ +static void init_accessory_ports(void) {} +static void teardown_accessory_ports(void) {} +#endif + static int mts_id_eeprom_load(void) { int i; @@ -809,19 +826,13 @@ static int mts_id_eeprom_load(void) static void cleanup(void) { - int port; - int port_index; - log_info("cleaning up...."); if (mts_io_platform_device) { platform_device_unregister(mts_io_platform_device); } - for (port_index = 0, port = 1; port_index < NUM_AP; port_index++, port++) { - if (port_info[port_index]) { - port_info[port_index]->teardown(port); - kfree(port_info[port_index]); - } - } + + teardown_accessory_ports(); + log_info("done cleaning up...."); } @@ -829,7 +840,6 @@ static int __init mts_io_init(void) { struct gpio_pin *pin; int ret; - int port_index; log_info("init: " DRIVER_VERSION); @@ -851,12 +861,7 @@ static int __init mts_io_init(void) return ret; } - if (NUM_AP) { - for (port_index = 0; port_index < NUM_AP; port_index++) { - port_info[port_index] = NULL; - } - init_accessory_ports(); - } + init_accessory_ports(); ret = sysfs_create_group(&mts_io_platform_device->dev.kobj, attr_group); if (ret) { -- cgit v1.2.3