* [PATCH] ARM: orion: fix orion_ge00_switch_board_info initialization
@ 2018-02-21 12:18 Arnd Bergmann
2018-02-22 13:30 ` Andrew Lunn
0 siblings, 1 reply; 3+ messages in thread
From: Arnd Bergmann @ 2018-02-21 12:18 UTC (permalink / raw)
To: Jason Cooper, Andrew Lunn, Sebastian Hesselbarth, Gregory Clement
Cc: Arnd Bergmann, stable, linux-arm-kernel, linux-kernel
A section type mismatch warning shows up when building with LTO,
since orion_ge00_mvmdio_bus_name was put in __initconst but not marked
const itself:
include/linux/of.h: In function 'spear_setup_of_timer':
arch/arm/mach-spear/time.c:207:34: error: 'timer_of_match' causes a section type conflict with 'orion_ge00_mvmdio_bus_name'
static const struct of_device_id timer_of_match[] __initconst = {
^
arch/arm/plat-orion/common.c:475:32: note: 'orion_ge00_mvmdio_bus_name' was declared here
static __initconst const char *orion_ge00_mvmdio_bus_name = "orion-mii";
^
As pointed out by Andrew Lunn, it should in fact be 'const' but not
'__initconst' because the string is never copied but may be accessed
after the init sections are freed. To fix that, I get rid of the
extra symbol and rewrite the initialization in a simpler way that
assigns both the bus_id and modalias statically.
I spotted another theoretical bug in the same place, where d->netdev[i]
may be an out of bounds access, this can be fixed by moving the device
assignment into the loop.
Cc: stable@vger.kernel.org
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
v2: complete rewrite
---
arch/arm/plat-orion/common.c | 23 +++++++++++------------
1 file changed, 11 insertions(+), 12 deletions(-)
diff --git a/arch/arm/plat-orion/common.c b/arch/arm/plat-orion/common.c
index aff6994950ba..a2399fd66e97 100644
--- a/arch/arm/plat-orion/common.c
+++ b/arch/arm/plat-orion/common.c
@@ -472,28 +472,27 @@ void __init orion_ge11_init(struct mv643xx_eth_platform_data *eth_data,
/*****************************************************************************
* Ethernet switch
****************************************************************************/
-static __initconst const char *orion_ge00_mvmdio_bus_name = "orion-mii";
-static __initdata struct mdio_board_info
- orion_ge00_switch_board_info;
+static __initdata struct mdio_board_info orion_ge00_switch_board_info = {
+ .bus_id = "orion-mii",
+ .modalias = "mv88e6085",
+};
void __init orion_ge00_switch_init(struct dsa_chip_data *d)
{
- struct mdio_board_info *bd;
unsigned int i;
if (!IS_BUILTIN(CONFIG_PHYLIB))
return;
- for (i = 0; i < ARRAY_SIZE(d->port_names); i++)
- if (!strcmp(d->port_names[i], "cpu"))
+ for (i = 0; i < ARRAY_SIZE(d->port_names); i++) {
+ if (!strcmp(d->port_names[i], "cpu")) {
+ d->netdev[i] = &orion_ge00.dev;
break;
+ }
+ }
- bd = &orion_ge00_switch_board_info;
- bd->bus_id = orion_ge00_mvmdio_bus_name;
- bd->mdio_addr = d->sw_addr;
- d->netdev[i] = &orion_ge00.dev;
- strcpy(bd->modalias, "mv88e6085");
- bd->platform_data = d;
+ orion_ge00_switch_board_info.mdio_addr = d->sw_addr;
+ orion_ge00_switch_board_info.platform_data = d;
mdiobus_register_board_info(&orion_ge00_switch_board_info, 1);
}
--
2.9.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] ARM: orion: fix orion_ge00_switch_board_info initialization
2018-02-21 12:18 [PATCH] ARM: orion: fix orion_ge00_switch_board_info initialization Arnd Bergmann
@ 2018-02-22 13:30 ` Andrew Lunn
2018-02-22 16:49 ` Arnd Bergmann
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Lunn @ 2018-02-22 13:30 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Jason Cooper, Sebastian Hesselbarth, Gregory Clement,
linux-arm-kernel, stable, linux-kernel
On Wed, Feb 21, 2018 at 01:18:49PM +0100, Arnd Bergmann wrote:
> A section type mismatch warning shows up when building with LTO,
> since orion_ge00_mvmdio_bus_name was put in __initconst but not marked
> const itself:
>
> include/linux/of.h: In function 'spear_setup_of_timer':
> arch/arm/mach-spear/time.c:207:34: error: 'timer_of_match' causes a section type conflict with 'orion_ge00_mvmdio_bus_name'
> static const struct of_device_id timer_of_match[] __initconst = {
> ^
> arch/arm/plat-orion/common.c:475:32: note: 'orion_ge00_mvmdio_bus_name' was declared here
> static __initconst const char *orion_ge00_mvmdio_bus_name = "orion-mii";
> ^
>
> As pointed out by Andrew Lunn, it should in fact be 'const' but not
> '__initconst' because the string is never copied but may be accessed
> after the init sections are freed. To fix that, I get rid of the
> extra symbol and rewrite the initialization in a simpler way that
> assigns both the bus_id and modalias statically.
>
> I spotted another theoretical bug in the same place, where d->netdev[i]
> may be an out of bounds access, this can be fixed by moving the device
> assignment into the loop.
>
> Cc: stable@vger.kernel.org
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Andrew
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] ARM: orion: fix orion_ge00_switch_board_info initialization
2018-02-22 13:30 ` Andrew Lunn
@ 2018-02-22 16:49 ` Arnd Bergmann
0 siblings, 0 replies; 3+ messages in thread
From: Arnd Bergmann @ 2018-02-22 16:49 UTC (permalink / raw)
To: Andrew Lunn
Cc: Jason Cooper, Sebastian Hesselbarth, Gregory Clement, Linux ARM,
# 3.4.x, Linux Kernel Mailing List
On Thu, Feb 22, 2018 at 2:30 PM, Andrew Lunn <andrew@lunn.ch> wrote:
> On Wed, Feb 21, 2018 at 01:18:49PM +0100, Arnd Bergmann wrote:
>> A section type mismatch warning shows up when building with LTO,
>> since orion_ge00_mvmdio_bus_name was put in __initconst but not marked
>> const itself:
>>
>> include/linux/of.h: In function 'spear_setup_of_timer':
>> arch/arm/mach-spear/time.c:207:34: error: 'timer_of_match' causes a section type conflict with 'orion_ge00_mvmdio_bus_name'
>> static const struct of_device_id timer_of_match[] __initconst = {
>> ^
>> arch/arm/plat-orion/common.c:475:32: note: 'orion_ge00_mvmdio_bus_name' was declared here
>> static __initconst const char *orion_ge00_mvmdio_bus_name = "orion-mii";
>> ^
>>
>> As pointed out by Andrew Lunn, it should in fact be 'const' but not
>> '__initconst' because the string is never copied but may be accessed
>> after the init sections are freed. To fix that, I get rid of the
>> extra symbol and rewrite the initialization in a simpler way that
>> assigns both the bus_id and modalias statically.
>>
>> I spotted another theoretical bug in the same place, where d->netdev[i]
>> may be an out of bounds access, this can be fixed by moving the device
>> assignment into the loop.
>>
>> Cc: stable@vger.kernel.org
>> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
>
> Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Thanks, applied into fixes branch with your Reviewed-by tag now.
Arnd
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-02-22 16:49 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-21 12:18 [PATCH] ARM: orion: fix orion_ge00_switch_board_info initialization Arnd Bergmann
2018-02-22 13:30 ` Andrew Lunn
2018-02-22 16:49 ` Arnd Bergmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).