From a6475f34624acccddd7abcd13ac69e7110bc0db7 Mon Sep 17 00:00:00 2001 From: Wonsang Ryou Date: Wed, 2 Aug 2017 17:18:52 +0900 Subject: [PATCH] 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 --- os/arch/arm/src/s5j/s5j_i2c.c | 6 ++++++ os/arch/arm/src/s5j/s5j_spi.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) 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; } -- 2.7.4