Skip to content

Commit

Permalink
can: janz-ican3: cleanup of ican3_to_can_frame and can_frame_to_ican3
Browse files Browse the repository at this point in the history
This patch cleans up the ICAN3 to Linux CAN frame and vice versa
conversion functions:

- RX: Use get_can_dlc() to limit the dlc value.
- RX+TX: Don't copy the whole frame, only copy the amount of bytes
  specified in cf->can_dlc.

Acked-by: Ira W. Snyder <iws@ovro.caltech.edu>
Tested-by: Ira W. Snyder <iws@ovro.caltech.edu>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
  • Loading branch information
Marc Kleine-Budde committed Jul 20, 2012
1 parent 007890d commit 9e4d690
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions drivers/net/can/janz-ican3.c
Original file line number Diff line number Diff line change
Expand Up @@ -811,10 +811,10 @@ static void ican3_to_can_frame(struct ican3_dev *mod,

cf->can_id |= desc->data[0] << 3;
cf->can_id |= (desc->data[1] & 0xe0) >> 5;
cf->can_dlc = desc->data[1] & ICAN3_CAN_DLC_MASK;
memcpy(cf->data, &desc->data[2], sizeof(cf->data));
cf->can_dlc = get_can_dlc(desc->data[1] & ICAN3_CAN_DLC_MASK);
memcpy(cf->data, &desc->data[2], cf->can_dlc);
} else {
cf->can_dlc = desc->data[0] & ICAN3_CAN_DLC_MASK;
cf->can_dlc = get_can_dlc(desc->data[0] & ICAN3_CAN_DLC_MASK);
if (desc->data[0] & ICAN3_EFF_RTR)
cf->can_id |= CAN_RTR_FLAG;

Expand All @@ -829,7 +829,7 @@ static void ican3_to_can_frame(struct ican3_dev *mod,
cf->can_id |= desc->data[3] >> 5; /* 2-0 */
}

memcpy(cf->data, &desc->data[6], sizeof(cf->data));
memcpy(cf->data, &desc->data[6], cf->can_dlc);
}
}

Expand Down Expand Up @@ -861,7 +861,7 @@ static void can_frame_to_ican3(struct ican3_dev *mod,
}

/* copy the data bits into the descriptor */
memcpy(&desc->data[6], cf->data, sizeof(cf->data));
memcpy(&desc->data[6], cf->data, cf->can_dlc);
}

/*
Expand Down

0 comments on commit 9e4d690

Please sign in to comment.