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>
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) {
{
FAR struct s5j_spidev_s *priv = NULL;
- if (port >= SPI_PORT_MAX) {
+ if (port < 0 || port >= SPI_PORT_MAX) {
return NULL;
}