Skip to content

Commit 7a192ec

Browse files
ming1gregkh
authored andcommitted
platform driver: fix incorrect use of 'platform_bus_type' with 'struct device_driver'
This patch fixes the bug reported in http://bugzilla.kernel.org/show_bug.cgi?id=11681. "Lots of device drivers register a 'struct device_driver' with the '.bus' member set to '&platform_bus_type'. This is wrong, since the platform_bus functions expect the 'struct device_driver' to be wrapped up in a 'struct platform_driver' which provides some additional callbacks (like suspend_late, resume_early). The effect may be that platform_suspend_late() uses bogus data outside the device_driver struct as a pointer pointer to the device driver's suspend_late() function or other hard to reproduce failures."(Lothar Wassmann) Signed-off-by: Ming Lei <tom.leiming@gmail.com> Acked-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br> Acked-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent 6da2d37 commit 7a192ec

21 files changed

Lines changed: 371 additions & 250 deletions

File tree

‎arch/mips/basler/excite/excite_iodev.c‎

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333

3434

3535
static const struct resource *iodev_get_resource(struct platform_device *, const char *, unsigned int);
36-
static int __init iodev_probe(struct device *);
37-
static int __exit iodev_remove(struct device *);
36+
static int __init iodev_probe(struct platform_device *);
37+
static int __exit iodev_remove(struct platform_device *);
3838
static int iodev_open(struct inode *, struct file *);
3939
static int iodev_release(struct inode *, struct file *);
4040
static ssize_t iodev_read(struct file *, char __user *, size_t s, loff_t *);
@@ -65,13 +65,13 @@ static struct miscdevice miscdev =
6565
.fops = &fops
6666
};
6767

68-
static struct device_driver iodev_driver =
69-
{
70-
.name = (char *) iodev_name,
71-
.bus = &platform_bus_type,
72-
.owner = THIS_MODULE,
68+
static struct platform_driver iodev_driver = {
69+
.driver = {
70+
.name = iodev_name,
71+
.owner = THIS_MODULE,
72+
},
7373
.probe = iodev_probe,
74-
.remove = __exit_p(iodev_remove)
74+
.remove = __devexit_p(iodev_remove),
7575
};
7676

7777

@@ -89,11 +89,10 @@ iodev_get_resource(struct platform_device *pdv, const char *name,
8989

9090

9191
/* No hotplugging on the platform bus - use __init */
92-
static int __init iodev_probe(struct device *dev)
92+
static int __init iodev_probe(struct platform_device *dev)
9393
{
94-
struct platform_device * const pdv = to_platform_device(dev);
9594
const struct resource * const ri =
96-
iodev_get_resource(pdv, IODEV_RESOURCE_IRQ, IORESOURCE_IRQ);
95+
iodev_get_resource(dev, IODEV_RESOURCE_IRQ, IORESOURCE_IRQ);
9796

9897
if (unlikely(!ri))
9998
return -ENXIO;
@@ -104,7 +103,7 @@ static int __init iodev_probe(struct device *dev)
104103

105104

106105

107-
static int __exit iodev_remove(struct device *dev)
106+
static int __exit iodev_remove(struct platform_device *dev)
108107
{
109108
return misc_deregister(&miscdev);
110109
}
@@ -160,14 +159,14 @@ static irqreturn_t iodev_irqhdl(int irq, void *ctxt)
160159

161160
static int __init iodev_init_module(void)
162161
{
163-
return driver_register(&iodev_driver);
162+
return platform_driver_register(&iodev_driver);
164163
}
165164

166165

167166

168167
static void __exit iodev_cleanup_module(void)
169168
{
170-
driver_unregister(&iodev_driver);
169+
platform_driver_unregister(&iodev_driver);
171170
}
172171

173172
module_init(iodev_init_module);

‎drivers/char/tpm/tpm_atmel.c‎

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,22 @@ static void atml_plat_remove(void)
168168
}
169169
}
170170

171-
static struct device_driver atml_drv = {
172-
.name = "tpm_atmel",
173-
.bus = &platform_bus_type,
174-
.owner = THIS_MODULE,
175-
.suspend = tpm_pm_suspend,
176-
.resume = tpm_pm_resume,
171+
static int tpm_atml_suspend(struct platform_device *dev, pm_message_t msg)
172+
{
173+
return tpm_pm_suspend(&dev->dev, msg);
174+
}
175+
176+
static int tpm_atml_resume(struct platform_device *dev)
177+
{
178+
return tpm_pm_resume(&dev->dev);
179+
}
180+
static struct platform_driver atml_drv = {
181+
.driver = {
182+
.name = "tpm_atmel",
183+
.owner = THIS_MODULE,
184+
},
185+
.suspend = tpm_atml_suspend,
186+
.resume = tpm_atml_resume,
177187
};
178188

179189
static int __init init_atmel(void)
@@ -184,7 +194,7 @@ static int __init init_atmel(void)
184194
unsigned long base;
185195
struct tpm_chip *chip;
186196

187-
rc = driver_register(&atml_drv);
197+
rc = platform_driver_register(&atml_drv);
188198
if (rc)
189199
return rc;
190200

@@ -223,13 +233,13 @@ static int __init init_atmel(void)
223233
atmel_release_region(base,
224234
region_size);
225235
err_unreg_drv:
226-
driver_unregister(&atml_drv);
236+
platform_driver_unregister(&atml_drv);
227237
return rc;
228238
}
229239

230240
static void __exit cleanup_atmel(void)
231241
{
232-
driver_unregister(&atml_drv);
242+
platform_driver_unregister(&atml_drv);
233243
atml_plat_remove();
234244
}
235245

‎drivers/char/tpm/tpm_tis.c‎

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -654,12 +654,22 @@ module_param_string(hid, tpm_pnp_tbl[TIS_HID_USR_IDX].id,
654654
sizeof(tpm_pnp_tbl[TIS_HID_USR_IDX].id), 0444);
655655
MODULE_PARM_DESC(hid, "Set additional specific HID for this driver to probe");
656656

657-
static struct device_driver tis_drv = {
658-
.name = "tpm_tis",
659-
.bus = &platform_bus_type,
660-
.owner = THIS_MODULE,
661-
.suspend = tpm_pm_suspend,
662-
.resume = tpm_pm_resume,
657+
static int tpm_tis_suspend(struct platform_device *dev, pm_message_t msg)
658+
{
659+
return tpm_pm_suspend(&dev->dev, msg);
660+
}
661+
662+
static int tpm_tis_resume(struct platform_device *dev)
663+
{
664+
return tpm_pm_resume(&dev->dev);
665+
}
666+
static struct platform_driver tis_drv = {
667+
.driver = {
668+
.name = "tpm_tis",
669+
.owner = THIS_MODULE,
670+
},
671+
.suspend = tpm_tis_suspend,
672+
.resume = tpm_tis_resume,
663673
};
664674

665675
static struct platform_device *pdev;
@@ -672,14 +682,14 @@ static int __init init_tis(void)
672682
int rc;
673683

674684
if (force) {
675-
rc = driver_register(&tis_drv);
685+
rc = platform_driver_register(&tis_drv);
676686
if (rc < 0)
677687
return rc;
678688
if (IS_ERR(pdev=platform_device_register_simple("tpm_tis", -1, NULL, 0)))
679689
return PTR_ERR(pdev);
680690
if((rc=tpm_tis_init(&pdev->dev, TIS_MEM_BASE, TIS_MEM_LEN, 0)) != 0) {
681691
platform_device_unregister(pdev);
682-
driver_unregister(&tis_drv);
692+
platform_driver_unregister(&tis_drv);
683693
}
684694
return rc;
685695
}
@@ -711,7 +721,7 @@ static void __exit cleanup_tis(void)
711721

712722
if (force) {
713723
platform_device_unregister(pdev);
714-
driver_unregister(&tis_drv);
724+
platform_driver_unregister(&tis_drv);
715725
} else
716726
pnp_unregister_driver(&tis_pnp_driver);
717727
}

‎drivers/ide/au1xxx-ide.c‎

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -536,9 +536,8 @@ static const struct ide_port_info au1xxx_port_info = {
536536
#endif
537537
};
538538

539-
static int au_ide_probe(struct device *dev)
539+
static int au_ide_probe(struct platform_device *dev)
540540
{
541-
struct platform_device *pdev = to_platform_device(dev);
542541
_auide_hwif *ahwif = &auide_hwif;
543542
struct resource *res;
544543
struct ide_host *host;
@@ -552,23 +551,23 @@ static int au_ide_probe(struct device *dev)
552551
#endif
553552

554553
memset(&auide_hwif, 0, sizeof(_auide_hwif));
555-
ahwif->irq = platform_get_irq(pdev, 0);
554+
ahwif->irq = platform_get_irq(dev, 0);
556555

557-
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
556+
res = platform_get_resource(dev, IORESOURCE_MEM, 0);
558557

559558
if (res == NULL) {
560-
pr_debug("%s %d: no base address\n", DRV_NAME, pdev->id);
559+
pr_debug("%s %d: no base address\n", DRV_NAME, dev->id);
561560
ret = -ENODEV;
562561
goto out;
563562
}
564563
if (ahwif->irq < 0) {
565-
pr_debug("%s %d: no IRQ\n", DRV_NAME, pdev->id);
564+
pr_debug("%s %d: no IRQ\n", DRV_NAME, dev->id);
566565
ret = -ENODEV;
567566
goto out;
568567
}
569568

570569
if (!request_mem_region(res->start, res->end - res->start + 1,
571-
pdev->name)) {
570+
dev->name)) {
572571
pr_debug("%s: request_mem_region failed\n", DRV_NAME);
573572
ret = -EBUSY;
574573
goto out;
@@ -583,7 +582,7 @@ static int au_ide_probe(struct device *dev)
583582
memset(&hw, 0, sizeof(hw));
584583
auide_setup_ports(&hw, ahwif);
585584
hw.irq = ahwif->irq;
586-
hw.dev = dev;
585+
hw.dev = &dev->dev;
587586
hw.chipset = ide_au1xxx;
588587

589588
ret = ide_host_add(&au1xxx_port_info, hws, &host);
@@ -592,46 +591,47 @@ static int au_ide_probe(struct device *dev)
592591

593592
auide_hwif.hwif = host->ports[0];
594593

595-
dev_set_drvdata(dev, host);
594+
platform_set_drvdata(dev, host);
596595

597596
printk(KERN_INFO "Au1xxx IDE(builtin) configured for %s\n", mode );
598597

599598
out:
600599
return ret;
601600
}
602601

603-
static int au_ide_remove(struct device *dev)
602+
static int au_ide_remove(struct platform_device *dev)
604603
{
605-
struct platform_device *pdev = to_platform_device(dev);
606604
struct resource *res;
607-
struct ide_host *host = dev_get_drvdata(dev);
605+
struct ide_host *host = platform_get_drvdata(dev);
608606
_auide_hwif *ahwif = &auide_hwif;
609607

610608
ide_host_remove(host);
611609

612610
iounmap((void *)ahwif->regbase);
613611

614-
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
612+
res = platform_get_resource(dev, IORESOURCE_MEM, 0);
615613
release_mem_region(res->start, res->end - res->start + 1);
616614

617615
return 0;
618616
}
619617

620-
static struct device_driver au1200_ide_driver = {
621-
.name = "au1200-ide",
622-
.bus = &platform_bus_type,
618+
static struct platform_driver au1200_ide_driver = {
619+
.driver = {
620+
.name = "au1200-ide",
621+
.owner = THIS_MODULE,
622+
},
623623
.probe = au_ide_probe,
624624
.remove = au_ide_remove,
625625
};
626626

627627
static int __init au_ide_init(void)
628628
{
629-
return driver_register(&au1200_ide_driver);
629+
return platform_driver_register(&au1200_ide_driver);
630630
}
631631

632632
static void __exit au_ide_exit(void)
633633
{
634-
driver_unregister(&au1200_ide_driver);
634+
platform_driver_unregister(&au1200_ide_driver);
635635
}
636636

637637
MODULE_LICENSE("GPL");

‎drivers/mtd/maps/pxa2xx-flash.c‎

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ struct pxa2xx_flash_info {
4141
static const char *probes[] = { "RedBoot", "cmdlinepart", NULL };
4242

4343

44-
static int __init pxa2xx_flash_probe(struct device *dev)
44+
static int __init pxa2xx_flash_probe(struct platform_device *pdev)
4545
{
46-
struct platform_device *pdev = to_platform_device(dev);
4746
struct flash_platform_data *flash = pdev->dev.platform_data;
4847
struct pxa2xx_flash_info *info;
4948
struct mtd_partition *parts;
@@ -114,15 +113,15 @@ static int __init pxa2xx_flash_probe(struct device *dev)
114113
add_mtd_device(info->mtd);
115114
}
116115

117-
dev_set_drvdata(dev, info);
116+
platform_set_drvdata(pdev, info);
118117
return 0;
119118
}
120119

121-
static int __exit pxa2xx_flash_remove(struct device *dev)
120+
static int __exit pxa2xx_flash_remove(struct platform_device *dev)
122121
{
123-
struct pxa2xx_flash_info *info = dev_get_drvdata(dev);
122+
struct pxa2xx_flash_info *info = platform_get_drvdata(dev);
124123

125-
dev_set_drvdata(dev, NULL);
124+
platform_set_drvdata(dev, NULL);
126125

127126
#ifdef CONFIG_MTD_PARTITIONS
128127
if (info->nr_parts)
@@ -141,27 +140,27 @@ static int __exit pxa2xx_flash_remove(struct device *dev)
141140
}
142141

143142
#ifdef CONFIG_PM
144-
static int pxa2xx_flash_suspend(struct device *dev, pm_message_t state)
143+
static int pxa2xx_flash_suspend(struct platform_device *dev, pm_message_t state)
145144
{
146-
struct pxa2xx_flash_info *info = dev_get_drvdata(dev);
145+
struct pxa2xx_flash_info *info = platform_get_drvdata(dev);
147146
int ret = 0;
148147

149148
if (info->mtd && info->mtd->suspend)
150149
ret = info->mtd->suspend(info->mtd);
151150
return ret;
152151
}
153152

154-
static int pxa2xx_flash_resume(struct device *dev)
153+
static int pxa2xx_flash_resume(struct platform_device *dev)
155154
{
156-
struct pxa2xx_flash_info *info = dev_get_drvdata(dev);
155+
struct pxa2xx_flash_info *info = platform_get_drvdata(dev);
157156

158157
if (info->mtd && info->mtd->resume)
159158
info->mtd->resume(info->mtd);
160159
return 0;
161160
}
162-
static void pxa2xx_flash_shutdown(struct device *dev)
161+
static void pxa2xx_flash_shutdown(struct platform_device *dev)
163162
{
164-
struct pxa2xx_flash_info *info = dev_get_drvdata(dev);
163+
struct pxa2xx_flash_info *info = platform_get_drvdata(dev);
165164

166165
if (info && info->mtd->suspend(info->mtd) == 0)
167166
info->mtd->resume(info->mtd);
@@ -172,24 +171,26 @@ static void pxa2xx_flash_shutdown(struct device *dev)
172171
#define pxa2xx_flash_shutdown NULL
173172
#endif
174173

175-
static struct device_driver pxa2xx_flash_driver = {
176-
.name = "pxa2xx-flash",
177-
.bus = &platform_bus_type,
174+
static struct platform_driver pxa2xx_flash_driver = {
175+
.driver = {
176+
.name = "pxa2xx-flash",
177+
.owner = THIS_MODULE,
178+
},
178179
.probe = pxa2xx_flash_probe,
179-
.remove = __exit_p(pxa2xx_flash_remove),
180+
.remove = __devexit_p(pxa2xx_flash_remove),
180181
.suspend = pxa2xx_flash_suspend,
181182
.resume = pxa2xx_flash_resume,
182183
.shutdown = pxa2xx_flash_shutdown,
183184
};
184185

185186
static int __init init_pxa2xx_flash(void)
186187
{
187-
return driver_register(&pxa2xx_flash_driver);
188+
return platform_driver_register(&pxa2xx_flash_driver);
188189
}
189190

190191
static void __exit cleanup_pxa2xx_flash(void)
191192
{
192-
driver_unregister(&pxa2xx_flash_driver);
193+
platform_driver_unregister(&pxa2xx_flash_driver);
193194
}
194195

195196
module_init(init_pxa2xx_flash);

0 commit comments

Comments
 (0)