From e5a893bfb836f5d8a8cea7a2d9434aa703ee04db Mon Sep 17 00:00:00 2001 From: Thomas Ingleby Date: Wed, 21 May 2014 13:57:30 +0100 Subject: [PATCH] i2c: internal setup function properly works Signed-off-by: Thomas Ingleby --- include/maa_internal.h | 2 +- src/maa.c | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/include/maa_internal.h b/include/maa_internal.h index a3944ca..428132d 100644 --- a/include/maa_internal.h +++ b/include/maa_internal.h @@ -46,7 +46,7 @@ unsigned int maa_setup_aio(int pin); * * @return unsigned int if using /dev/i2c-2 returned would be 2 */ -unsigned int maa_setup_i2c(); +unsigned int maa_setup_i2c(int bus); /** Setup spi interface, sets up multiplexer on device. * diff --git a/src/maa.c b/src/maa.c index 215687c..0170564 100644 --- a/src/maa.c +++ b/src/maa.c @@ -121,7 +121,7 @@ maa_setup_aio(int aio) } unsigned int -maa_setup_i2c(int bus_s) +maa_setup_i2c(int bus) { if (plat == NULL) return -3; @@ -130,7 +130,10 @@ maa_setup_i2c(int bus_s) fprintf(stderr, "No i2c buses defined in platform"); return -1; } - int bus = 0; + if (bus >= plat->i2c_bus_count) { + fprintf(stderr, "Above i2c bus count"); + return -1; + } int pos = plat->i2c_bus[bus].sda; if (plat->pins[pos].i2c.mux_total > 0) -- 2.7.4