[rtems commit] i2c: Avoid undefined right shift operation

Sebastian Huber sebh at rtems.org
Wed Nov 26 07:26:39 UTC 2014


Module:    rtems
Branch:    master
Commit:    d6f0ca64a5932ee38fb5891dbce886e0b10f63e7
Changeset: http://git.rtems.org/rtems/commit/?id=d6f0ca64a5932ee38fb5891dbce886e0b10f63e7

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Wed Nov 26 08:24:39 2014 +0100

i2c: Avoid undefined right shift operation

---

 cpukit/dev/i2c/eeprom.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/cpukit/dev/i2c/eeprom.c b/cpukit/dev/i2c/eeprom.c
index 9165141..39cff95 100644
--- a/cpukit/dev/i2c/eeprom.c
+++ b/cpukit/dev/i2c/eeprom.c
@@ -221,17 +221,20 @@ int i2c_dev_register_eeprom(
 
   if (address_bytes > EEPROM_MAX_ADDRESS_BYTES) {
     rtems_set_errno_and_return_minus_one(ERANGE);
+  } else if (address_bytes == EEPROM_MAX_ADDRESS_BYTES) {
+    extra_address = 0;
+  } else {
+    extra_address = size_in_bytes >> (8 * address_bytes);
   }
 
-  if (page_size_in_bytes > EEPROM_MAX_PAGE_SIZE) {
-    page_size_in_bytes = EEPROM_MAX_PAGE_SIZE;
-  }
-
-  extra_address = size_in_bytes >> (8 * address_bytes);
   if (extra_address != 0 && (extra_address & (extra_address - 1)) != 0) {
     rtems_set_errno_and_return_minus_one(EINVAL);
   }
 
+  if (page_size_in_bytes > EEPROM_MAX_PAGE_SIZE) {
+    page_size_in_bytes = EEPROM_MAX_PAGE_SIZE;
+  }
+
   if (program_timeout_in_ms == 0) {
     program_timeout_in_ms = 1000;
   }



More information about the vc mailing list