From: Oliver Hartkopp <socketcan@hartkopp.net>
To: Wolfram Sang <w.sang@pengutronix.de>
Cc: Wolfgang Grandegger <wg@grandegger.com>,
Linux Netdev List <netdev@vger.kernel.org>,
Andre Naujoks <nautsch@gmail.com>
Subject: Re: [PATCH net] mscan: zero accidentally copied register content
Date: Wed, 05 Oct 2011 18:10:29 +0200 [thread overview]
Message-ID: <4E8C8175.2040202@hartkopp.net> (raw)
In-Reply-To: <20111005155127.GB13794@pengutronix.de>
On 10/05/11 17:51, Wolfram Sang wrote:
> On Wed, Oct 05, 2011 at 05:34:00PM +0200, Oliver Hartkopp wrote:
>> 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 clears the data byte read from the invalid register entry.
>>
>> Reported-by: Andre Naujoks <nautsch@gmail.com>
>> Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
>>
>> ---
>>
>> Hello Wolf[gang|ram],
>>
>> from an error report from Andre Naujoks i tracked down the problem of
>> uninitialized data in (normally) initialized CAN frames to the mscan driver.
>>
>> Regards,
>> Oliver
>>
>>
>> diff --git a/drivers/net/can/mscan/mscan.c b/drivers/net/can/mscan/mscan.c
>> index 92feac6..1b60fbe 100644
>> --- a/drivers/net/can/mscan/mscan.c
>> +++ b/drivers/net/can/mscan/mscan.c
>> @@ -327,20 +327,23 @@ static void mscan_get_rx_frame(struct net_device *dev, struct can_frame *frame)
>> frame->can_dlc = get_can_dlc(in_8(®s->rx.dlr) & 0xf);
>>
>> if (!(frame->can_id & CAN_RTR_FLAG)) {
>> void __iomem *data = ®s->rx.dsr1_0;
>> u16 *payload = (u16 *)frame->data;
>>
>> for (i = 0; i < (frame->can_dlc + 1) / 2; i++) {
>> *payload++ = in_be16(data);
>> data += 2 + _MSCAN_RESERVED_DSR_SIZE;
>> }
>> + /* zero accidentally copied register content at odd DLCs */
>> + if (frame->can_dlc & 1)
>> + frame->data[frame->can_dlc] = 0;
>> }
>>
>> out_8(®s->canrflg, MSCAN_RXF);
>
> Nice catch, but wouldn't it be more elegant to never have an invalid byte
> in the first place?
>
> if (can_dlc & 1)
> *payload = in_be16() & mask;
>
Hm, then i would rather think about changing the for() statement and to read
byte-by-byte instead of the current in_be16() usage with the 16bit access
drawbacks ...
Regards,
Oliver
next prev parent reply other threads:[~2011-10-05 16:10 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-05 15:34 [PATCH net] mscan: zero accidentally copied register content Oliver Hartkopp
2011-10-05 15:51 ` Wolfram Sang
2011-10-05 16:10 ` Oliver Hartkopp [this message]
2011-10-06 7:02 ` Oliver Hartkopp
2011-10-06 9:09 ` Wolfgang Grandegger
2011-10-06 9:24 ` Wolfram Sang
2011-10-06 14:01 ` Oliver Hartkopp
2011-10-06 14:09 ` Wolfram Sang
2011-10-06 14:14 ` Andre Naujoks
2011-10-06 14:33 ` Oliver Hartkopp
2011-10-06 15:03 ` Andre Naujoks
2011-10-06 18:24 ` Wolfgang Grandegger
2011-10-10 16:38 ` Oliver Hartkopp
2011-10-06 18:25 ` Marc Kleine-Budde
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4E8C8175.2040202@hartkopp.net \
--to=socketcan@hartkopp.net \
--cc=nautsch@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=w.sang@pengutronix.de \
--cc=wg@grandegger.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.