api: added parameter check statement. 66/151566/4
authorSegwon <segwon.han@samsung.com>
Thu, 21 Sep 2017 07:37:46 +0000 (16:37 +0900)
committerKibak Yoon <kibak.yoon@samsung.com>
Tue, 26 Sep 2017 01:55:00 +0000 (01:55 +0000)
Signed-off-by: Segwon <segwon.han@samsung.com>
Change-Id: I610bba87b751637c1443e7cd6b1ba83a25b8f246

src/peripheral_gpio.c
src/peripheral_i2c.c
src/peripheral_pwm.c
src/peripheral_spi.c
src/peripheral_uart.c

index f7b68eec5636f33f7a21069a244645a1f77445ad..afb09f3c3dfbd6a1142caf4b2e8ea5289967b81e 100644 (file)
@@ -114,6 +114,7 @@ int peripheral_gpio_open(int gpio_pin, peripheral_gpio_h *gpio)
        int ret = PERIPHERAL_ERROR_NONE;
        peripheral_gpio_h handle;
 
+       RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid gpio handle");
        RETVM_IF(gpio_pin < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid gpio pin number");
 
        /* Initialize */
@@ -170,6 +171,7 @@ int peripheral_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direct
        int ret = PERIPHERAL_ERROR_NONE;
 
        RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL");
+       RETVM_IF((direction < PERIPHERAL_GPIO_DIRECTION_IN) || (direction > PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid direction input");
 
        /* call gpio_set_direction */
        ret = peripheral_gdbus_gpio_set_direction(gpio, direction);
@@ -188,8 +190,7 @@ int peripheral_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e
        int ret = PERIPHERAL_ERROR_NONE;
 
        RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL");
-       RETVM_IF(edge > PERIPHERAL_GPIO_EDGE_BOTH, PERIPHERAL_ERROR_INVALID_PARAMETER,
-               "Invalid edge input");
+       RETVM_IF((edge < PERIPHERAL_GPIO_EDGE_NONE) || (edge > PERIPHERAL_GPIO_EDGE_BOTH), PERIPHERAL_ERROR_INVALID_PARAMETER, "edge input is invalid");
 
        /* call gpio_set_edge_mode */
        ret = peripheral_gdbus_gpio_set_edge_mode(gpio, edge);
@@ -207,6 +208,7 @@ int peripheral_gpio_set_interrupted_cb(peripheral_gpio_h gpio, peripheral_gpio_i
        int ret = PERIPHERAL_ERROR_NONE;
 
        RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL");
+       RETVM_IF(callback == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio interrupted callback is NULL");
 
        ret = peripheral_gdbus_gpio_set_interrupted_cb(gpio, callback, user_data);
        if (ret != PERIPHERAL_ERROR_NONE) {
@@ -252,6 +254,7 @@ int peripheral_gpio_read(peripheral_gpio_h gpio, uint32_t *value)
        int ret = PERIPHERAL_ERROR_NONE;
 
        RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL");
+       RETVM_IF(value == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio read value is invalid");
 
        /* call gpio_read */
        ret = peripheral_gdbus_gpio_read(gpio, (int *)value);
@@ -269,6 +272,7 @@ int peripheral_gpio_write(peripheral_gpio_h gpio, uint32_t value)
        int ret = PERIPHERAL_ERROR_NONE;
 
        RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL");
+       RETVM_IF((value != 0) && (value != 1), PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio value is invalid");
 
        /* call gpio_write */
        ret = peripheral_gdbus_gpio_write(gpio, (int)value);
index f52b9b4899520648ea2ceb9089e0f04572fe36aa..63934940d39a58ca3e1b04e282037a7f35bf5fab 100644 (file)
@@ -39,6 +39,7 @@ int peripheral_i2c_open(int bus, int address, peripheral_i2c_h *i2c)
        peripheral_i2c_h handle;
        int ret = PERIPHERAL_ERROR_NONE;
 
+       RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid i2c handle");
        RETVM_IF(bus < 0 || address < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
 
        handle = (peripheral_i2c_h)malloc(sizeof(struct _peripheral_i2c_s));
@@ -84,7 +85,7 @@ int peripheral_i2c_read(peripheral_i2c_h i2c, uint8_t *data, uint32_t length)
        int ret;
 
        RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL");
-       RETVM_IF(data == NULL || length < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
 
        ret = peripheral_gdbus_i2c_read(i2c, data, (int)length);
        if (ret != PERIPHERAL_ERROR_NONE)
@@ -98,7 +99,7 @@ int peripheral_i2c_write(peripheral_i2c_h i2c, uint8_t *data, uint32_t length)
        int ret;
 
        RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL");
-       RETVM_IF(data == NULL || length < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
 
        ret = peripheral_gdbus_i2c_write(i2c, data, (int)length);
        if (ret != PERIPHERAL_ERROR_NONE)
@@ -113,6 +114,7 @@ int peripheral_i2c_read_register_byte(peripheral_i2c_h i2c, uint8_t reg, uint8_t
        uint16_t w_data, dummy = 0;
 
        RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL");
+       RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
 
        ret = peripheral_gdbus_i2c_smbus_ioctl(i2c, I2C_SMBUS_READ, reg, I2C_SMBUS_BYTE_DATA, dummy, &w_data);
        if (ret != PERIPHERAL_ERROR_NONE)
@@ -143,6 +145,7 @@ int peripheral_i2c_read_register_word(peripheral_i2c_h i2c, uint8_t reg, uint16_
        uint16_t dummy = 0, data_out;
 
        RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL");
+       RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
 
        ret = peripheral_gdbus_i2c_smbus_ioctl(i2c, I2C_SMBUS_READ, reg, I2C_SMBUS_WORD_DATA, dummy, &data_out);
        if (ret != PERIPHERAL_ERROR_NONE)
index be18d45d3d759b22a7223480743d43e20a77d41c..3ea42e00a756e54d67647d53d773a42fd7d6fa33 100644 (file)
@@ -29,6 +29,7 @@ int peripheral_pwm_open(int chip, int pin, peripheral_pwm_h *pwm)
        peripheral_pwm_h handle;
        int ret = PERIPHERAL_ERROR_NONE;
 
+       RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid pwm handle");
        RETVM_IF(chip < 0 || pin < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
 
        /* Initialize */
@@ -99,6 +100,7 @@ int peripheral_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e
        int ret;
 
        RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL");
+       RETVM_IF((polarity < PERIPHERAL_PWM_POLARITY_ACTIVE_HIGH) || (polarity > PERIPHERAL_PWM_POLARITY_ACTIVE_LOW), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid polarity parameter");
 
        ret = peripheral_gdbus_pwm_set_polarity(pwm, polarity);
        if (ret != PERIPHERAL_ERROR_NONE)
index 7b2baf793cc2b566f7233fd1476c84fc92eed1e7..07fefdf7c896039fd7edd1537d4e2bcd48e658c8 100644 (file)
@@ -30,6 +30,7 @@ int peripheral_spi_open(int bus, int cs, peripheral_spi_h *spi)
        peripheral_spi_h handle;
        int ret = PERIPHERAL_ERROR_NONE;
 
+       RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid spi handle");
        RETVM_IF(bus < 0 || cs < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
 
        /* Initialize */
@@ -75,8 +76,7 @@ int peripheral_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode)
        int ret;
 
        RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL");
-       RETVM_IF(mode > PERIPHERAL_SPI_MODE_3, PERIPHERAL_ERROR_INVALID_PARAMETER,
-               "Invalid spi mode parameter");
+       RETVM_IF((mode < PERIPHERAL_SPI_MODE_0) || (mode > PERIPHERAL_SPI_MODE_3), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid spi mode parameter");
 
        ret = peripheral_gdbus_spi_set_mode(spi, mode);
        if (ret != PERIPHERAL_ERROR_NONE)
@@ -90,6 +90,7 @@ int peripheral_spi_set_bit_order(peripheral_spi_h spi, peripheral_spi_bit_order_
        int ret;
 
        RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL");
+       RETVM_IF((bit_order < PERIPHERAL_SPI_BIT_ORDER_MSB) || (bit_order > PERIPHERAL_SPI_BIT_ORDER_LSB), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid bit order parameter");
 
        bool lsb = (bit_order == PERIPHERAL_SPI_BIT_ORDER_LSB) ? true : false;
        ret = peripheral_gdbus_spi_set_bit_order(spi, lsb);
@@ -130,6 +131,7 @@ int peripheral_spi_read(peripheral_spi_h spi, uint8_t *data, uint32_t length)
        int ret;
 
        RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL");
+       RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
 
        ret = peripheral_gdbus_spi_read(spi, data, (int)length);
        if (ret != PERIPHERAL_ERROR_NONE)
@@ -143,6 +145,7 @@ int peripheral_spi_write(peripheral_spi_h spi, uint8_t *data, uint32_t length)
        int ret;
 
        RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL");
+       RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
 
        ret = peripheral_gdbus_spi_write(spi, data, (int)length);
        if (ret != PERIPHERAL_ERROR_NONE)
@@ -156,6 +159,7 @@ int peripheral_spi_transfer(peripheral_spi_h spi, uint8_t *txdata, uint8_t *rxda
        int ret;
 
        RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL");
+       RETVM_IF(txdata == NULL || rxdata == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
 
        ret = peripheral_gdbus_spi_transfer(spi, txdata, rxdata, (int)length);
        if (ret != PERIPHERAL_ERROR_NONE)
index cb62b52619ed541caaa714c62092cea8eb0722cf..f90d4333e912f4b9c2b4bc75ff459da907ad3a9b 100644 (file)
@@ -32,6 +32,7 @@ int peripheral_uart_open(int port, peripheral_uart_h *uart)
        peripheral_uart_h handle;
        int ret;
 
+       RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid uart handle");
        RETVM_IF(port < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid port number");
 
        handle = (peripheral_uart_h)calloc(1, sizeof(struct _peripheral_uart_s));
@@ -83,8 +84,7 @@ int peripheral_uart_set_baud_rate(peripheral_uart_h uart, peripheral_uart_baud_r
        int ret;
 
        RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL");
-       RETVM_IF(baud > PERIPHERAL_UART_BAUD_RATE_230400, PERIPHERAL_ERROR_INVALID_PARAMETER,
-               "Invalid baud input");
+       RETVM_IF((baud < PERIPHERAL_UART_BAUD_RATE_0) || (baud > PERIPHERAL_UART_BAUD_RATE_230400), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid baud input");
 
        ret = peripheral_gdbus_uart_set_baud_rate(uart, baud);
        if (ret != PERIPHERAL_ERROR_NONE)
@@ -144,6 +144,8 @@ int peripheral_uart_set_flow_control(peripheral_uart_h uart, peripheral_uart_sof
        int ret;
 
        RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL");
+       RETVM_IF((sw_flow_control < PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_NONE) || (sw_flow_control > PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_XONXOFF), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid sw_flow_control parameter");
+       RETVM_IF((hw_flow_control < PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_NONE) || (hw_flow_control > PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_AUTO_RTSCTS), PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid hw_flow_control parameter");
 
        bool xonxoff = (sw_flow_control == PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_XONXOFF) ? true : false;
        bool rtscts = (hw_flow_control == PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_AUTO_RTSCTS) ? true : false;
@@ -163,7 +165,7 @@ int peripheral_uart_read(peripheral_uart_h uart, uint8_t *data, uint32_t length)
        int ret;
 
        RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL");
-       RETVM_IF(data == NULL || length < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
 
        ret = peripheral_gdbus_uart_read(uart, data, (int)length);
        if (ret < PERIPHERAL_ERROR_NONE)
@@ -180,7 +182,7 @@ int peripheral_uart_write(peripheral_uart_h uart, uint8_t *data, uint32_t length
        int ret;
 
        RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL");
-       RETVM_IF(data == NULL || length < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       RETVM_IF(data == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid parameter");
 
        ret = peripheral_gdbus_uart_write(uart, data, (int)length);
        if (ret < PERIPHERAL_ERROR_NONE)