From 83dc6a9b79c0b886af338d5cc8a8c57d55deb8eb Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 5 Feb 2016 10:49:27 -0600 Subject: [PATCH] I2C tool: Verify that the I2C bus driver exists when process the -b option --- system/i2c/i2c_common.c | 37 +++++++++---------------------------- 1 file changed, 9 insertions(+), 28 deletions(-) diff --git a/system/i2c/i2c_common.c b/system/i2c/i2c_common.c index 514e50d72..a3b3fce23 100644 --- a/system/i2c/i2c_common.c +++ b/system/i2c/i2c_common.c @@ -43,30 +43,6 @@ #include "i2ctool.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -95,7 +71,7 @@ int common_args(FAR struct i2ctool_s *i2ctool, FAR char **arg) goto out_of_range; } - i2ctool->addr = (uint8_t) value; + i2ctool->addr = (uint8_t)value; return ret; case 'b': @@ -105,7 +81,12 @@ int common_args(FAR struct i2ctool_s *i2ctool, FAR char **arg) goto out_of_range; } - i2ctool->bus = (uint8_t) value; + if (!i2cdev_exists((int)value)) + { + goto invalid_argument; + } + + i2ctool->bus = (uint8_t)value; return ret; case 'f': @@ -137,7 +118,7 @@ int common_args(FAR struct i2ctool_s *i2ctool, FAR char **arg) goto out_of_range; } - i2ctool->regaddr = (uint8_t) value; + i2ctool->regaddr = (uint8_t)value; return ret; case 's': @@ -151,7 +132,7 @@ int common_args(FAR struct i2ctool_s *i2ctool, FAR char **arg) goto out_of_range; } - i2ctool->width = (uint8_t) value; + i2ctool->width = (uint8_t)value; return ret; default: