From 25bd897ec5935b1179ff0cde10540403c3612b9f Mon Sep 17 00:00:00 2001 From: Thomas Ingleby Date: Tue, 20 Jan 2015 16:22:04 +0000 Subject: [PATCH] uart: use const char* instead of plain char* Signed-off-by: Thomas Ingleby --- api/mraa/common.h | 2 +- src/arm/raspberry_pi_b.c | 7 +------ src/uart/uart.c | 2 +- src/x86/intel_edison_fab_c.c | 9 ++------- src/x86/intel_galileo_rev_d.c | 14 ++------------ src/x86/intel_galileo_rev_g.c | 8 +------- 6 files changed, 8 insertions(+), 34 deletions(-) diff --git a/api/mraa/common.h b/api/mraa/common.h index 8456b8d..eb8f0a3 100644 --- a/api/mraa/common.h +++ b/api/mraa/common.h @@ -149,7 +149,7 @@ typedef struct { unsigned int index; /**< ID as exposed in the system */ int rx; /**< uart rx */ int tx; /**< uart tx */ - char* device_path; /**< To store "/dev/ttyS1" for example */ + const char* device_path; /**< To store "/dev/ttyS1" for example */ /*@}*/ } mraa_uart_dev_t; diff --git a/src/arm/raspberry_pi_b.c b/src/arm/raspberry_pi_b.c index 2bf2c7c..c23572d 100644 --- a/src/arm/raspberry_pi_b.c +++ b/src/arm/raspberry_pi_b.c @@ -180,12 +180,7 @@ mraa_raspberry_pi_b() b->def_uart_dev = 0; b->uart_dev[0].rx = 10; b->uart_dev[0].tx = 8; - int uart_path_length = strlen(UART_DEV_PATH) + 1; - b->uart_dev[0].device_path = (char*) malloc(sizeof(char) * uart_path_length); - if (b->uart_dev[0].device_path == NULL) { - goto error; - } - strncpy(b->uart_dev[0].device_path, UART_DEV_PATH, uart_path_length); + b->uart_dev[0].device_path = UART_DEV_PATH; return b; diff --git a/src/uart/uart.c b/src/uart/uart.c index d1b811e..4528c11 100644 --- a/src/uart/uart.c +++ b/src/uart/uart.c @@ -83,7 +83,7 @@ mraa_uart_init(int index) memset(dev, 0, sizeof(struct _uart)); dev->index = index; - dev->path = plat->uart_dev[index].device_path; + dev->path = (char*) plat->uart_dev[index].device_path; if (advance_func->uart_init_post != NULL) { mraa_result_t ret = advance_func->uart_init_post(dev); if (ret != MRAA_SUCCESS) { diff --git a/src/x86/intel_edison_fab_c.c b/src/x86/intel_edison_fab_c.c index d2c4cd4..8044248 100644 --- a/src/x86/intel_edison_fab_c.c +++ b/src/x86/intel_edison_fab_c.c @@ -1067,6 +1067,7 @@ mraa_intel_edison_miniboard(mraa_board_t* b) b->def_uart_dev = 0; b->uart_dev[0].rx = 26; b->uart_dev[0].tx = 35; + b->uart_dev[0].device_path = UART_DEV_PATH; return MRAA_SUCCESS; } @@ -1365,13 +1366,7 @@ mraa_intel_edison_fab_c() b->def_uart_dev = 0; b->uart_dev[0].rx = 0; b->uart_dev[0].tx = 1; - - int uart_path_length = strlen(UART_DEV_PATH) + 1; - b->uart_dev[0].device_path = (char*) malloc(sizeof(char) * uart_path_length); - if (b->uart_dev[0].device_path == NULL) { - goto error; - } - strncpy(b->uart_dev[0].device_path, UART_DEV_PATH, uart_path_length); + b->uart_dev[0].device_path = UART_DEV_PATH; int il; for (il =0; il < MRAA_INTEL_EDISON_PINCOUNT; il++) { diff --git a/src/x86/intel_galileo_rev_d.c b/src/x86/intel_galileo_rev_d.c index dbfb461..08ddbf7 100644 --- a/src/x86/intel_galileo_rev_d.c +++ b/src/x86/intel_galileo_rev_d.c @@ -405,25 +405,15 @@ mraa_intel_galileo_rev_d() b->spi_bus[0].miso = 12; b->spi_bus[0].sclk = 13; - int uart_path_length = strlen("/dev/ttyS0") + 1; - b->uart_dev_count = 2; b->def_uart_dev = 0; b->uart_dev[0].rx = 0; b->uart_dev[0].tx = 1; - b->uart_dev[0].device_path = (char*) malloc(sizeof(char) * uart_path_length); - if (b->uart_dev[0].device_path == NULL) { - goto error; - } - strncpy(b->uart_dev[0].device_path, "/dev/ttyS0", uart_path_length); + b->uart_dev[0].device_path = "/dev/ttyS0"; b->uart_dev[1].rx = -1; b->uart_dev[1].tx = -1; - b->uart_dev[1].device_path = (char*) malloc(sizeof(char) * uart_path_length); - if (b->uart_dev[1].device_path == NULL) { - goto error; - } - strncpy(b->uart_dev[1].device_path, "/dev/ttyS1", uart_path_length); + b->uart_dev[1].device_path = "/dev/ttyS1"; return b; error: diff --git a/src/x86/intel_galileo_rev_g.c b/src/x86/intel_galileo_rev_g.c index cd83041..414b6c5 100644 --- a/src/x86/intel_galileo_rev_g.c +++ b/src/x86/intel_galileo_rev_g.c @@ -746,17 +746,11 @@ mraa_intel_galileo_gen2() b->spi_bus[0].miso = 12; b->spi_bus[0].sclk = 13; - int uart_path_length = strlen("/dev/ttyS0") + 1; - b->uart_dev_count = 1; b->def_uart_dev = 0; b->uart_dev[0].rx = 0; b->uart_dev[0].tx = 1; - b->uart_dev[0].device_path = (char*) malloc(sizeof(char) * uart_path_length); - if (b->uart_dev[0].device_path == NULL) { - goto error; - } - strncpy(b->uart_dev[0].device_path, "/dev/ttyS0", uart_path_length); + b->uart_dev[0].device_path = "/dev/ttyS0"; return b; error: