s5j: add exception handling codes in spi and i2c drivers
authorWonsang Ryou <wonsang.yoo@samsung.com>
Wed, 2 Aug 2017 08:18:52 +0000 (17:18 +0900)
committerEunBong Song <eunb.song@samsung.com>
Wed, 30 Aug 2017 04:15:48 +0000 (21:15 -0700)
This patch adds the codes in order to check if the port number is valid
in spi and i2c drivers. If the port is invalid, the exception handling
code returns NULL.

Change-Id: I9c5360ce58cd0c3778e048377ea92472ac31e21b
Signed-off-by: Wonsang Ryou <wonsang.yoo@samsung.com>
os/arch/arm/src/s5j/s5j_i2c.c
os/arch/arm/src/s5j/s5j_spi.c

index ba0e633..18797b3 100644 (file)
@@ -1261,6 +1261,12 @@ struct i2c_dev_s *up_i2cinitialize(int port)
        struct s5j_i2c_priv_s *priv = NULL;
        const struct s5j_i2c_config_s *config;
        int flags;
+       int total_ports = sizeof(g_s5j_i2c_priv) / sizeof(g_s5j_i2c_priv[0]);
+
+       /* check if port is valid */
+       if (port < 0 || port >= total_ports) {
+               return NULL;
+       }
 
        /* Get I2C private structure */
        if (g_s5j_i2c_priv[port] != NULL) {
index d18873a..18112e2 100644 (file)
@@ -521,7 +521,7 @@ struct spi_dev_s *up_spiinitialize(int port)
 {
        FAR struct s5j_spidev_s *priv = NULL;
 
-       if (port >= SPI_PORT_MAX) {
+       if (port < 0 || port >= SPI_PORT_MAX) {
                return NULL;
        }