* Nested function in drivers/of/of_mdio.c
@ 2009-10-07 15:15 Jérôme Pouiller
2009-10-07 16:11 ` Grant Likely
0 siblings, 1 reply; 7+ messages in thread
From: Jérôme Pouiller @ 2009-10-07 15:15 UTC (permalink / raw)
To: Grant Likely; +Cc: netdev, linuxppc, Andy Fleming, David S. Miller
Dear,
I have a problem with commit 8bc487d150b939e69830c39322df4ee486efe381=20
in file drivers/of/of_mdio.c in function of_phy_find_device.
As you see, this function define match() as a nested function. My=20
compiler (powerpc-e500-linux-gnu-gcc-3.4.1) raise an error during link=20
due to this nested definition:
drivers/built-in.o(.text+0x5e2a4): In function `of_phy_find_device': /hom=
e/jezz/linux-next/drivers/of/of_mdio.c:107:=20
undefined reference to `__trampoline_setup'
I am sure I could solve problem by rebuilding my toolchain.=20
Nevertheless, I think nested function definition is not perfectly=20
supported by all compilers. Also, I suggest to place function match()=20
outside of scope of of_phy_find_device as in following patch.
diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c
index bacaa53..c7b2e26 100644
=2D-- a/drivers/of/of_mdio.c
+++ b/drivers/of/of_mdio.c
@@ -97,6 +97,10 @@ int of_mdiobus_register(struct mii_bus *mdio, struct dev=
ice_node *np)
}
EXPORT_SYMBOL(of_mdiobus_register);
+static int match(struct device *dev, void *phy_np)
+{
+ return dev_archdata_get_node(&dev->archdata) =3D=3D phy_np;
+}
/**
* of_phy_find_device - Give a PHY node, find the phy_device
* @phy_np: Pointer to the phy's device tree node
@@ -106,11 +110,6 @@ EXPORT_SYMBOL(of_mdiobus_register);
struct phy_device *of_phy_find_device(struct device_node *phy_np)
{
struct device *d;
=2D int match(struct device *dev, void *phy_np)
=2D {
=2D return dev_archdata_get_node(&dev->archdata) =3D=3D phy_n=
p;
=2D }
=2D
if (!phy_np)
return NULL;
What do you think about it?
Best regards,
=2D-=20
J=E9r=F4me Pouiller (jezz AT sysmic DOT org)
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Nested function in drivers/of/of_mdio.c
2009-10-07 15:15 Nested function in drivers/of/of_mdio.c Jérôme Pouiller
@ 2009-10-07 16:11 ` Grant Likely
2009-10-07 16:23 ` vb
2009-10-08 8:34 ` [PATCH] Remove nested function Jérôme Pouiller
0 siblings, 2 replies; 7+ messages in thread
From: Grant Likely @ 2009-10-07 16:11 UTC (permalink / raw)
To: Jérôme Pouiller; +Cc: netdev, linuxppc, Andy Fleming, David S. Miller
On Wed, Oct 7, 2009 at 9:15 AM, J=E9r=F4me Pouiller <jezz@sysmic.org> wrote=
:
> Dear,
>
> I have a problem with commit 8bc487d150b939e69830c39322df4ee486efe381
> in file drivers/of/of_mdio.c in function of_phy_find_device.
>
> As you see, this function define match() as a nested function. My
> compiler (powerpc-e500-linux-gnu-gcc-3.4.1) raise an error during link
> due to this nested definition:
> =A0drivers/built-in.o(.text+0x5e2a4): In function `of_phy_find_device': /=
home/jezz/linux-next/drivers/of/of_mdio.c:107:
> undefined reference to `__trampoline_setup'
>
> I am sure I could solve problem by rebuilding my toolchain.
> Nevertheless, I think nested function definition is not perfectly
> supported by all compilers. Also, I suggest to place function match()
> outside of scope of of_phy_find_device as in following patch.
I'm okay with that, but if you're moving code out of the file scope,
then please rename the function to of_phy_match() to avoid global
namespace conflicts.
g.
>
> diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c
> index bacaa53..c7b2e26 100644
> --- a/drivers/of/of_mdio.c
> +++ b/drivers/of/of_mdio.c
> @@ -97,6 +97,10 @@ int of_mdiobus_register(struct mii_bus *mdio, struct d=
evice_node *np)
> =A0}
> =A0EXPORT_SYMBOL(of_mdiobus_register);
>
> +static int match(struct device *dev, void *phy_np)
> +{
> + =A0 =A0 =A0 return dev_archdata_get_node(&dev->archdata) =3D=3D phy_np;
> +}
> =A0/**
> =A0* of_phy_find_device - Give a PHY node, find the phy_device
> =A0* @phy_np: Pointer to the phy's device tree node
> @@ -106,11 +110,6 @@ EXPORT_SYMBOL(of_mdiobus_register);
> =A0struct phy_device *of_phy_find_device(struct device_node *phy_np)
> =A0{
> =A0 =A0 =A0 =A0struct device *d;
> - =A0 =A0 =A0 int match(struct device *dev, void *phy_np)
> - =A0 =A0 =A0 {
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 return dev_archdata_get_node(&dev->archdata=
) =3D=3D phy_np;
> - =A0 =A0 =A0 }
> -
> =A0 =A0 =A0 =A0if (!phy_np)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return NULL;
>
>
> What do you think about it?
>
> Best regards,
>
> --
> J=E9r=F4me Pouiller (jezz AT sysmic DOT org)
>
--=20
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Nested function in drivers/of/of_mdio.c
2009-10-07 16:11 ` Grant Likely
@ 2009-10-07 16:23 ` vb
2009-10-08 8:45 ` Jérôme Pouiller
2009-10-08 8:34 ` [PATCH] Remove nested function Jérôme Pouiller
1 sibling, 1 reply; 7+ messages in thread
From: vb @ 2009-10-07 16:23 UTC (permalink / raw)
To: Grant Likely; +Cc: netdev, linuxppc, Andy Fleming, David S. Miller
Guys, are there other instances of nested C functions in the codebase
or was this the first attempt?
On Wed, Oct 7, 2009 at 9:11 AM, Grant Likely <grant.likely@secretlab.ca> wr=
ote:
> On Wed, Oct 7, 2009 at 9:15 AM, J=E9r=F4me Pouiller <jezz@sysmic.org> wro=
te:
>> Dear,
>>
>> I have a problem with commit 8bc487d150b939e69830c39322df4ee486efe381
>> in file drivers/of/of_mdio.c in function of_phy_find_device.
>>
>> As you see, this function define match() as a nested function. My
>> compiler (powerpc-e500-linux-gnu-gcc-3.4.1) raise an error during link
>> due to this nested definition:
>> =A0drivers/built-in.o(.text+0x5e2a4): In function `of_phy_find_device': =
/home/jezz/linux-next/drivers/of/of_mdio.c:107:
>> undefined reference to `__trampoline_setup'
>>
>> I am sure I could solve problem by rebuilding my toolchain.
>> Nevertheless, I think nested function definition is not perfectly
>> supported by all compilers. Also, I suggest to place function match()
>> outside of scope of of_phy_find_device as in following patch.
>
> I'm okay with that, but if you're moving code out of the file scope,
> then please rename the function to of_phy_match() to avoid global
> namespace conflicts.
>
> g.
>
>>
>> diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c
>> index bacaa53..c7b2e26 100644
>> --- a/drivers/of/of_mdio.c
>> +++ b/drivers/of/of_mdio.c
>> @@ -97,6 +97,10 @@ int of_mdiobus_register(struct mii_bus *mdio, struct =
device_node *np)
>> =A0}
>> =A0EXPORT_SYMBOL(of_mdiobus_register);
>>
>> +static int match(struct device *dev, void *phy_np)
>> +{
>> + =A0 =A0 =A0 return dev_archdata_get_node(&dev->archdata) =3D=3D phy_np=
;
>> +}
>> =A0/**
>> =A0* of_phy_find_device - Give a PHY node, find the phy_device
>> =A0* @phy_np: Pointer to the phy's device tree node
>> @@ -106,11 +110,6 @@ EXPORT_SYMBOL(of_mdiobus_register);
>> =A0struct phy_device *of_phy_find_device(struct device_node *phy_np)
>> =A0{
>> =A0 =A0 =A0 =A0struct device *d;
>> - =A0 =A0 =A0 int match(struct device *dev, void *phy_np)
>> - =A0 =A0 =A0 {
>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 return dev_archdata_get_node(&dev->archdat=
a) =3D=3D phy_np;
>> - =A0 =A0 =A0 }
>> -
>> =A0 =A0 =A0 =A0if (!phy_np)
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return NULL;
>>
>>
>> What do you think about it?
>>
>> Best regards,
>>
>> --
>> J=E9r=F4me Pouiller (jezz AT sysmic DOT org)
>>
>
>
>
> --
> Grant Likely, B.Sc., P.Eng.
> Secret Lab Technologies Ltd.
> _______________________________________________
> Linuxppc-dev mailing list
> Linuxppc-dev@lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/linuxppc-dev
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] Remove nested function
2009-10-07 16:11 ` Grant Likely
2009-10-07 16:23 ` vb
@ 2009-10-08 8:34 ` Jérôme Pouiller
2009-10-08 9:10 ` David Miller
1 sibling, 1 reply; 7+ messages in thread
From: Jérôme Pouiller @ 2009-10-08 8:34 UTC (permalink / raw)
To: Grant Likely
Cc: netdev, linuxppc, Andy Fleming, Jérôme Pouiller,
David S. Miller
Some toolchains dislike nested function definition, so we define function match
outside of of_phy_find_device.
Signed-off-by: Jérôme Pouiller <jezz@sysmic.org>
---
drivers/of/of_mdio.c | 13 +++++++------
1 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c
index bacaa53..4b22ba5 100644
--- a/drivers/of/of_mdio.c
+++ b/drivers/of/of_mdio.c
@@ -97,6 +97,12 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
}
EXPORT_SYMBOL(of_mdiobus_register);
+/* Helper function for of_phy_find_device */
+static int of_phy_match(struct device *dev, void *phy_np)
+{
+ return dev_archdata_get_node(&dev->archdata) == phy_np;
+}
+
/**
* of_phy_find_device - Give a PHY node, find the phy_device
* @phy_np: Pointer to the phy's device tree node
@@ -106,15 +112,10 @@ EXPORT_SYMBOL(of_mdiobus_register);
struct phy_device *of_phy_find_device(struct device_node *phy_np)
{
struct device *d;
- int match(struct device *dev, void *phy_np)
- {
- return dev_archdata_get_node(&dev->archdata) == phy_np;
- }
-
if (!phy_np)
return NULL;
- d = bus_find_device(&mdio_bus_type, NULL, phy_np, match);
+ d = bus_find_device(&mdio_bus_type, NULL, phy_np, of_phy_match);
return d ? to_phy_device(d) : NULL;
}
EXPORT_SYMBOL(of_phy_find_device);
--
1.6.0.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: Nested function in drivers/of/of_mdio.c
2009-10-07 16:23 ` vb
@ 2009-10-08 8:45 ` Jérôme Pouiller
2009-10-08 11:14 ` Gabriel Paubert
0 siblings, 1 reply; 7+ messages in thread
From: Jérôme Pouiller @ 2009-10-08 8:45 UTC (permalink / raw)
To: linuxppc-dev, Grant Likely; +Cc: netdev, Andy Fleming, David S. Miller
I did some grep on codebase. I have not found any other instances of=20
nested functions, but my regexps are not enough to be 100% sure.
On Wednesday 07 October 2009 18:23:04 vb@vsbe.com wrote:
> Guys, are there other instances of nested C functions in the codebase
> or was this the first attempt?
>=20
> On Wed, Oct 7, 2009 at 9:11 AM, Grant Likely=20
<grant.likely@secretlab.ca> wrote:
> > On Wed, Oct 7, 2009 at 9:15 AM, J=E9r=F4me Pouiller <jezz@sysmic.org>=20
wrote:
> >> Dear,
> >>
> >> I have a problem with commit
> >> 8bc487d150b939e69830c39322df4ee486efe381 in file
> >> drivers/of/of_mdio.c in function of_phy_find_device.
> >>
> >> As you see, this function define match() as a nested function. My
> >> compiler (powerpc-e500-linux-gnu-gcc-3.4.1) raise an error during
> >> link due to this nested definition:
> >> drivers/built-in.o(.text+0x5e2a4): In function
> >> `of_phy_find_device':
> >> /home/jezz/linux-next/drivers/of/of_mdio.c:107: undefined
> >> reference to `__trampoline_setup'
> >>
> >> I am sure I could solve problem by rebuilding my toolchain.
> >> Nevertheless, I think nested function definition is not perfectly
> >> supported by all compilers. Also, I suggest to place function
> >> match() outside of scope of of_phy_find_device as in following
> >> patch.
> >
> > I'm okay with that, but if you're moving code out of the file
> > scope, then please rename the function to of_phy_match() to avoid
> > global namespace conflicts.
> >
> > g.
> >
> >> diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c
> >> index bacaa53..c7b2e26 100644
> >> --- a/drivers/of/of_mdio.c
> >> +++ b/drivers/of/of_mdio.c
> >> @@ -97,6 +97,10 @@ int of_mdiobus_register(struct mii_bus *mdio,
> >> struct device_node *np) }
> >> EXPORT_SYMBOL(of_mdiobus_register);
> >>
> >> +static int match(struct device *dev, void *phy_np)
> >> +{
> >> + return dev_archdata_get_node(&dev->archdata) =3D=3D phy_np;
> >> +}
> >> /**
> >> * of_phy_find_device - Give a PHY node, find the phy_device
> >> * @phy_np: Pointer to the phy's device tree node
> >> @@ -106,11 +110,6 @@ EXPORT_SYMBOL(of_mdiobus_register);
> >> struct phy_device *of_phy_find_device(struct device_node *phy_np)
> >> {
> >> struct device *d;
> >> - int match(struct device *dev, void *phy_np)
> >> - {
> >> - return dev_archdata_get_node(&dev->archdata) =3D=3D
> >> phy_np; - }
> >> -
> >> if (!phy_np)
> >> return NULL;
> >>
> >>
> >> What do you think about it?
> >>
> >> Best regards,
> >>
> >> --
> >> J=E9r=F4me Pouiller (jezz AT sysmic DOT org)
> >
> > --
> > Grant Likely, B.Sc., P.Eng.
> > Secret Lab Technologies Ltd.
> > _______________________________________________
> > Linuxppc-dev mailing list
> > Linuxppc-dev@lists.ozlabs.org
> > https://lists.ozlabs.org/listinfo/linuxppc-dev
>=20
> _______________________________________________
> Linuxppc-dev mailing list
> Linuxppc-dev@lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/linuxppc-dev
>=20
=2D-=20
J=E9r=F4me Pouiller (jerome AT sysmic DOT org)
Expert Linux Embarqu=E9
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Remove nested function
2009-10-08 8:34 ` [PATCH] Remove nested function Jérôme Pouiller
@ 2009-10-08 9:10 ` David Miller
0 siblings, 0 replies; 7+ messages in thread
From: David Miller @ 2009-10-08 9:10 UTC (permalink / raw)
To: jezz; +Cc: netdev, linuxppc-dev, afleming
From: J=E9r=F4me Pouiller <jezz@sysmic.org>
Date: Thu, 8 Oct 2009 10:34:23 +0200
> Some toolchains dislike nested function definition, so we define func=
tion match
> outside of of_phy_find_device.
> =
> Signed-off-by: J=E9r=F4me Pouiller <jezz@sysmic.org>
Acked-by: David S. Miller <davem@davemloft.net>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Nested function in drivers/of/of_mdio.c
2009-10-08 8:45 ` Jérôme Pouiller
@ 2009-10-08 11:14 ` Gabriel Paubert
0 siblings, 0 replies; 7+ messages in thread
From: Gabriel Paubert @ 2009-10-08 11:14 UTC (permalink / raw)
To: Jérôme Pouiller
Cc: netdev, linuxppc-dev, Andy Fleming, David S. Miller
On Thu, Oct 08, 2009 at 10:45:12AM +0200, Jérôme Pouiller wrote:
> I did some grep on codebase. I have not found any other instances of
> nested functions, but my regexps are not enough to be 100% sure.
>From Documentation/CodingStyle, written by the Head Penguin himself:
"Heretic people all over the world have claimed that this inconsistency
is ... well ... inconsistent, but all right-thinking people know that
(a) K&R are _right_ and (b) K&R are right. Besides, functions are
special anyway (you can't nest them in C)."
^^^^^^^^^^^^^^^^^^^^^^^^
I interpret it as a clear prohibition of using nested functions
in the kernel.
Regards,
Gabriel
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2009-10-08 11:14 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-07 15:15 Nested function in drivers/of/of_mdio.c Jérôme Pouiller
2009-10-07 16:11 ` Grant Likely
2009-10-07 16:23 ` vb
2009-10-08 8:45 ` Jérôme Pouiller
2009-10-08 11:14 ` Gabriel Paubert
2009-10-08 8:34 ` [PATCH] Remove nested function Jérôme Pouiller
2009-10-08 9:10 ` David Miller
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).