From: Tom Rini <trini@konsulko.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] usb: dwc3: fixes crash in dwc3 driver due to types size mismatch
Date: Fri, 22 Jul 2016 07:55:11 -0400 [thread overview]
Message-ID: <20160722115511.GL1623@bill-the-cat> (raw)
In-Reply-To: <CAK7LNATGoROLg6r=bEjuoSmmXabuE20SUKpJkE99XZhpUtDwjA@mail.gmail.com>
On Fri, Jul 22, 2016 at 02:10:22PM +0900, Masahiro Yamada wrote:
> Hi.
>
>
> 2016-07-21 21:29 GMT+09:00 B, Ravi <ravibabu@ti.com>:
> > Hi Marek
> >
> >>> The crash at dwc3 driver observed due to offset misalignment of
> >>> structure members across files causing wrong code generation and leads
> >>> to crash, the issue is found during dfu test.
> >>>
> >>> For instance, ther is is mismatch in code generation to access the
> >>> address of structure member dwc->dep[0] in gadget.c and ep0.c. This
> >>> leads to NULL pointer reference casuing the crash. The inclusion of
> >>> common.h fixes the issue.
> >
> >>Please explain why this patch fixes the issue.
> >
> > Ok I will explain, due to the commit[1] the resource_size_t size has increased to 8 bytes (64 bit), compared to earlier 32 bit (4bytes) and the definition is moved to includes/linux/types.h from asm.h. Due to this change the code generated in gadget.c is correct, due to inclusion of right header file (common.h, which includes linux/types.h). Whereas, the ep0.c does not includes common.h, hence size of resources_size_t is 4 bytes, causing wrong offset code generated for structure members which includes resource_size_t, which leads to pointing to wrong offset location causing the crash.
>
>
> I will explain it more precisely.
>
>
> Both gadget.c and ep.c include <linux/types.h>
>
> See,
> include/linux/types.h is included
> from include/linux/kernel.h included
> from drivers/usb/dwc3/ep0.c
>
>
> So, <linux/types.h> is not a problem.
>
>
> The root cause of problem is:
> gadget.c include <config.h>, but ep0.c does not.
>
>
> If <config.h> is not included, any CONFIGs
> from the board header are defined.
>
>
> The size of phys_addr_t depends on CONFIG_PHYS_64BIT
> as you see in:
>
>
> #ifdef CONFIG_PHYS_64BIT
> typedef unsigned long long phys_addr_t;
> typedef unsigned long long phys_size_t;
> #else
> /* DMA addresses are 32-bits wide */
> typedef unsigned long phys_addr_t;
> typedef unsigned long phys_size_t;
> #endif
>
>
> So, phys_addr_t is 8 byte in gadget.c
> and phys_addr_t is 4 byte in ep0.c
>
>
> My commit changed resource_size_t
> based on phys_addr_t, so it triggered
> the problem for DWC3, which had already potentially existed.
>
>
> CONFIGs in Kconfig are guaranteed to be defined for all files,
> but CONFIGs in board headers are not.
>
> So we need to make sure to add
> #include <common.h> (or #include <config.h>)
> in each source file.
>
>
> So, your patch is doing a right thing.
>
> I will issue my Reviewed-by when you update the git-log.
>
>
> (Moving CONFIG_PHYS_64BIT is a right thing as well)
Can we move PHYS_64BIT to Kconfig instead here please? This is the kind
of thing we should be able to select based on SoC / board. Thanks!
--
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160722/3a8a14c6/attachment.sig>
next prev parent reply other threads:[~2016-07-22 11:55 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-21 10:41 [U-Boot] [PATCH] usb: dwc3: fixes crash in dwc3 driver due to types size mismatch Ravi Babu
2016-07-21 11:42 ` Marek Vasut
2016-07-21 12:29 ` B, Ravi
2016-07-21 12:35 ` Marek Vasut
2016-07-21 12:44 ` B, Ravi
2016-07-21 12:54 ` Marek Vasut
2016-07-21 13:03 ` B, Ravi
2016-07-21 13:05 ` Marek Vasut
2016-07-22 5:10 ` Masahiro Yamada
2016-07-22 8:06 ` B, Ravi
2016-07-22 10:19 ` Marek Vasut
2016-07-22 11:55 ` Tom Rini [this message]
2016-07-26 12:59 ` B, Ravi
2016-07-26 13:04 ` Tom Rini
2016-07-26 13:16 ` B, Ravi
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=20160722115511.GL1623@bill-the-cat \
--to=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox