IDE: Fix platform device registration in Swarm IDE driver
PATCH 1/1 IDE: Fix platform device registration in Swarm IDE driver
The Swarm IDE driver uses a release method which is defined in the driver itself thus potencially oopsable. The simpel fix would be to just leak the device but this patch goes the full length and moves the entire handling of the platform device in the platform code and retains only the platform driver code in drivers/ide/mips/swarm.c.
---
This patch is for 2.6.27. The same issue exists in -stable but the patch won't apply due to other driver changes.
arch/mips/sibyte/swarm/Makefile | 3 arch/mips/sibyte/swarm/platform.c | 60 ++++++++++++++++ drivers/ide/mips/swarm.c | 140 +++++++++++--------------------------- 3 files changed, 104 insertions(+), 99 deletions(-)
arch/mips/sibyte/swarm/platform.c new file +60 -0
@@ -0,0 +1,60 @@ +#include <linux/err.h> +#include <linux/kernel.h> +#include <linux/init.h> +#include <linux/io.h> +#include <linux/platform_device.h> + +#include <asm/sibyte/board.h> +#include <asm/sibyte/sb1250_genbus.h> +#include <asm/sibyte/sb1250_regs.h> + +#define DEV_NAME "ide-swarm" + +static struct resource swarm_ide_resource[] = { + { + .name ="Swarm GenBus IDE" , + .flags =IORESOURCE_MEM , + }, { + .name ="Swarm GenBus IDE" , + .flags =IORESOURCE_IRQ , + .start =K_INT_GB_IDE , + .end =K_INT_GB_IDE , + }, +}; + +static int __init swarm_ide_init (void ) +{ +struct platform_device *pdev; +u8 __iomem *base; +phys_t offset, size; + +if (!SIBYTE_HAVE_IDE ) +return -ENODEV ; + + base =ioremap (A_IO_EXT_BASE ,0x800 ); + offset =__raw_readq (base +R_IO_EXT_REG (R_IO_EXT_START_ADDR ,IDE_CS )); + size =__raw_readq (base +R_IO_EXT_REG (R_IO_EXT_MULT_SIZE ,IDE_CS )); +iounmap (base); + + offset =G_IO_START_ADDR (offset) <<S_IO_ADDRBASE ; + size = (G_IO_MULT_SIZE (size) +1 ) <<S_IO_REGSIZE ; +if (offset <A_PHYS_GENBUS || offset >=A_PHYS_GENBUS_END ) { +pr_info (DEV_NAME ": IDE interface at GenBus disabled\n" ); + +return -EBUSY ; + } + +pr_info (DEV_NAME ": IDE interface at GenBus slot %i\n" ,IDE_CS ); + + swarm_ide_resource[0 ].start = offset; + swarm_ide_resource[0 ].end = offset + size -1 ; + + pdev =platform_device_register_simple (DEV_NAME ,-1 , + swarm_ide_resource,ARRAY_SIZE (swarm_ide_resource)); +if (IS_ERR (pdev)) +return PTR_ERR (pdev); + +return 0 ; +} + +device_initcall (swarm_ide_init);
arch/mips/sibyte/swarm/Makefile +2 -1
@@ -1,3 +1,4 @@ -obj-y := setup.o rtc_xicor1241.o rtc_m41t81.o +obj-y := platform.o setup.o rtc_xicor1241.o \ + rtc_m41t81.o obj-$(CONFIG_I2C_BOARDINFO) += swarm-i2c.o
drivers/ide/mips/swarm.c +42 -98
189 lines not on this page · raw message
Hello.
Quoted 3 lines · Ralf Baechle
The Swarm IDE driver uses a release method which is defined in the driver itself thus potencially oopsable. The simpel fix would be to just leak
"Potentially" and "simple". :-P
Quoted 21 lines
the device but this patch goes the full length and moves the entire handling of the platform device in the platform code and retains only the platform driver code in
drivers/ide/mips/swarm.c.Signed-off-by Ralf Baechle <[email protected]>---
This patch is for 2.6.27. The same issue exists in -stable but the patch won't apply due to other driver changes.
arch/mips/sibyte/swarm/Makefile | 3 arch/mips/sibyte/swarm/platform.c | 60 ++++++++++++++++ drivers/ide/mips/swarm.c | 140 +++++++++++--------------------------- 3 files changed, 104 insertions(+), 99 deletions(-)Index:
linux-mips/arch/mips/sibyte/swarm/platform.c
===================================================================arch/mips/sibyte/swarm/platform.c new file +0
-0@@ -0,0 +1,60 @@
[...]
Quoted 15 lines
arch/mips/sibyte/swarm/platform.c new file +14
-0+static struct resource swarm_ide_resource[] = { + { + .name ="Swarm GenBus IDE" , + .flags =IORESOURCE_MEM , + }, { + .name ="Swarm GenBus IDE" , + .flags =IORESOURCE_IRQ , + .start =K_INT_GB_IDE , + .end =K_INT_GB_IDE , + }, +}; + +static int __init swarm_ide_init (void ) +{
[...]
arch/mips/sibyte/swarm/platform.c line 53
Quoted 3 lines
arch/mips/sibyte/swarm/platform.c new file +2
-0+ pdev =platform_device_register_simple (DEV_NAME ,-1 , + swarm_ide_resource,ARRAY_SIZE (swarm_ide_resource));
If you have the resources as static array anyway, why not have the
device in the static variable too and use platform_device_register()?
Quoted 13 lines
Index:
linux-mips/drivers/ide/mips/swarm.c
===================================================================drivers/ide/mips/swarm.c +0
-4@@ -46,21 +46,10 @@#include <asm/io.h> -#include <asm/sibyte/board.h> -#include <asm/sibyte/sb1250_genbus.h> -#include <asm/sibyte/sb1250_regs.h> -#define DRV_NAME "ide-swarm"
drivers/ide/mips/swarm.c line 53
Quoted 10 lines
drivers/ide/mips/swarm.c +0
-6static char swarm_ide_string[] =DRV_NAME ; -static struct resource swarm_ide_resource = { - .name ="SWARM GenBus IDE" , - .flags =IORESOURCE_MEM , -}; - -static struct platform_device *swarm_ide_dev;
Platform device in the driver itself? Interesting... :-)
Quoted 27 lines
drivers/ide/mips/swarm.c +2
-14@@ -70,41 +59,18 @@ static const struct ide_port_info swarm_* swarm_ide_probe - if the board header indicates the existence of * Generic Bus IDE, allocate a HWIF for it. */ -static int __devinit swarm_ide_probe (struct device *dev) +static int __devinit swarm_ide_probe (struct platform_device *pdev) {u8 __iomem *base;struct ide_host *host;phys_t offset, size; +struct resource *r;int i, rc;hw_regs_t hw, *hws[] = { &hw,NULL ,NULL ,NULL }; -if (!SIBYTE_HAVE_IDE ) -return -ENODEV ; - - base =ioremap (A_IO_EXT_BASE ,0x800 ); - offset =__raw_readq (base +R_IO_EXT_REG (R_IO_EXT_START_ADDR ,IDE_CS )); - size =__raw_readq (base +R_IO_EXT_REG (R_IO_EXT_MULT_SIZE ,IDE_CS )); -iounmap (base); - - offset =G_IO_START_ADDR (offset) <<S_IO_ADDRBASE ; - size = (G_IO_MULT_SIZE (size) +1 ) <<S_IO_REGSIZE ; -if (offset <A_PHYS_GENBUS || offset >=A_PHYS_GENBUS_END ) { - printk(KERN_INFO DRV_NAME - ": IDE interface at GenBus disabled\n");
drivers/ide/mips/swarm.c static const struct ide_port_info swarm_ · line 71
Quoted 10 lines
drivers/ide/mips/swarm.c +0
-9-return -EBUSY ; - } - - printk(KERN_INFO DRV_NAME ": IDE interface at GenBus slot %i\n", - IDE_CS); - - swarm_ide_resource.start = offset; - swarm_ide_resource.end = offset + size -1 ; -if (request_resource (&iomem_resource, &swarm_ide_resource)) {
Why drop request_resource() completely? Replace it byrequest_mem_region().
MBR, Sergei
Quoted 1 line · Sergei Shtylyov
Platform device in the driver itself? Interesting... :-)
Better than nothing for platforms which did not have platform
initialisation at all. Some driver subsystems do not support non-driver-model devices at all or anymore.
Maciej
Quoted 5 lines · Maciej W. Rozycki
Quoted 1 line
Platform device in the driver itself? Interesting... :-)
Better than nothing for platforms which did not have platform
initialisation at all. Some driver subsystems do not support non-driver-model devices at all or anymore.
Historically registration of the device file in the driver itself wasn't uncommon before it turned out to be not such a great idea. I hope this was the last of the affected MIPS-specific drivers.
Ralf
On Wednesday 24 September 2008, Sergei Shtylyov wrote:
[...]
Quoted 32 lines
Quoted 32 lines
drivers/ide/mips/swarm.c +2
-19@@ -70,41 +59,18 @@ static const struct ide_port_info swarm_* swarm_ide_probe - if the board header indicates the existence of * Generic Bus IDE, allocate a HWIF for it. */ -static int __devinit swarm_ide_probe (struct device *dev) +static int __devinit swarm_ide_probe (struct platform_device *pdev) {u8 __iomem *base;struct ide_host *host;phys_t offset, size; +struct resource *r;int i, rc;hw_regs_t hw, *hws[] = { &hw,NULL ,NULL ,NULL }; -if (!SIBYTE_HAVE_IDE ) -return -ENODEV ; - - base =ioremap (A_IO_EXT_BASE ,0x800 ); - offset =__raw_readq (base +R_IO_EXT_REG (R_IO_EXT_START_ADDR ,IDE_CS )); - size =__raw_readq (base +R_IO_EXT_REG (R_IO_EXT_MULT_SIZE ,IDE_CS )); -iounmap (base); - - offset =G_IO_START_ADDR (offset) <<S_IO_ADDRBASE ; - size = (G_IO_MULT_SIZE (size) +1 ) <<S_IO_REGSIZE ; -if (offset <A_PHYS_GENBUS || offset >=A_PHYS_GENBUS_END ) { - printk(KERN_INFO DRV_NAME - ": IDE interface at GenBus disabled\n"); -return -EBUSY ; - } - - printk(KERN_INFO DRV_NAME ": IDE interface at GenBus slot %i\n", - IDE_CS);
Quoted 8 lines
drivers/ide/mips/swarm.c static const struct ide_port_info swarm_ · line 75
Quoted 5 lines
drivers/ide/mips/swarm.c +0
-4- - swarm_ide_resource.start = offset; - swarm_ide_resource.end = offset + size -1 ; -if (request_resource (&iomem_resource, &swarm_ide_resource)) {Why drop
request_resource()completely? Replace it byrequest_mem_region().
Yes, this needs fixing (otherwise everything looks good).
Ralf: I guess that your next step will be dropping swarm-specific platform ide driver in favor of generic one (please see drivers/ide/legacy/ide_platform.c) as they are _very_ similar now? :)
Thanks,
Bart
Hello.
Quoted 42 lines · Bartlomiej Zolnierkiewicz
Quoted 32 lines
Quoted 32 lines
drivers/ide/mips/swarm.c +2
-19@@ -70,41 +59,18 @@ static const struct ide_port_info swarm_* swarm_ide_probe - if the board header indicates the existence of * Generic Bus IDE, allocate a HWIF for it. */ -static int __devinit swarm_ide_probe (struct device *dev) +static int __devinit swarm_ide_probe (struct platform_device *pdev) {u8 __iomem *base;struct ide_host *host;phys_t offset, size; +struct resource *r;int i, rc;hw_regs_t hw, *hws[] = { &hw,NULL ,NULL ,NULL }; -if (!SIBYTE_HAVE_IDE ) -return -ENODEV ; - - base =ioremap (A_IO_EXT_BASE ,0x800 ); - offset =__raw_readq (base +R_IO_EXT_REG (R_IO_EXT_START_ADDR ,IDE_CS )); - size =__raw_readq (base +R_IO_EXT_REG (R_IO_EXT_MULT_SIZE ,IDE_CS )); -iounmap (base); - - offset =G_IO_START_ADDR (offset) <<S_IO_ADDRBASE ; - size = (G_IO_MULT_SIZE (size) +1 ) <<S_IO_REGSIZE ; -if (offset <A_PHYS_GENBUS || offset >=A_PHYS_GENBUS_END ) { - printk(KERN_INFO DRV_NAME - ": IDE interface at GenBus disabled\n"); -return -EBUSY ; - } - - printk(KERN_INFO DRV_NAME ": IDE interface at GenBus slot %i\n", - IDE_CS);Quoted 9 lines
drivers/ide/mips/swarm.c static const struct ide_port_info swarm_
Quoted 6 lines
drivers/ide/mips/swarm.c +0
-4- - swarm_ide_resource.start = offset; - swarm_ide_resource.end = offset + size -1 ; -if (request_resource (&iomem_resource, &swarm_ide_resource)) {Why drop
request_resource()completely? Replace it byrequest_mem_region().
Quoted 2 lines
Yes, this needs fixing (otherwise everything looks good).
BTW, calling request_resource() seems pointless, asplatform_device_register() call will have called __request_resource() already...
WBR, Sergei
Quoted 9 lines · Bartlomiej Zolnierkiewicz
Quoted 7 lines
drivers/ide/mips/swarm.c static const struct ide_port_info swarm_ · line 102
Quoted 4 lines
drivers/ide/mips/swarm.c +0
-3- swarm_ide_resource.start = offset; - swarm_ide_resource.end = offset + size -1 ; -if (request_resource (&iomem_resource, &swarm_ide_resource)) {Why drop
request_resource()completely? Replace it byrequest_mem_region().Yes, this needs fixing (otherwise everything looks good).
No, platform_device_add which is called by platform_device_register* will take care of adding the resources - but only if if's told about them which the old driver didn't.
Also, in case of a resource conflict a device should not be added at all but exactly that is what the old code did. A resource conflict would have been caught by the platform_driver probing code well too late.
Quoted 3 lines
Ralf: I guess that your next step will be dropping swarm-specific platform ide driver in favor of generic one (please see
drivers/ide/legacy/ide_platform.c) as they are _very_ similar now? :)
Good point - I was already wondering if something like that does exist. What's left over of the swarm driver way too much looks like it can be squeezed into some sort of template.
Ralf
Hello.
Quoted 7 lines · Ralf Baechle
Quoted 6 lines
Quoted 6 lines
drivers/ide/mips/swarm.c static const struct ide_port_info swarm_ · line 102
Quoted 3 lines
drivers/ide/mips/swarm.c +0
-3- swarm_ide_resource.start = offset; - swarm_ide_resource.end = offset + size -1 ; -if (request_resource (&iomem_resource, &swarm_ide_resource)) {Why drop
request_resource()completely? Replace it byrequest_mem_region().
Quoted 5 lines
Quoted 1 line
Yes, this needs fixing (otherwise everything looks good).
No,
platform_device_addwhich is called by platform_device_register* will take care of adding the resources - but only if if's told about them which the old driver didn't.
Ah, I've missed that the platform device was registered without resources
(ugh) -- request_resource() call wasn't pointless then. Note however that request_mem_region() does somewhat different thing: it pins the memory resource for the driver, setting IORESOURCE_BUSY flag on the resource (and it also walks the resource tree in depth, using __request_resource() on each level. That's the thing that drivers do routinely on intialization.
Quoted 1 line
Ralf
MBR, Sergei
PATCH v2 1/1 IDE: Fix platform device registration in Swarm IDE driver
In reply to Ralf BaechleThe Swarm IDE driver uses a release method which is defined in the driver itself thus potentially oopsable. The simple fix would be to just leak the device but this patch goes the full length and moves the entire handling of the platform device in the platform code and retains only the platform driver code in drivers/ide/mips/swarm.c.
---
This patch is for 2.6.27. The same issue exists in -stable but the patch won't apply due to other driver changes.
Changes: v2 rewritten to use pata_platform, as suggested.
arch/mips/sibyte/swarm/Makefile | 3 arch/mips/sibyte/swarm/platform.c | 81 +++++++++++++++ drivers/ide/mips/Makefile | 1 drivers/ide/mips/swarm.c | 197 -------------------------------------- 4 files changed, 83 insertions(+), 199 deletions(-)
arch/mips/sibyte/swarm/platform.c new file +81 -0
@@ -0,0 +1,81 @@ +#include <linux/err.h> +#include <linux/kernel.h> +#include <linux/init.h> +#include <linux/io.h> +#include <linux/platform_device.h> +#include <linux/ata_platform.h> + +#include <asm/sibyte/board.h> +#include <asm/sibyte/sb1250_genbus.h> +#include <asm/sibyte/sb1250_regs.h> + +#define DRV_NAME "pata-swarm" + +#define SWARM_IDE_SHIFT 5 +#define SWARM_IDE_BASE 0x1f0 +#define SWARM_IDE_CTRL 0x3f6 + +static struct resource swarm_pata_resource[] = { + { + .name ="Swarm GenBus IDE" , + .flags =IORESOURCE_MEM , + }, { + .name ="Swarm GenBus IDE" , + .flags =IORESOURCE_MEM , + }, { + .name ="Swarm GenBus IDE" , + .flags =IORESOURCE_IRQ , + .start =K_INT_GB_IDE , + .end =K_INT_GB_IDE , + }, +}; + +static struct pata_platform_info pata_platform_data = { + .ioport_shift =SWARM_IDE_SHIFT , +}; + +static struct platform_device swarm_pata_device = { + .name ="pata_platform" , + .id =-1 , + .resource = swarm_pata_resource, + .num_resources =ARRAY_SIZE (swarm_pata_resource), + .dev = { + .platform_data = &pata_platform_data, + .coherent_dma_mask = ~0 ,/* grumble */ + }, +}; + +static int __init swarm_pata_init (void ) +{ +u8 __iomem *base; +phys_t offset, size; +struct resource *r; + +if (!SIBYTE_HAVE_IDE ) +return -ENODEV ; + + base =ioremap (A_IO_EXT_BASE ,0x800 ); + offset =__raw_readq (base +R_IO_EXT_REG (R_IO_EXT_START_ADDR ,IDE_CS )); + size =__raw_readq (base +R_IO_EXT_REG (R_IO_EXT_MULT_SIZE ,IDE_CS )); +iounmap (base); + + offset =G_IO_START_ADDR (offset) <<S_IO_ADDRBASE ; + size = (G_IO_MULT_SIZE (size) +1 ) <<S_IO_REGSIZE ; +if (offset <A_PHYS_GENBUS || offset >=A_PHYS_GENBUS_END ) { +pr_info (DRV_NAME ": PATA interface at GenBus disabled\n" ); + +return -EBUSY ; + } + +pr_info (DRV_NAME ": PATA interface at GenBus slot %i\n" ,IDE_CS ); + + r = swarm_pata_resource; + r[0 ].start = offset + (SWARM_IDE_BASE <<SWARM_IDE_SHIFT ); + r[0 ].end = offset + ((SWARM_IDE_BASE +8 ) <<SWARM_IDE_SHIFT ) -1 ; + r[1 ].start = offset + (SWARM_IDE_CTRL <<SWARM_IDE_SHIFT ); + r[1 ].end = offset + ((SWARM_IDE_CTRL +1 ) <<SWARM_IDE_SHIFT ) -1 ; + +return platform_device_register (&swarm_pata_device); +} + +device_initcall (swarm_pata_init);
arch/mips/sibyte/swarm/Makefile +2 -1
@@ -1,3 +1,4 @@ -obj-y := setup.o rtc_xicor1241.o rtc_m41t81.o +obj-y := platform.o setup.o rtc_xicor1241.o \ + rtc_m41t81.o obj-$(CONFIG_I2C_BOARDINFO) += swarm-i2c.o
drivers/ide/mips/swarm.c deleted +0 -197
197 lines not on this page · raw message
drivers/ide/mips/Makefile +0 -1
@@ -1,4 +1,3 @@ -obj-$(CONFIG_BLK_DEV_IDE_SWARM) += swarm.o obj-$(CONFIG_BLK_DEV_IDE_AU1XXX) += au1xxx-ide.o EXTRA_CFLAGS := -Idrivers/ide
Hello.
Quoted 8 lines · Ralf Baechle
The Swarm IDE driver uses a release method which is defined in the driver itself thus potentially oopsable. The simple fix would be to just leak the device but this patch goes the full length and moves the entire handling of the platform device in the platform code and retains only the platform driver code in
drivers/ide/mips/swarm.c.Signed-off-by Ralf Baechle <[email protected]>
Quoted 8 lines
Index:
linux-mips/arch/mips/sibyte/swarm/platform.c
===================================================================arch/mips/sibyte/swarm/platform.c new file +2
-0@@ -0,0 +1,81 @@ +#include <linux/err.h> +#include <linux/kernel.h>
arch/mips/sibyte/swarm/platform.c line 12
Quoted 10 lines
arch/mips/sibyte/swarm/platform.c new file +10
-0+#include <linux/init.h> +#include <linux/io.h> +#include <linux/platform_device.h> +#include <linux/ata_platform.h> + +#include <asm/sibyte/board.h> +#include <asm/sibyte/sb1250_genbus.h> +#include <asm/sibyte/sb1250_regs.h> + +#define DRV_NAME "pata-swarm"
Hm, what driver? This is just a platform code. :-)
Quoted 8 lines
arch/mips/sibyte/swarm/platform.c new file +7
-0+ +#define SWARM_IDE_SHIFT 5 +#define SWARM_IDE_BASE 0x1f0 +#define SWARM_IDE_CTRL 0x3f6 + +static struct resource swarm_pata_resource[] = { + {
arch/mips/sibyte/swarm/platform.c line 29
Quoted 10 lines
arch/mips/sibyte/swarm/platform.c new file +10
-0+ .name = "Swarm GenBus IDE", + .flags = IORESOURCE_MEM, + }, { + .name = "Swarm GenBus IDE", + .flags = IORESOURCE_MEM, + }, { + .name = "Swarm GenBus IDE", + .flags = IORESOURCE_IRQ, + .start = K_INT_GB_IDE, + .end = K_INT_GB_IDE,
Giving the resources similar names is pointless. You can just leave
the 'name' field uninitialized.
MBR, Sergei
Quoted 7 lines · Sergei Shtylyov
Quoted 7 lines
arch/mips/sibyte/swarm/platform.c new file +7
-0+ { + .name = "Swarm GenBus IDE", + .flags = IORESOURCE_MEM, + }, { + .name = "Swarm GenBus IDE", + .flags = IORESOURCE_MEM, + }, {
Quoted 8 lines
arch/mips/sibyte/swarm/platform.c line 29
Quoted 5 lines
arch/mips/sibyte/swarm/platform.c new file +4
-0+ .name = "Swarm GenBus IDE", + .flags = IORESOURCE_IRQ, + .start = K_INT_GB_IDE, + .end = K_INT_GB_IDE,Giving the resources similar names is pointless. You can just leave
the 'name' field uninitialized.
I could - but I prefer things to have reasonable names in /proc/iomem or wherever. Unfortunately the IRQ resources name isn't yet being used to for the interrupt but there's always something left to do :)
Ralf
Quoted 10 lines · Hello, I wrote:
Quoted 8 lines
The Swarm IDE driver uses a release method which is defined in the driver itself thus potentially oopsable. The simple fix would be to just leak the device but this patch goes the full length and moves the entire handling of the platform device in the platform code and retains only the platform driver code in
drivers/ide/mips/swarm.c.Signed-off-by Ralf Baechle <[email protected]>Acked-by Sergei Shtylyov <[email protected]>
Perhaps worth splitting into arch/mips/ and the follow-updrivers/ide/ patches though...
MBR, Sergei
Bartlomiej Zolnierkiewicz
AppliedQuoted 11 lines · Sergei Shtylyov
Hello.
Quoted 7 lines · Ralf Baechle
The Swarm IDE driver uses a release method which is defined in the driver itself thus potentially oopsable. The simple fix would be to just leak the device but this patch goes the full length and moves the entire handling of the platform device in the platform code and retains only the platform driver code in
drivers/ide/mips/swarm.c.Signed-off-by Ralf Baechle <[email protected]>
wow, v2 happened really quickly :)
Quoted 1 line
Acked-by Sergei Shtylyov <[email protected]>
applied
[ I removed no longer needed BLK_DEV_IDE_SWARM from ide/Kconfig while at it ]
Quoted 9 lines · Bartlomiej Zolnierkiewicz
Quoted 7 lines
Quoted 7 lines
The Swarm IDE driver uses a release method which is defined in the driver itself thus potentially oopsable. The simple fix would be to just leak the device but this patch goes the full length and moves the entire handling of the platform device in the platform code and retains only the platform driver code in
drivers/ide/mips/swarm.c.Signed-off-by Ralf Baechle <[email protected]>wow, v2 happened really quickly :)
It not just tidying up, it fixing a potencial crash so had to happen quickly to (hopefully) make the release ...
Quoted 1 line
[ I removed no longer needed
BLK_DEV_IDE_SWARMfrom ide/Kconfig while at it ]
Thanks!
Ralf
Quoted 9 lines · Sergei Shtylyov
Quoted 2 lines
+{
[...]
arch/mips/sibyte/swarm/platform.c line 53
Quoted 3 lines
arch/mips/sibyte/swarm/platform.c new file +2
-0+ pdev =platform_device_register_simple (DEV_NAME ,-1 , + swarm_ide_resource,ARRAY_SIZE (swarm_ide_resource));If you have the resources as static array anyway, why not have the
device in the static variable too and useplatform_device_register()?
It saves a few lines of code.
Quoted 4 lines
Quoted 2 lines
-static struct
platform_device*swarm_ide_dev;Platform device in the driver itself? Interesting... :-)
It works and isn't a too bad idea for certain drivers where adding one half of the code to a platform file, another to the driver file is just too much fuzz. It's just that this wasn't done right in case of the Swarm so I'm gluing that now.
Ralf
Hello.
Quoted 11 lines · Ralf Baechle
Quoted 9 lines
Quoted 1 line
+{
[...]
arch/mips/sibyte/swarm/platform.c line 53
Quoted 2 lines
arch/mips/sibyte/swarm/platform.c new file +2
-0+ pdev =platform_device_register_simple (DEV_NAME ,-1 , + swarm_ide_resource,ARRAY_SIZE (swarm_ide_resource));If you have the resources as static array anyway, why not have the
device in the static variable too and useplatform_device_register()?It saves a few lines of code.
And wastes few words of static data sinceplatform_device_register_simple() will kmalloc() the resources and do a copy from these resources after which they are not needed -- so, it's worth making swarm_ide_resource[] __initdata at least.
If you were using platform_device_register() with static platform device,
no memory allocation would have happened, and no data would have been wasted.
WBR, Sergei
Quoted 12 lines · Sergei Shtylyov
Quoted 9 lines · Ralf Baechle
Quoted 9 lines
Quoted 1 line
+{
[...]
arch/mips/sibyte/swarm/platform.c line 53
Quoted 2 lines
arch/mips/sibyte/swarm/platform.c new file +2
-0+ pdev =platform_device_register_simple (DEV_NAME ,-1 , + swarm_ide_resource,ARRAY_SIZE (swarm_ide_resource));If you have the resources as static array anyway, why not have the
device in the static variable too and useplatform_device_register()?
Quoted 8 lines
Quoted 1 line
It saves a few lines of code.
And wastes few words of static data since
platform_device_register_simple()
willkmalloc()the resources and do a copy from these resources after which they are not needed -- so, it's worth making swarm_ide_resource[]__initdataat least.
If you were usingplatform_device_register()with static platform device,
no memory allocation would have happened, and no data would have been wasted.
Indeed, there are different static/dynamic memory usage patterns for the various ways to register platform devices. Unfortunately (AFAIK) it's not properly documented which to use when.
E.g. if some devices may be present (as indicated by e.g. firmware), which one is the most optimal to use?
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds