Skip to content

Commit b1608d6

Browse files
committed
drivercore: revert addition of of_match to struct device
Commit b826291, "drivercore/dt: add a match table pointer to struct device" added an of_match pointer to struct device to cache the of_match_table entry discovered at driver match time. This was unsafe because matching is not an atomic operation with probing a driver. If two or more drivers are attempted to be matched to a driver at the same time, then the cached matching entry pointer could get overwritten. This patch reverts the of_match cache pointer and reworks all users to call of_match_device() directly instead. Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
1 parent 01294d8 commit b1608d6

22 files changed

Lines changed: 108 additions & 50 deletions

File tree

‎arch/powerpc/platforms/83xx/suspend.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,17 +318,20 @@ static const struct platform_suspend_ops mpc83xx_suspend_ops = {
318318
.end = mpc83xx_suspend_end,
319319
};
320320

321+
static struct of_device_id pmc_match[];
321322
static int pmc_probe(struct platform_device *ofdev)
322323
{
324+
const struct of_device_id *match;
323325
struct device_node *np = ofdev->dev.of_node;
324326
struct resource res;
325327
struct pmc_type *type;
326328
int ret = 0;
327329

328-
if (!ofdev->dev.of_match)
330+
match = of_match_device(pmc_match, &ofdev->dev);
331+
if (!match)
329332
return -EINVAL;
330333

331-
type = ofdev->dev.of_match->data;
334+
type = match->data;
332335

333336
if (!of_device_is_available(np))
334337
return -ENODEV;

‎arch/powerpc/sysdev/fsl_msi.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,10 @@ static int __devinit fsl_msi_setup_hwirq(struct fsl_msi *msi,
304304
return 0;
305305
}
306306

307+
static const struct of_device_id fsl_of_msi_ids[];
307308
static int __devinit fsl_of_msi_probe(struct platform_device *dev)
308309
{
310+
const struct of_device_id *match;
309311
struct fsl_msi *msi;
310312
struct resource res;
311313
int err, i, j, irq_index, count;
@@ -316,9 +318,10 @@ static int __devinit fsl_of_msi_probe(struct platform_device *dev)
316318
u32 offset;
317319
static const u32 all_avail[] = { 0, NR_MSI_IRQS };
318320

319-
if (!dev->dev.of_match)
321+
match = of_match_device(fsl_of_msi_ids, &dev->dev);
322+
if (!match)
320323
return -EINVAL;
321-
features = dev->dev.of_match->data;
324+
features = match->data;
322325

323326
printk(KERN_DEBUG "Setting up Freescale MSI support\n");
324327

‎arch/sparc/kernel/pci_sabre.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,10 @@ static void __devinit sabre_pbm_init(struct pci_pbm_info *pbm,
452452
sabre_scan_bus(pbm, &op->dev);
453453
}
454454

455+
static const struct of_device_id sabre_match[];
455456
static int __devinit sabre_probe(struct platform_device *op)
456457
{
458+
const struct of_device_id *match;
457459
const struct linux_prom64_registers *pr_regs;
458460
struct device_node *dp = op->dev.of_node;
459461
struct pci_pbm_info *pbm;
@@ -463,7 +465,8 @@ static int __devinit sabre_probe(struct platform_device *op)
463465
const u32 *vdma;
464466
u64 clear_irq;
465467

466-
hummingbird_p = op->dev.of_match && (op->dev.of_match->data != NULL);
468+
match = of_match_device(sabre_match, &op->dev);
469+
hummingbird_p = match && (match->data != NULL);
467470
if (!hummingbird_p) {
468471
struct device_node *cpu_dp;
469472

‎arch/sparc/kernel/pci_schizo.c‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,11 +1458,15 @@ static int __devinit __schizo_init(struct platform_device *op, unsigned long chi
14581458
return err;
14591459
}
14601460

1461+
static const struct of_device_id schizo_match[];
14611462
static int __devinit schizo_probe(struct platform_device *op)
14621463
{
1463-
if (!op->dev.of_match)
1464+
const struct of_device_id *match;
1465+
1466+
match = of_match_device(schizo_match, &op->dev);
1467+
if (!match)
14641468
return -EINVAL;
1465-
return __schizo_init(op, (unsigned long) op->dev.of_match->data);
1469+
return __schizo_init(op, (unsigned long)match->data);
14661470
}
14671471

14681472
/* The ordering of this table is very important. Some Tomatillo

‎drivers/atm/fore200e.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2643,16 +2643,19 @@ fore200e_init(struct fore200e* fore200e, struct device *parent)
26432643
}
26442644

26452645
#ifdef CONFIG_SBUS
2646+
static const struct of_device_id fore200e_sba_match[];
26462647
static int __devinit fore200e_sba_probe(struct platform_device *op)
26472648
{
2649+
const struct of_device_id *match;
26482650
const struct fore200e_bus *bus;
26492651
struct fore200e *fore200e;
26502652
static int index = 0;
26512653
int err;
26522654

2653-
if (!op->dev.of_match)
2655+
match = of_match_device(fore200e_sba_match, &op->dev);
2656+
if (!match)
26542657
return -EINVAL;
2655-
bus = op->dev.of_match->data;
2658+
bus = match->data;
26562659

26572660
fore200e = kzalloc(sizeof(struct fore200e), GFP_KERNEL);
26582661
if (!fore200e)

‎drivers/char/hw_random/n2-drv.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -619,15 +619,18 @@ static void __devinit n2rng_driver_version(void)
619619
pr_info("%s", version);
620620
}
621621

622+
static const struct of_device_id n2rng_match[];
622623
static int __devinit n2rng_probe(struct platform_device *op)
623624
{
625+
const struct of_device_id *match;
624626
int victoria_falls;
625627
int err = -ENOMEM;
626628
struct n2rng *np;
627629

628-
if (!op->dev.of_match)
630+
match = of_match_device(n2rng_match, &op->dev);
631+
if (!match)
629632
return -EINVAL;
630-
victoria_falls = (op->dev.of_match->data != NULL);
633+
victoria_falls = (match->data != NULL);
631634

632635
n2rng_driver_version();
633636
np = kzalloc(sizeof(*np), GFP_KERNEL);

‎drivers/char/ipmi/ipmi_si_intf.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2554,9 +2554,11 @@ static struct pci_driver ipmi_pci_driver = {
25542554
};
25552555
#endif /* CONFIG_PCI */
25562556

2557+
static struct of_device_id ipmi_match[];
25572558
static int __devinit ipmi_probe(struct platform_device *dev)
25582559
{
25592560
#ifdef CONFIG_OF
2561+
const struct of_device_id *match;
25602562
struct smi_info *info;
25612563
struct resource resource;
25622564
const __be32 *regsize, *regspacing, *regshift;
@@ -2566,7 +2568,8 @@ static int __devinit ipmi_probe(struct platform_device *dev)
25662568

25672569
dev_info(&dev->dev, "probing via device tree\n");
25682570

2569-
if (!dev->dev.of_match)
2571+
match = of_match_device(ipmi_match, &dev->dev);
2572+
if (!match)
25702573
return -EINVAL;
25712574

25722575
ret = of_address_to_resource(np, 0, &resource);
@@ -2601,7 +2604,7 @@ static int __devinit ipmi_probe(struct platform_device *dev)
26012604
return -ENOMEM;
26022605
}
26032606

2604-
info->si_type = (enum si_type) dev->dev.of_match->data;
2607+
info->si_type = (enum si_type) match->data;
26052608
info->addr_source = SI_DEVICETREE;
26062609
info->irq_setup = std_irq_setup;
26072610

‎drivers/char/xilinx_hwicap/xilinx_hwicap.c‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -715,13 +715,13 @@ static int __devexit hwicap_remove(struct device *dev)
715715
}
716716

717717
#ifdef CONFIG_OF
718-
static int __devinit hwicap_of_probe(struct platform_device *op)
718+
static int __devinit hwicap_of_probe(struct platform_device *op,
719+
const struct hwicap_driver_config *config)
719720
{
720721
struct resource res;
721722
const unsigned int *id;
722723
const char *family;
723724
int rc;
724-
const struct hwicap_driver_config *config = op->dev.of_match->data;
725725
const struct config_registers *regs;
726726

727727

@@ -751,20 +751,24 @@ static int __devinit hwicap_of_probe(struct platform_device *op)
751751
regs);
752752
}
753753
#else
754-
static inline int hwicap_of_probe(struct platform_device *op)
754+
static inline int hwicap_of_probe(struct platform_device *op,
755+
const struct hwicap_driver_config *config)
755756
{
756757
return -EINVAL;
757758
}
758759
#endif /* CONFIG_OF */
759760

761+
static const struct of_device_id __devinitconst hwicap_of_match[];
760762
static int __devinit hwicap_drv_probe(struct platform_device *pdev)
761763
{
764+
const struct of_device_id *match;
762765
struct resource *res;
763766
const struct config_registers *regs;
764767
const char *family;
765768

766-
if (pdev->dev.of_match)
767-
return hwicap_of_probe(pdev);
769+
match = of_match_device(hwicap_of_match, &pdev->dev);
770+
if (match)
771+
return hwicap_of_probe(pdev, match->data);
768772

769773
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
770774
if (!res)

‎drivers/edac/ppc4xx_edac.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,7 @@ ppc4xx_edac_mc_init(struct mem_ctl_info *mci,
10191019
struct ppc4xx_edac_pdata *pdata = NULL;
10201020
const struct device_node *np = op->dev.of_node;
10211021

1022-
if (op->dev.of_match == NULL)
1022+
if (of_match_device(ppc4xx_edac_match, &op->dev) == NULL)
10231023
return -EINVAL;
10241024

10251025
/* Initial driver pointers and private data */

‎drivers/i2c/busses/i2c-mpc.c‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -560,15 +560,18 @@ static struct i2c_adapter mpc_ops = {
560560
.timeout = HZ,
561561
};
562562

563+
static const struct of_device_id mpc_i2c_of_match[];
563564
static int __devinit fsl_i2c_probe(struct platform_device *op)
564565
{
566+
const struct of_device_id *match;
565567
struct mpc_i2c *i2c;
566568
const u32 *prop;
567569
u32 clock = MPC_I2C_CLOCK_LEGACY;
568570
int result = 0;
569571
int plen;
570572

571-
if (!op->dev.of_match)
573+
match = of_match_device(mpc_i2c_of_match, &op->dev);
574+
if (!match)
572575
return -EINVAL;
573576

574577
i2c = kzalloc(sizeof(*i2c), GFP_KERNEL);
@@ -605,8 +608,8 @@ static int __devinit fsl_i2c_probe(struct platform_device *op)
605608
clock = *prop;
606609
}
607610

608-
if (op->dev.of_match->data) {
609-
struct mpc_i2c_data *data = op->dev.of_match->data;
611+
if (match->data) {
612+
struct mpc_i2c_data *data = match->data;
610613
data->setup(op->dev.of_node, i2c, clock, data->prescaler);
611614
} else {
612615
/* Backwards compatibility */

0 commit comments

Comments
 (0)