History

mscan: too much data copied to CAN frame due to 16 bit accesses

Due to the 16 bit access to mscan registers there's too much data copied to the zero initialized CAN frame when having an odd number of bytes to copy. This patch ensures that only the requested bytes are copied by using an 8 bit access for the remaining byte.

Wolfgang Grandegger committed 15 years ago

Commit a3a4bfd1 parent cdaf5571 file · +8 −3Browse files

Unified · Split

drivers/net/can/mscan/mscan.c+8−3
@@ -261,11 +261,13 @@ static netdev_tx_t mscan_start_xmit(struct sk_buff *skb, struct net_device *dev) · 260 unmodified lines
261261 void __iomem *data = &regs->tx.dsr1_0;
262262 u16 *payload = (u16 *)frame->data;
263263
264− /* It is safe to write into dsr[dlc+1] */
265− for (i = 0; i < (frame->can_dlc + 1) / 2; i++) {
264+ for (i = 0; i < frame->can_dlc / 2; i++) {
266265 out_be16(data, *payload++);
267266 data += 2 + _MSCAN_RESERVED_DSR_SIZE;
268267 }
268+ /* write remaining byte if necessary */
269+ if (frame->can_dlc & 1)
270+ out_8(data, frame->data[frame->can_dlc - 1]);
269271 }
270272
271273 out_8(&regs->tx.dlr, frame->can_dlc);
@@ -330,10 +332,13 @@ static void mscan_get_rx_frame(struct net_device *dev, struct can_frame *frame) · 58 unmodified lines
330332 void __iomem *data = &regs->rx.dsr1_0;
331333 u16 *payload = (u16 *)frame->data;
332334
333− for (i = 0; i < (frame->can_dlc + 1) / 2; i++) {
335+ for (i = 0; i < frame->can_dlc / 2; i++) {
334336 *payload++ = in_be16(data);
335337 data += 2 + _MSCAN_RESERVED_DSR_SIZE;
336338 }
339+ /* read remaining byte if necessary */
340+ if (frame->can_dlc & 1)
341+ frame->data[frame->can_dlc - 1] = in_8(data);
337342 }
338343
339344 out_8(&regs->canrflg, MSCAN_RXF);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t