cc2520: packetbuf attributes were set using wrong pointer

The buf pointer in cc2520_read() points to memory that will
hold the received data. It must not be used to set RSSI and
link quality values. Very difficult to find memory corruption
was seen as we were overwriting memory in other part of the
system. The fix was to set the RSSI and link quality variables
in read_packet() where the buf pointer points to proper memory.

Change-Id: I49bfe37f4c7ccc0f582f3aecdf73d5b3ea6bb4e5
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
Jukka Rissanen 2016-02-10 12:02:50 +02:00 committed by Anas Nashif
commit 971af2b249

View file

@ -866,11 +866,6 @@ static int cc2520_read(void *buf, unsigned short bufsize)
if (footer[1] & FOOTER1_CRC_OK) {
cc2520_last_rssi = footer[0];
cc2520_last_correlation = footer[1] & FOOTER1_CORRELATION;
packetbuf_set_attr(buf, PACKETBUF_ATTR_RSSI, cc2520_last_rssi);
packetbuf_set_attr(buf, PACKETBUF_ATTR_LINK_QUALITY,
cc2520_last_correlation);
} else {
goto error;
}
@ -916,6 +911,9 @@ static void read_packet(void)
goto out;
}
packetbuf_set_attr(buf, PACKETBUF_ATTR_RSSI, cc2520_last_rssi);
packetbuf_set_attr(buf, PACKETBUF_ATTR_LINK_QUALITY,
cc2520_last_correlation);
packetbuf_set_datalen(buf, len);
DBG("%s: received %d bytes\n", __func__, len);