From: Segwon Date: Wed, 15 Nov 2017 07:40:18 +0000 (+0900) Subject: interface: do not check if fd is negative X-Git-Tag: submit/tizen_4.0/20171220.125806^2~21 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d934f33cca753b515853713c844369ca5e8e6e22;p=platform%2Fcore%2Fapi%2Fperipheral-io.git interface: do not check if fd is negative - it is checked by the caller. - the check is meaningless even if handle is not opened. Change-Id: Id22083b04f4e95a0788a32f1cbc2929c08dd8c31 Signed-off-by: Segwon --- diff --git a/src/interface/peripheral_interface_i2c.c b/src/interface/peripheral_interface_i2c.c index 87be206..d0a9985 100644 --- a/src/interface/peripheral_interface_i2c.c +++ b/src/interface/peripheral_interface_i2c.c @@ -22,12 +22,7 @@ int peripheral_interface_i2c_close(peripheral_i2c_h i2c) { - int status; - - _D("fd : %d", i2c->fd); - RETVM_IF(i2c->fd < 0, -EINVAL, "Invalid fd"); - - status = close(i2c->fd); + int status = close(i2c->fd); CHECK_ERROR(status); return 0; @@ -35,11 +30,7 @@ int peripheral_interface_i2c_close(peripheral_i2c_h i2c) int peripheral_interface_i2c_read(peripheral_i2c_h i2c, uint8_t *data, uint32_t length) { - int status; - - RETVM_IF(i2c->fd < 0, -EINVAL, "Invalid fd : %d", i2c->fd); - - status = read(i2c->fd, data, length); + int status = read(i2c->fd, data, length); CHECK_ERROR(status); return 0; @@ -47,11 +38,7 @@ int peripheral_interface_i2c_read(peripheral_i2c_h i2c, uint8_t *data, uint32_t int peripheral_interface_i2c_write(peripheral_i2c_h i2c, uint8_t *data, uint32_t length) { - int status; - - RETVM_IF(i2c->fd < 0, -EINVAL, "Invalid fd : %d", i2c->fd); - - status = write(i2c->fd, data, length); + int status = write(i2c->fd, data, length); CHECK_ERROR(status); return 0; @@ -59,11 +46,7 @@ int peripheral_interface_i2c_write(peripheral_i2c_h i2c, uint8_t *data, uint32_t int peripheral_interface_i2c_smbus_ioctl(peripheral_i2c_h i2c, struct i2c_smbus_ioctl_data *data) { - int status; - - RETVM_IF(i2c->fd < 0, -EINVAL, "Invalid fd : %d", i2c->fd); - - status = ioctl(i2c->fd, I2C_SMBUS, data); + int status = ioctl(i2c->fd, I2C_SMBUS, data); CHECK_ERROR(status); return 0; diff --git a/src/interface/peripheral_interface_spi.c b/src/interface/peripheral_interface_spi.c index e8a0fc6..bf68c50 100644 --- a/src/interface/peripheral_interface_spi.c +++ b/src/interface/peripheral_interface_spi.c @@ -26,12 +26,7 @@ int peripheral_interface_spi_close(peripheral_spi_h spi) { - int status; - - _D("fd : %d", spi->fd); - RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd"); - - status = close(spi->fd); + int status = close(spi->fd); CHECK_ERROR(status); return 0; @@ -39,12 +34,7 @@ int peripheral_interface_spi_close(peripheral_spi_h spi) int peripheral_interface_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode) { - int status; - - _D("fd : %d, mode : %d", spi->fd, mode); - RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd"); - - status = ioctl(spi->fd, SPI_IOC_WR_MODE, &mode); + int status = ioctl(spi->fd, SPI_IOC_WR_MODE, &mode); CHECK_ERROR(status); return 0; @@ -52,12 +42,7 @@ int peripheral_interface_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_ int peripheral_interface_spi_set_bit_order(peripheral_spi_h spi, peripheral_spi_bit_order_e bit_order) { - int status; - - _D("fd : %d, lsb : %d", spi->fd, bit_order); - RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd"); - - status = ioctl(spi->fd, SPI_IOC_WR_LSB_FIRST, &bit_order); + int status = ioctl(spi->fd, SPI_IOC_WR_LSB_FIRST, &bit_order); CHECK_ERROR(status); return 0; @@ -65,12 +50,7 @@ int peripheral_interface_spi_set_bit_order(peripheral_spi_h spi, peripheral_spi_ int peripheral_interface_spi_set_bits_per_word(peripheral_spi_h spi, uint8_t bits) { - int status; - - _D("fd : %d, bits : %d", spi->fd, bits); - RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd"); - - status = ioctl(spi->fd, SPI_IOC_WR_BITS_PER_WORD, &bits); + int status = ioctl(spi->fd, SPI_IOC_WR_BITS_PER_WORD, &bits); CHECK_ERROR(status); return 0; @@ -78,12 +58,7 @@ int peripheral_interface_spi_set_bits_per_word(peripheral_spi_h spi, uint8_t bit int peripheral_interface_spi_set_frequency(peripheral_spi_h spi, uint32_t freq) { - int status; - - _D("fd : %d, freq : %d", spi->fd, freq); - RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd"); - - status = ioctl(spi->fd, SPI_IOC_WR_MAX_SPEED_HZ, &freq); + int status = ioctl(spi->fd, SPI_IOC_WR_MAX_SPEED_HZ, &freq); CHECK_ERROR(status); return 0; @@ -94,8 +69,6 @@ int peripheral_interface_spi_read(peripheral_spi_h spi, uint8_t *rxbuf, uint32_t int status; struct spi_ioc_transfer xfer; - RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd : %d", spi->fd); - memset(&xfer, 0, sizeof(struct spi_ioc_transfer)); xfer.rx_buf = (unsigned long)rxbuf; xfer.len = length; @@ -111,8 +84,6 @@ int peripheral_interface_spi_write(peripheral_spi_h spi, uint8_t *txbuf, uint32_ int status; struct spi_ioc_transfer xfer; - RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd : %d", spi->fd); - memset(&xfer, 0, sizeof(struct spi_ioc_transfer)); xfer.tx_buf = (unsigned long)txbuf; xfer.len = length; @@ -128,8 +99,6 @@ int peripheral_interface_spi_transfer(peripheral_spi_h spi, uint8_t *txbuf, uint int status; struct spi_ioc_transfer xfer; - RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd : %d", spi->fd); - if (!txbuf || !rxbuf) return -EINVAL; memset(&xfer, 0, sizeof(xfer)); diff --git a/src/interface/peripheral_interface_uart.c b/src/interface/peripheral_interface_uart.c index 4944bb9..36131a1 100644 --- a/src/interface/peripheral_interface_uart.c +++ b/src/interface/peripheral_interface_uart.c @@ -47,13 +47,6 @@ int peripheral_interface_uart_close(peripheral_uart_h uart) { int status; - _D("file_hndl : %d", uart->fd); - - if (uart->fd < 0) { - _E("Invalid NULL parameter"); - return -EINVAL; - } - status = peripheral_interface_uart_flush(uart); CHECK_ERROR(status); @@ -65,14 +58,7 @@ int peripheral_interface_uart_close(peripheral_uart_h uart) int peripheral_interface_uart_flush(peripheral_uart_h uart) { - int ret; - - if (!uart->fd) { - _E("Invalid NULL parameter"); - return -EINVAL; - } - - ret = tcflush(uart->fd, TCIOFLUSH); + int ret = tcflush(uart->fd, TCIOFLUSH); CHECK_ERROR(ret); return 0; @@ -83,19 +69,6 @@ int peripheral_interface_uart_set_baud_rate(peripheral_uart_h uart, peripheral_u int ret; struct termios tio; - _D("file_hndl : %d, baud : %d", uart->fd, baud); - - memset(&tio, 0, sizeof(tio)); - if (!uart->fd) { - _E("Invalid NULL parameter"); - return -EINVAL; - } - - if (baud > PERIPHERAL_UART_BAUD_RATE_230400) { - _E("Invalid parameter"); - return -EINVAL; - } - ret = tcgetattr(uart->fd, &tio); CHECK_ERROR(ret); @@ -118,22 +91,9 @@ int peripheral_interface_uart_set_byte_size(peripheral_uart_h uart, peripheral_u int ret; struct termios tio; - _D("file_hndl : %d, bytesize : %d", uart->fd, byte_size); - - if (!uart->fd) { - _E("Invalid NULL parameter"); - return -EINVAL; - } - - if (byte_size > PERIPHERAL_UART_BYTE_SIZE_8BIT) { - _E("Invalid bytesize parameter"); - return -EINVAL; - } - ret = tcgetattr(uart->fd, &tio); CHECK_ERROR(ret); - /* set byte size */ tio.c_cflag &= ~CSIZE; tio.c_cflag |= byteinfo[byte_size]; @@ -151,13 +111,6 @@ int peripheral_interface_uart_set_parity(peripheral_uart_h uart, peripheral_uart int ret; struct termios tio; - _D("file_hndl : %d, parity : %d", uart->fd, parity); - - if (!uart->fd) { - _E("Invalid NULL parameter"); - return -EINVAL; - } - ret = tcgetattr(uart->fd, &tio); CHECK_ERROR(ret); @@ -190,13 +143,6 @@ int peripheral_interface_uart_set_stop_bits(peripheral_uart_h uart, peripheral_u int ret; struct termios tio; - _D("file_hndl : %d, stopbits : %d", uart->fd, stop_bits); - - if (!uart->fd) { - _E("Invalid NULL parameter"); - return -EINVAL; - } - ret = tcgetattr(uart->fd, &tio); CHECK_ERROR(ret); @@ -225,13 +171,6 @@ int peripheral_interface_uart_set_flow_control(peripheral_uart_h uart, periphera int ret; struct termios tio; - _D("file_hndl : %d, xonxoff : %d, rtscts : %d", uart->fd, xonxoff, rtscts); - - if (!uart->fd) { - _E("Invalid NULL parameter"); - return -EINVAL; - } - ret = tcgetattr(uart->fd, &tio); CHECK_ERROR(ret); @@ -257,14 +196,7 @@ int peripheral_interface_uart_set_flow_control(peripheral_uart_h uart, periphera int peripheral_interface_uart_read(peripheral_uart_h uart, uint8_t *buf, uint32_t length) { - int ret; - - if (!uart->fd) { - _E("Invalid NULL parameter"); - return -EINVAL; - } - - ret = read(uart->fd, (void *)buf, length); + int ret = read(uart->fd, (void *)buf, length); CHECK_ERROR(ret); return ret; @@ -272,14 +204,7 @@ int peripheral_interface_uart_read(peripheral_uart_h uart, uint8_t *buf, uint32_ int peripheral_interface_uart_write(peripheral_uart_h uart, uint8_t *buf, uint32_t length) { - int ret; - - if (!uart->fd) { - _E("Invalid NULL parameter"); - return -EINVAL; - } - - ret = write(uart->fd, buf, length); + int ret = write(uart->fd, buf, length); CHECK_ERROR(ret); return ret;