]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
stm25p: fix seek error master
authorR. Steve McKown <rsmckown@gmail.com>
Fri, 2 Jan 2015 21:06:50 +0000 (14:06 -0700)
committerR. Steve McKown <rsmckown@gmail.com>
Fri, 2 Jan 2015 21:22:43 +0000 (14:22 -0700)
Ensure correct computation of m_log_info[ id ].read_addr when client code
requests seek() to a cookie whose value is below the current virtual
address range by a distance, in address value, greater than 255 sectors.

The sector component of a virtual address is 16 bits, given
STM25P_SECTOR_SIZE_LOG2 is 16 and sizeof(storage_cookie_t) is 32.
However, in ClientResource.granted[]() in the S_SEEK case, the client's
read_addr value can have its upper bits silently discarded because
sector value are handled in uint8_t variables.

The symptom of upper bit discards is that client code receives the
contents of a full log many times until the client read_addr value
finally increments to the point that allows satisfaction of the end of
log condition,

    read_addr >= m_log_info[ client ].write_addr

Example case exhibiting this behavior:

read_addr = 0x59f0000
write_addr = 5a6dbf8
LogRead.seek(0x2a71400)

The resulting address handling in ClientResource.granted[]() in the
S_SEEK request case, around Stm25pLogP.nc:229:

readSector = 0xa7; // from incoming cookie value, should be 0x2a7
writeSector = 0xa7; // should be 0x5a7
if (writeSector - readSector > numSectors): FALSE, should be TRUE
  Had the if expression above been TRUE, the read address would
  still be computed incorrectly due to 8-bit match in the if's
  'then' clause.
m_log_state[ id  ].read_addr = 0x2a7000; // should be 0x59f000

tos/chips/stm25p/Stm25pLogP.nc

index e454de79d88c27d03d5b8dafb4aca2e937632343..b63cf3f71f5baa507b20b7d2de2b3460337d1b89 100644 (file)
@@ -230,9 +230,9 @@ implementation {
        {
          // make sure the cookie is still within the range of valid data
          uint8_t numSectors = call Sector.getNumSectors[ id ]();
-         uint8_t readSector = 
+         uint16_t readSector =
            (m_log_state[ id ].cookie >> STM25P_SECTOR_SIZE_LOG2);
-         uint8_t writeSector =
+         uint16_t writeSector =
            ((m_log_info[ id ].write_addr-1)>>STM25P_SECTOR_SIZE_LOG2)+1;
          // if cookie is overwritten, advance to beginning of log
          if ( (writeSector - readSector) > numSectors ) {