aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio/gpio-dwapb.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpio/gpio-dwapb.c')
-rw-r--r--drivers/gpio/gpio-dwapb.c53
1 files changed, 14 insertions, 39 deletions
diff --git a/drivers/gpio/gpio-dwapb.c b/drivers/gpio/gpio-dwapb.c
index b4eb6a657d34..58faf04fce5d 100644
--- a/drivers/gpio/gpio-dwapb.c
+++ b/drivers/gpio/gpio-dwapb.c
@@ -469,15 +469,13 @@ dwapb_gpio_get_pdata_of(struct device *dev)
469 if (nports == 0) 469 if (nports == 0)
470 return ERR_PTR(-ENODEV); 470 return ERR_PTR(-ENODEV);
471 471
472 pdata = kzalloc(sizeof(*pdata), GFP_KERNEL); 472 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
473 if (!pdata) 473 if (!pdata)
474 return ERR_PTR(-ENOMEM); 474 return ERR_PTR(-ENOMEM);
475 475
476 pdata->properties = kcalloc(nports, sizeof(*pp), GFP_KERNEL); 476 pdata->properties = devm_kcalloc(dev, nports, sizeof(*pp), GFP_KERNEL);
477 if (!pdata->properties) { 477 if (!pdata->properties)
478 kfree(pdata);
479 return ERR_PTR(-ENOMEM); 478 return ERR_PTR(-ENOMEM);
480 }
481 479
482 pdata->nports = nports; 480 pdata->nports = nports;
483 481
@@ -490,8 +488,6 @@ dwapb_gpio_get_pdata_of(struct device *dev)
490 pp->idx >= DWAPB_MAX_PORTS) { 488 pp->idx >= DWAPB_MAX_PORTS) {
491 dev_err(dev, "missing/invalid port index for %s\n", 489 dev_err(dev, "missing/invalid port index for %s\n",
492 port_np->full_name); 490 port_np->full_name);
493 kfree(pdata->properties);
494 kfree(pdata);
495 return ERR_PTR(-EINVAL); 491 return ERR_PTR(-EINVAL);
496 } 492 }
497 493
@@ -523,15 +519,6 @@ dwapb_gpio_get_pdata_of(struct device *dev)
523 return pdata; 519 return pdata;
524} 520}
525 521
526static inline void dwapb_free_pdata_of(struct dwapb_platform_data *pdata)
527{
528 if (!IS_ENABLED(CONFIG_OF_GPIO) || !pdata)
529 return;
530
531 kfree(pdata->properties);
532 kfree(pdata);
533}
534
535static int dwapb_gpio_probe(struct platform_device *pdev) 522static int dwapb_gpio_probe(struct platform_device *pdev)
536{ 523{
537 unsigned int i; 524 unsigned int i;
@@ -540,40 +527,32 @@ static int dwapb_gpio_probe(struct platform_device *pdev)
540 int err; 527 int err;
541 struct device *dev = &pdev->dev; 528 struct device *dev = &pdev->dev;
542 struct dwapb_platform_data *pdata = dev_get_platdata(dev); 529 struct dwapb_platform_data *pdata = dev_get_platdata(dev);
543 bool is_pdata_alloc = !pdata;
544 530
545 if (is_pdata_alloc) { 531 if (!pdata) {
546 pdata = dwapb_gpio_get_pdata_of(dev); 532 pdata = dwapb_gpio_get_pdata_of(dev);
547 if (IS_ERR(pdata)) 533 if (IS_ERR(pdata))
548 return PTR_ERR(pdata); 534 return PTR_ERR(pdata);
549 } 535 }
550 536
551 if (!pdata->nports) { 537 if (!pdata->nports)
552 err = -ENODEV; 538 return -ENODEV;
553 goto out_err;
554 }
555 539
556 gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL); 540 gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL);
557 if (!gpio) { 541 if (!gpio)
558 err = -ENOMEM; 542 return -ENOMEM;
559 goto out_err; 543
560 }
561 gpio->dev = &pdev->dev; 544 gpio->dev = &pdev->dev;
562 gpio->nr_ports = pdata->nports; 545 gpio->nr_ports = pdata->nports;
563 546
564 gpio->ports = devm_kcalloc(&pdev->dev, gpio->nr_ports, 547 gpio->ports = devm_kcalloc(&pdev->dev, gpio->nr_ports,
565 sizeof(*gpio->ports), GFP_KERNEL); 548 sizeof(*gpio->ports), GFP_KERNEL);
566 if (!gpio->ports) { 549 if (!gpio->ports)
567 err = -ENOMEM; 550 return -ENOMEM;
568 goto out_err;
569 }
570 551
571 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 552 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
572 gpio->regs = devm_ioremap_resource(&pdev->dev, res); 553 gpio->regs = devm_ioremap_resource(&pdev->dev, res);
573 if (IS_ERR(gpio->regs)) { 554 if (IS_ERR(gpio->regs))
574 err = PTR_ERR(gpio->regs); 555 return PTR_ERR(gpio->regs);
575 goto out_err;
576 }
577 556
578 for (i = 0; i < gpio->nr_ports; i++) { 557 for (i = 0; i < gpio->nr_ports; i++) {
579 err = dwapb_gpio_add_port(gpio, &pdata->properties[i], i); 558 err = dwapb_gpio_add_port(gpio, &pdata->properties[i], i);
@@ -582,16 +561,12 @@ static int dwapb_gpio_probe(struct platform_device *pdev)
582 } 561 }
583 platform_set_drvdata(pdev, gpio); 562 platform_set_drvdata(pdev, gpio);
584 563
585 goto out_err; 564 return 0;
586 565
587out_unregister: 566out_unregister:
588 dwapb_gpio_unregister(gpio); 567 dwapb_gpio_unregister(gpio);
589 dwapb_irq_teardown(gpio); 568 dwapb_irq_teardown(gpio);
590 569
591out_err:
592 if (is_pdata_alloc)
593 dwapb_free_pdata_of(pdata);
594
595 return err; 570 return err;
596} 571}
597 572