From: Wonsang Ryou Date: Wed, 2 Aug 2017 08:18:52 +0000 (+0900) Subject: s5j: add exception handling codes in spi and i2c drivers X-Git-Tag: 1.1_Public_Release~318^2~29 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a6475f34624acccddd7abcd13ac69e7110bc0db7;p=rtos%2Ftinyara.git s5j: add exception handling codes in spi and i2c drivers 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 --- diff --git a/os/arch/arm/src/s5j/s5j_i2c.c b/os/arch/arm/src/s5j/s5j_i2c.c index ba0e633..18797b3 100644 --- a/os/arch/arm/src/s5j/s5j_i2c.c +++ b/os/arch/arm/src/s5j/s5j_i2c.c @@ -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) { diff --git a/os/arch/arm/src/s5j/s5j_spi.c b/os/arch/arm/src/s5j/s5j_spi.c index d18873a..18112e2 100644 --- a/os/arch/arm/src/s5j/s5j_spi.c +++ b/os/arch/arm/src/s5j/s5j_spi.c @@ -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; }