struct goldfish_audio *data;
dma_addr_t buf_addr;
- data = kzalloc(sizeof(*data), GFP_KERNEL);
- if (data == NULL) {
- ret = -ENOMEM;
- goto err_data_alloc_failed;
- }
+ data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
+ if (data == NULL)
+ return -ENOMEM;
spin_lock_init(&data->lock);
init_waitqueue_head(&data->wait);
platform_set_drvdata(pdev, data);
r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (r == NULL) {
dev_err(&pdev->dev, "platform_get_resource failed\n");
- ret = -ENODEV;
- goto err_no_io_base;
- }
- data->reg_base = ioremap(r->start, PAGE_SIZE);
- if (data->reg_base == NULL) {
- ret = -ENOMEM;
- goto err_no_io_base;
+ return -ENODEV;
}
+ data->reg_base = devm_ioremap(&pdev->dev, r->start, PAGE_SIZE);
+ if (data->reg_base == NULL)
+ return -ENOMEM;
data->irq = platform_get_irq(pdev, 0);
if (data->irq < 0) {
dev_err(&pdev->dev, "platform_get_irq failed\n");
- ret = -ENODEV;
- goto err_no_irq;
+ return -ENODEV;
}
- data->buffer_virt = dma_alloc_coherent(&pdev->dev,
+ data->buffer_virt = dmam_alloc_coherent(&pdev->dev,
COMBINED_BUFFER_SIZE, &buf_addr, GFP_KERNEL);
if (data->buffer_virt == 0) {
- ret = -ENOMEM;
dev_err(&pdev->dev, "allocate buffer failed\n");
- goto err_alloc_write_buffer_failed;
+ return -ENOMEM;
}
data->buffer_phys = buf_addr;
data->write_buffer1 = data->buffer_virt;
data->write_buffer2 = data->buffer_virt + WRITE_BUFFER_SIZE;
data->read_buffer = data->buffer_virt + 2 * WRITE_BUFFER_SIZE;
- ret = request_irq(data->irq, goldfish_audio_interrupt,
+ ret = devm_request_irq(&pdev->dev, data->irq, goldfish_audio_interrupt,
IRQF_SHARED, pdev->name, data);
if (ret) {
dev_err(&pdev->dev, "request_irq failed\n");
- goto err_request_irq_failed;
+ return ret;
}
ret = misc_register(&goldfish_audio_device);
dev_err(&pdev->dev,
"misc_register returned %d in goldfish_audio_init\n",
ret);
- goto err_misc_register_failed;
+ return ret;
}
AUDIO_WRITE64(data, AUDIO_SET_WRITE_BUFFER_1,
audio_data = data;
return 0;
-
-err_misc_register_failed:
- free_irq(data->irq, data);
-err_request_irq_failed:
- dma_free_coherent(&pdev->dev, COMBINED_BUFFER_SIZE,
- data->buffer_virt, data->buffer_phys);
-err_alloc_write_buffer_failed:
-err_no_irq:
- iounmap(data->reg_base);
-err_no_io_base:
- kfree(data);
-err_data_alloc_failed:
- return ret;
}
static int goldfish_audio_remove(struct platform_device *pdev)
{
- struct goldfish_audio *data = platform_get_drvdata(pdev);
-
misc_deregister(&goldfish_audio_device);
- free_irq(data->irq, data);
- dma_free_coherent(&pdev->dev, COMBINED_BUFFER_SIZE,
- data->buffer_virt, data->buffer_phys);
- iounmap(data->reg_base);
- kfree(data);
audio_data = NULL;
return 0;
}