net: Fix compiler-error on dgrs.c when !CONFIG_PCI
Subsystems (2)
PATCH 1/1 net: Fix compiler-error on dgrs.c when !CONFIG_PCI
From: Richard Knutsson <[email protected]>
Fix compiler-error on dgrs.c when CONFIG_PCI not set.
---
dgrs.c | 2 ++ 1 files changed, 2 insertions(+)
drivers/net/dgrs.c +2 -0
@@ -1458,6 +1458,8 @@ static struct pci_driver dgrs_pci_driver .probe = dgrs_pci_probe, .remove = __devexit_p(dgrs_pci_remove), }; +#else +static struct pci_driver dgrs_pci_driver = {};#endif
drivers/net/dgrs.c 2005-11-19 20:29:52.000000000 +0100 static struct pci_driver dgrs_pci_driver · line 1463
Quoted 11 lines · Richard Knutsson
diff -Narup
a/drivers/net/dgrs.cb/drivers/net/dgrs.cdrivers/net/dgrs.c 2005-11-19 20:29:52.000000000 +0100 renamed from drivers/net/dgrs.c 2005-11-19 20:17:51.000000000 +0100 +2
-0@@ -1458,6 +1458,8 @@ static struct pci_driver dgrs_pci_driver .probe = dgrs_pci_probe, .remove = __devexit_p(dgrs_pci_remove), }; +#else +static struct pci_driver dgrs_pci_driver = {}; #endif
How about something like this?
[NETDRV] dgrs: Fix compiler-error on dgrs.c when !CONFIG_PCI
The previous patch on this driver removed the #ifdef CONFIG_PCI around the pci_register_driver call in order to avoid a warning about an unused variable. This produces an error since the PCI driver object is undefined if CONFIG_PCI is not set.
Instead of doing that, we should simply make sure that the cardcount variable is always used.
The following patch does this by making inline function wrappers to do the actual registration/deregistration.
This problem was reported by Richard Knutsson.
Cheers,
Signature · 5 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
--drivers/net/dgrs.c +45 -11
@@ -1458,6 +1458,25 @@ static struct pci_driver dgrs_pci_driver .probe = dgrs_pci_probe, .remove = __devexit_p(dgrs_pci_remove), }; + +static inline int dgrs_register_pci (void ) +{ +return pci_register_driver (&dgrs_pci_driver); +} + +static inline void dgrs_unregister_pci (void ) +{ +pci_unregister_driver (&dgrs_pci_driver); +} +#else +static inline int dgrs_register_pci (void ) +{ +return 0 ; +} + +static inline int dgrs_unregister_pci (void ) +{ +}#endif
@@ -1520,6 +1539,25 @@ static struct eisa_driver dgrs_eisa_driv .remove = __devexit_p(dgrs_eisa_remove), } }; + +static inline int dgrs_register_eisa (void ) +{ +return eisa_driver_register (&dgrs_eisa_driver); +} + +static inline void dgrs_unregister_eisa (void ) +{ +eisa_driver_unregister (&dgrs_eisa_driver); +} +#else +static inline int dgrs_register_eisa (void ) +{ +return 0 ; +} + +static inline void dgrs_unregister_eisa (void ) +{ +}#endif /*
@@ -1590,25 +1628,21 @@ static int __init dgrs_init_module (void/* * Find and configure all the cards */ -#ifdef CONFIG_EISA - cardcount =eisa_driver_register (&dgrs_eisa_driver); + cardcount =dgrs_register_eisa ();if (cardcount <0 )return cardcount; -#endif - cardcount =pci_register_driver (&dgrs_pci_driver); -if (cardcount) + cardcount =dgrs_register_pci (); +if (cardcount <0 ) { +dgrs_unregister_eisa ();return cardcount; + }return 0 ; } static void __exit dgrs_cleanup_module (void) { -#ifdef CONFIG_EISA -eisa_driver_unregister (&dgrs_eisa_driver); -#endif -#ifdef CONFIG_PCI -pci_unregister_driver (&dgrs_pci_driver); -#endif +dgrs_unregister_pci (); +dgrs_unregister_eisa (); }module_init (dgrs_init_module);
Quoted 18 lines · Herbert Xu
drivers/net/dgrs.c 2005-11-19 20:29:52.000000000 +0100 static struct pci_driver dgrs_pci_driver · line 1465
Quoted 12 lines · Richard Knutsson
diff -Narup
a/drivers/net/dgrs.cb/drivers/net/dgrs.cdrivers/net/dgrs.c 2005-11-19 20:29:52.000000000 +0100 renamed from drivers/net/dgrs.c 2005-11-19 20:17:51.000000000 +0100 +2
-0@@ -1458,6 +1458,8 @@ static struct pci_driver dgrs_pci_driver .probe = dgrs_pci_probe, .remove = __devexit_p(dgrs_pci_remove), }; +#else +static struct pci_driver dgrs_pci_driver = {}; #endifHow about something like this?
Quoted 3 lines
[NETDRV] dgrs: Fix compiler-error on
dgrs.cwhen !CONFIG_PCI
[NETDRV], is that "standard" formating? If so, is there any more? Thanks :)
Quoted 6 lines
The previous patch on this driver removed the #ifdef
CONFIG_PCIaround thepci_register_drivercall in order to avoid a warning about an unused variable. This produces an error since the PCI driver object is undefined ifCONFIG_PCIis not set.
Well, not really. The removal of CONFIG_PCI was just a final touch by Andrew Morton. The only real change were from having two variables, for eisa and pci, to having one common.
Quoted 4 lines
Instead of doing that, we should simply make sure that the cardcount variable is always used.
Is it not? The problem were that dgrs_pci_driver was not defined if !CONFIG_PCI, and because the pci_*-functions have empty shells if !CONFIG_PCI, it is quite nice to use them without #ifdef. So the simplest solution (as I saw it) was to define an empty dgrs_pci_driver when CONFIG_PCI is not set.
On the design perspective, I would argue that struct's is more appropriate within #ifdef's then functions.
Quoted 4 lines
The following patch does this by making inline function wrappers to do the actual registration/deregistration.
I must say, I like that eisa gets addressed in the same manner as pci. But is it not more appropriate to implement empty eisa-functions if !CONFIG_EISA in linux/eisa.h (or equal)?
Quoted 7 lines
This problem was reported by Richard Knutsson.
Signed-off-by Herbert Xu <[email protected]>Cheers,
Thank you for the review,
Richard Knutsson
PS
You realize you have not tushed the cardcount-"problem"? ;) DS
Quoted 59 lines
drivers/net/dgrs.c +38
-0@@ -1458,6 +1458,25 @@ static struct pci_driver dgrs_pci_driver .probe = dgrs_pci_probe, .remove = __devexit_p(dgrs_pci_remove), }; + +static inline int dgrs_register_pci (void ) +{ +return pci_register_driver (&dgrs_pci_driver); +} + +static inline void dgrs_unregister_pci (void ) +{ +pci_unregister_driver (&dgrs_pci_driver); +} +#else +static inline int dgrs_register_pci (void ) +{ +return 0 ; +} + +static inline int dgrs_unregister_pci (void ) +{ +}#endif @@ -1520,6 +1539,25 @@ static struct eisa_driver dgrs_eisa_driv .remove = __devexit_p(dgrs_eisa_remove), } }; + +static inline int dgrs_register_eisa (void ) +{ +return eisa_driver_register (&dgrs_eisa_driver); +} + +static inline void dgrs_unregister_eisa (void ) +{ +eisa_driver_unregister (&dgrs_eisa_driver); +} +#else +static inline int dgrs_register_eisa (void ) +{ +return 0 ; +} + +static inline void dgrs_unregister_eisa (void ) +{ +}#endif /* @@ -1590,25 +1628,21 @@ static int __init dgrs_init_module (void/* * Find and configure all the cards */
drivers/net/dgrs.c static int __init dgrs_init_module (void · line 1635
Quoted 10 lines
drivers/net/dgrs.c +3
-5-#ifdef CONFIG_EISA - cardcount =eisa_driver_register (&dgrs_eisa_driver); + cardcount =dgrs_register_eisa ();if (cardcount <0 )return cardcount; -#endif - cardcount =pci_register_driver (&dgrs_pci_driver); -if (cardcount) + cardcount =dgrs_register_pci (); +if (cardcount <0 ) {
Are you sure it should be "cardcount < 0" and not "cardcount"?
drivers/net/dgrs.c static int __init dgrs_init_module (void · line 1636
Quoted 1 line
drivers/net/dgrs.c +1
-0+dgrs_unregister_eisa ();
Why change the behaviour off this driver?
Quoted 18 lines
drivers/net/dgrs.c +3
-6return cardcount; + }return 0 ; } static void __exit dgrs_cleanup_module (void) { -#ifdef CONFIG_EISA -eisa_driver_unregister (&dgrs_eisa_driver); -#endif -#ifdef CONFIG_PCI -pci_unregister_driver (&dgrs_pci_driver); -#endif +dgrs_unregister_pci (); +dgrs_unregister_eisa (); }module_init (dgrs_init_module);
Quoted 12 lines · Richard Knutsson
drivers/net/dgrs.c static int __init dgrs_init_module (void · line 1635
Quoted 11 lines
drivers/net/dgrs.c +1
-2-#ifdef CONFIG_EISA - cardcount =eisa_driver_register (&dgrs_eisa_driver); + cardcount =dgrs_register_eisa ();if (cardcount < 0) return cardcount;drivers/net/dgrs.c +2
-3-#endif - cardcount =pci_register_driver (&dgrs_pci_driver); -if (cardcount) + cardcount =dgrs_register_pci (); +if (cardcount <0 ) {Are you sure it should be "cardcount < 0" and not "cardcount"?
Yes if cardcount is >= 0 then the registration was successful.
Quoted 2 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ dgrs_unregister_eisa();Why change the behaviour off this driver?
Because the driver was buggy. When this function returns a non-zero value, it must return the system to its original state.
That means if the EISA driver has already been registered then it must be unregistered.
Cheers,
Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txtQuoted 30 lines · Herbert Xu
Quoted 5 lines · Richard Knutsson
Quoted 5 lines
(quoted diff) +1
-2-#ifdef CONFIG_EISA - cardcount = eisa_driver_register(&dgrs_eisa_driver); + cardcount = dgrs_register_eisa();if (cardcount < 0) return cardcount;Quoted 10 lines
Review
Quoted 7 lines
(quoted diff) +2
-3-#endif - cardcount = pci_register_driver(&dgrs_pci_driver); - if (cardcount) + cardcount = dgrs_register_pci(); + if (cardcount < 0) {Are you sure it should be "cardcount < 0" and not "cardcount"?
Yes if cardcount is >= 0 then the registration was successful.
Quoted 6 lines
Review
Quoted 3 lines
(quoted diff) +1
-0+ dgrs_unregister_eisa();Why change the behaviour off this driver?
Quoted 9 lines
Because the driver was buggy. When this function returns a non-zero value, it must return the system to its original state.
That means if the EISA driver has already been registered then it must be unregistered.
Cheers,
What do you think about this patch? Will you sign it? It is no longer an error-warning-fix but a bug-fix (and some cleanup).
I "took" you implementation of dgrs_(un)register_eisa(), especially since eisa needed to be unregistered if pci succeeds (I take you word for it to be so). (BTW, this patch is compiled with CONFIG_PCI set, CONFIG_EISA set and both set without errors/warnings for dgrs.o.)
This patch requirer the "net-fix-compiler-error-on-dgrsc-when-config_pci.patch" (added to the -mm tree after 2.6.15-rc1-mm2):
drivers/net/dgrs.c renamed from drivers/net/dgrs.c~net-fix-compiler-error-on-dgrsc-when-config_pci +0 -0
@@ -1458,6 +1458,8 @@ static struct pci_driver dgrs_pci_driver
.probe = dgrs_pci_probe, .remove = __devexit_p(dgrs_pci_remove), };
+#else
+static struct pci_driver dgrs_pci_driver = {};
#endif
---
drivers/net/dgrs.c +0 -0
@@ -1522,6 +1522,26 @@ static struct eisa_driver dgrs_eisa_driv
.remove = __devexit_p(dgrs_eisa_remove), } };
+
+
+static inline int dgrs_register_eisa(void)
+{
+ return eisa_driver_register(&dgrs_eisa_driver);
+}
+
+static inline void dgrs_unregister_eisa(void)
+{
+ eisa_driver_unregister(&dgrs_eisa_driver);
+}
+
+#else
+
+static inline int dgrs_register_eisa(void)
+{
+ return 0;
+}
+
+static inline void dgrs_unregister_eisa(void) {}
#endif
/*
@@ -1551,7 +1571,7 @@ MODULE_PARM_DESC(nicmode, "Digi RightSwi static int __init dgrs_init_module (void)
{
int i;- int cardcount = 0;
+ int cardcount;
/*
* Command line variable overrides
@@ -1592,25 +1612,23 @@ static int __init dgrs_init_module (void
/*
* Find and configure all the cards
*/
-#ifdef CONFIG_EISA
- cardcount = eisa_driver_register(&dgrs_eisa_driver);
+
+ cardcount = dgrs_register_eisa();
if (cardcount < 0)
return cardcount;
-#endif
+
cardcount = pci_register_driver(&dgrs_pci_driver);
- if (cardcount)
+ if (cardcount < 0) {
+ dgrs_unregister_eisa();
return cardcount;
+ }
return 0;
}static void __exit dgrs_cleanup_module (void)
{
-#ifdef CONFIG_EISA
- eisa_driver_unregister (&dgrs_eisa_driver);
-#endif
-#ifdef CONFIG_PCI
+ dgrs_unregister_eisa(); pci_unregister_driver (&dgrs_pci_driver);
-#endif
}
module_init(dgrs_init_module);
Quoted 18 lines · Richard Knutsson
What do you think about this patch? Will you sign it? It is no longer an error-warning-fix but a bug-fix (and some cleanup).
I "took" you implementation of dgrs_(un)register_eisa(), especially since eisa needed to be unregistered if pci succeeds (I take you word for it to be so).
(BTW, this patch is compiled withCONFIG_PCIset,CONFIG_EISAset and both set without errors/warnings for dgrs.o.)This patch requirer the "net-fix-compiler-error-on-dgrsc-when-config_pci.patch" (added to the -mm tree after 2.6.15-rc1-mm2):
---
devel/drivers/net/dgrs.c~net-fix-compiler-error-on-dgrsc-when-config_pci2005-11-19 18:00:34.000000000 -0800+++
devel-akpm/drivers/net/dgrs.c2005-11-19 18:00:34.000000000 -0800
Review static struct pci_driver dgrs_pci_driver · line 1463
Quoted 6 lines
(quoted diff) +2
-0@@ -1458,6 +1458,8 @@ static struct pci_driver dgrs_pci_driver .probe = dgrs_pci_probe, .remove = __devexit_p(dgrs_pci_remove), }; +#else +static struct pci_driver dgrs_pci_driver = {}; #endif
I don't see the point. We shouldn't have this structure at all if CONFIG_PCI is not set.
Cheers,
Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txtQuoted 22 lines · Herbert Xu
Quoted 7 lines · Richard Knutsson
This patch requirer the "net-fix-compiler-error-on-dgrsc-when-config_pci.patch" (added to the -mm tree after 2.6.15-rc1-mm2):
---
devel/drivers/net/dgrs.c~net-fix-compiler-error-on-dgrsc-when-config_pci 2005-11-19 18:00:34.000000000 -0800
+++devel-akpm/drivers/net/dgrs.c2005-11-19 18:00:34.000000000 -0800Review static struct pci_driver dgrs_pci_driver · line 1465
Quoted 8 lines
(quoted diff) +2
-0@@ -1458,6 +1458,8 @@ static struct pci_driver dgrs_pci_driver .probe = dgrs_pci_probe, .remove = __devexit_p(dgrs_pci_remove), }; +#else +static struct pci_driver dgrs_pci_driver = {}; #endifI don't see the point. We shouldn't have this structure at all if
CONFIG_PCIis not set.
Quoted 2 lines
Cheers,
We need it even if pci_register_driver() and pci_register_driver() is empty shells. And instead of removing #endif CONFIG_PCI for dgrs_pci_driver, which needs dgrs_pci_tbl, dgrs_pci_probe() and dgrs_pci_remove() (and so on), I added the empty dgrs_pci_driver-structure.
cu,
Quoted 3 lines · Richard Knutsson
We need it even if
pci_register_driver()andpci_register_driver()is empty shells. And instead of removing #endifCONFIG_PCIfor
I don't think so. Please see my previous patch where pci_register_driver is not called at all if CONFIG_PCI is not defined.
Cheers,
Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txtQuoted 13 lines · Herbert Xu
Quoted 3 lines · Richard Knutsson
We need it even if
pci_register_driver()andpci_register_driver()is empty shells. And instead of removing #endifCONFIG_PCIforI don't think so. Please see my previous patch where
pci_register_driveris not called at all ifCONFIG_PCIis not defined.Cheers,
Yes, I know you patch don't need it (thought you commented the patch vs. dgrs.c, not vs. you patch). But to do that, you have to introduce a new dgrs-specific pci-layer to compensate. If you don't want to have an empty struct, is it not nicer/easier to just #ifdef CONFIG_PCI the pci_*-functions? (instead of two inline functions for every used pci_*-function?)
Am thinking of removing the #ifdef CONFIG_PCI's in other files, to "clean up" the code, but that would introduce this problem again, don't you think it is more readable to make an empty struct when !CONFIG_PCI, then making new pci_*-functions specific to the driver?
cu
Quoted 5 lines · Richard Knutsson
Am thinking of removing the #ifdef CONFIG_PCI's in other files, to "clean up" the code, but that would introduce this problem again, don't you think it is more readable to make an empty struct when !CONFIG_PCI, then making new pci_*-functions specific to the driver?
I think my version is more readable. However, it's really up to Jeff to decide.
Cheers,
Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txtQuoted 22 lines · Herbert Xu
Quoted 7 lines · Richard Knutsson
This patch requirer the "net-fix-compiler-error-on-dgrsc-when-config_pci.patch" (added to the -mm tree after 2.6.15-rc1-mm2):
---
devel/drivers/net/dgrs.c~net-fix-compiler-error-on-dgrsc-when-config_pci 2005-11-19 18:00:34.000000000 -0800
+++devel-akpm/drivers/net/dgrs.c2005-11-19 18:00:34.000000000 -0800Review static struct pci_driver dgrs_pci_driver · line 1465
Quoted 8 lines
(quoted diff) +2
-0@@ -1458,6 +1458,8 @@ static struct pci_driver dgrs_pci_driver .probe = dgrs_pci_probe, .remove = __devexit_p(dgrs_pci_remove), }; +#else +static struct pci_driver dgrs_pci_driver = {}; #endifI don't see the point. We shouldn't have this structure at all if
CONFIG_PCIis not set.
Quoted 3 lines
Cheers,
Opps, misread your mail. Sorry.
But in that case, why shall we have any pci_*-function in the first place when !CONFIG_PCI? As it was before, they were contained within #ifdef CONFIG_PCI's.
You said your patch were easier to read, please elaborate. Yes, in the dgrs_init_module() (no arguments there), but you introduces new functions (who need to be checked out if you read the code for the first time) and is really #ifdef's a good idea to change function behavior? Isn't better to change the input? (I know, linux/pci.h does it, but at least that is in a .h-file with inline functions containing at most "return 0;").
Btw, you said Jeff should decide. Why not Rich Richardson who is the author?
Apologize for the ranting.
As I said before, thinking of deleting CONFIG_PCI's containing pci_*-functions and if so, need a valid plan for it (because of the pci_driver-struct). If there is any no-no in "my" way, please point it out to spare me/you/lkml the patches. If not for this, I would've let this rest and leave it to Jeff (or Rich ;) ).
cu,
Richard