On Thu, Oct 21, 2010 at 07:53:31PM +0200, Marc Kleine-Budde wrote:
> This patch cleans up the ICAN3 to Linux CAN Frame Conversion function:
> 
> - Use get_can_dlc() to limit the dlc value.
> - Don't copy the whole frame, only copy the amount of bytes specified
>   in cf->can_dlc.
> 
> Signed-off-by: Marc Kleine-Budde <[email protected]>
> Cc: Ira W. Snyder <[email protected]>

Looks fine. If you're up for it, roll the following into the same patch.
It forces the TX path to respect the cf->can_dlc length when memcpy()ing
data into the transmit frame.

For the patch as-is, please add my Acked-by.

Thanks,
Ira

diff --git a/drivers/net/can/janz-ican3.c b/drivers/net/can/janz-ican3.c
index 8715162..e8e6695 100644
--- a/drivers/net/can/janz-ican3.c
+++ b/drivers/net/can/janz-ican3.c
@@ -863,7 +863,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);
 }
 
 /*

> ---
>  drivers/net/can/janz-ican3.c |    8 ++++----
>  1 files changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/net/can/janz-ican3.c b/drivers/net/can/janz-ican3.c
> index 6e533dc..7416f25 100644
> --- a/drivers/net/can/janz-ican3.c
> +++ b/drivers/net/can/janz-ican3.c
> @@ -812,10 +812,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;
>  
> @@ -830,7 +830,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);
>       }
>  }
>  
> -- 
> 1.7.0.4
> 
_______________________________________________
Socketcan-core mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/socketcan-core

Reply via email to