Skip to content

Commit a7f3ea7

Browse files
Dmitry TorokhovLinus Torvalds
authored andcommitted
[PATCH] dcdbas: convert to the new platform device interface
Do not use platform_device_register_simple() as it is going away, define dcdbas_driver and implement ->probe() and ->remove() functions so manual binding and unbinding will work with this driver. Also switch to using attribute_group when creating sysfs attributes and make sure to check and handle errors; explicitely remove attributes when detaching driver. Signed-off-by: Dmitry Torokhov <dtor@mail.ru> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent d049761 commit a7f3ea7

1 file changed

Lines changed: 88 additions & 22 deletions

File tree

‎drivers/firmware/dcdbas.c‎

Lines changed: 88 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -530,50 +530,107 @@ static DCDBAS_DEV_ATTR_RW(host_control_action);
530530
static DCDBAS_DEV_ATTR_RW(host_control_smi_type);
531531
static DCDBAS_DEV_ATTR_RW(host_control_on_shutdown);
532532

533-
static struct device_attribute *dcdbas_dev_attrs[] = {
534-
&dev_attr_smi_data_buf_size,
535-
&dev_attr_smi_data_buf_phys_addr,
536-
&dev_attr_smi_request,
537-
&dev_attr_host_control_action,
538-
&dev_attr_host_control_smi_type,
539-
&dev_attr_host_control_on_shutdown,
533+
static struct attribute *dcdbas_dev_attrs[] = {
534+
&dev_attr_smi_data_buf_size.attr,
535+
&dev_attr_smi_data_buf_phys_addr.attr,
536+
&dev_attr_smi_request.attr,
537+
&dev_attr_host_control_action.attr,
538+
&dev_attr_host_control_smi_type.attr,
539+
&dev_attr_host_control_on_shutdown.attr,
540540
NULL
541541
};
542542

543-
/**
544-
* dcdbas_init: initialize driver
545-
*/
546-
static int __init dcdbas_init(void)
543+
static struct attribute_group dcdbas_attr_group = {
544+
.attrs = dcdbas_dev_attrs,
545+
};
546+
547+
static int __devinit dcdbas_probe(struct platform_device *dev)
547548
{
548-
int i;
549+
int i, error;
549550

550551
host_control_action = HC_ACTION_NONE;
551552
host_control_smi_type = HC_SMITYPE_NONE;
552553

553-
dcdbas_pdev = platform_device_register_simple(DRIVER_NAME, -1, NULL, 0);
554-
if (IS_ERR(dcdbas_pdev))
555-
return PTR_ERR(dcdbas_pdev);
556-
557554
/*
558555
* BIOS SMI calls require buffer addresses be in 32-bit address space.
559556
* This is done by setting the DMA mask below.
560557
*/
561558
dcdbas_pdev->dev.coherent_dma_mask = DMA_32BIT_MASK;
562559
dcdbas_pdev->dev.dma_mask = &dcdbas_pdev->dev.coherent_dma_mask;
563560

561+
error = sysfs_create_group(&dev->dev.kobj, &dcdbas_attr_group);
562+
if (error)
563+
return error;
564+
565+
for (i = 0; dcdbas_bin_attrs[i]; i++) {
566+
error = sysfs_create_bin_file(&dev->dev.kobj,
567+
dcdbas_bin_attrs[i]);
568+
if (error) {
569+
while (--i >= 0)
570+
sysfs_remove_bin_file(&dev->dev.kobj,
571+
dcdbas_bin_attrs[i]);
572+
sysfs_create_group(&dev->dev.kobj, &dcdbas_attr_group);
573+
return error;
574+
}
575+
}
576+
564577
register_reboot_notifier(&dcdbas_reboot_nb);
565578

579+
dev_info(&dev->dev, "%s (version %s)\n",
580+
DRIVER_DESCRIPTION, DRIVER_VERSION);
581+
582+
return 0;
583+
}
584+
585+
static int __devexit dcdbas_remove(struct platform_device *dev)
586+
{
587+
int i;
588+
589+
unregister_reboot_notifier(&dcdbas_reboot_nb);
566590
for (i = 0; dcdbas_bin_attrs[i]; i++)
567-
sysfs_create_bin_file(&dcdbas_pdev->dev.kobj,
568-
dcdbas_bin_attrs[i]);
591+
sysfs_remove_bin_file(&dev->dev.kobj, dcdbas_bin_attrs[i]);
592+
sysfs_remove_group(&dev->dev.kobj, &dcdbas_attr_group);
569593

570-
for (i = 0; dcdbas_dev_attrs[i]; i++)
571-
device_create_file(&dcdbas_pdev->dev, dcdbas_dev_attrs[i]);
594+
return 0;
595+
}
572596

573-
dev_info(&dcdbas_pdev->dev, "%s (version %s)\n",
574-
DRIVER_DESCRIPTION, DRIVER_VERSION);
597+
static struct platform_driver dcdbas_driver = {
598+
.driver = {
599+
.name = DRIVER_NAME,
600+
.owner = THIS_MODULE,
601+
},
602+
.probe = dcdbas_probe,
603+
.remove = __devexit_p(dcdbas_remove),
604+
};
605+
606+
/**
607+
* dcdbas_init: initialize driver
608+
*/
609+
static int __init dcdbas_init(void)
610+
{
611+
int error;
612+
613+
error = platform_driver_register(&dcdbas_driver);
614+
if (error)
615+
return error;
616+
617+
dcdbas_pdev = platform_device_alloc(DRIVER_NAME, -1);
618+
if (!dcdbas_pdev) {
619+
error = -ENOMEM;
620+
goto err_unregister_driver;
621+
}
622+
623+
error = platform_device_add(dcdbas_pdev);
624+
if (error)
625+
goto err_free_device;
575626

576627
return 0;
628+
629+
err_free_device:
630+
platform_device_put(dcdbas_pdev);
631+
err_unregister_driver:
632+
platform_driver_unregister(&dcdbas_driver);
633+
return error;
577634
}
578635

579636
/**
@@ -588,6 +645,15 @@ static void __exit dcdbas_exit(void)
588645
unregister_reboot_notifier(&dcdbas_reboot_nb);
589646
smi_data_buf_free();
590647
platform_device_unregister(dcdbas_pdev);
648+
platform_driver_unregister(&dcdbas_driver);
649+
650+
/*
651+
* We have to free the buffer here instead of dcdbas_remove
652+
* because only in module exit function we can be sure that
653+
* all sysfs attributes belonging to this module have been
654+
* released.
655+
*/
656+
smi_data_buf_free();
591657
}
592658

593659
module_init(dcdbas_init);

0 commit comments

Comments
 (0)