mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-06 19:07:52 +00:00
staging: goldfish: Introduce the use of managed interfaces
This patch introduces the use of managed interfaces like devm_kzalloc, devm_ioremap, dmam_alloc_coherent, devm_request_irq and does away with the calls to functions to free the allocated memory in the probe and remove functions. Also, the labels are removed in the probe function. Signed-off-by: Himangi Saraogi <himangi774@gmail.com> Acked-by: Julia Lawall <julia.lawall@lip6.fr> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
5a9077a833
commit
85f28332e3
1 changed files with 13 additions and 40 deletions
|
@ -274,11 +274,9 @@ static int goldfish_audio_probe(struct platform_device *pdev)
|
||||||
struct goldfish_audio *data;
|
struct goldfish_audio *data;
|
||||||
dma_addr_t buf_addr;
|
dma_addr_t buf_addr;
|
||||||
|
|
||||||
data = kzalloc(sizeof(*data), GFP_KERNEL);
|
data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
|
||||||
if (data == NULL) {
|
if (data == NULL)
|
||||||
ret = -ENOMEM;
|
return -ENOMEM;
|
||||||
goto err_data_alloc_failed;
|
|
||||||
}
|
|
||||||
spin_lock_init(&data->lock);
|
spin_lock_init(&data->lock);
|
||||||
init_waitqueue_head(&data->wait);
|
init_waitqueue_head(&data->wait);
|
||||||
platform_set_drvdata(pdev, data);
|
platform_set_drvdata(pdev, data);
|
||||||
|
@ -286,38 +284,33 @@ static int goldfish_audio_probe(struct platform_device *pdev)
|
||||||
r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
||||||
if (r == NULL) {
|
if (r == NULL) {
|
||||||
dev_err(&pdev->dev, "platform_get_resource failed\n");
|
dev_err(&pdev->dev, "platform_get_resource failed\n");
|
||||||
ret = -ENODEV;
|
return -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;
|
|
||||||
}
|
}
|
||||||
|
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);
|
data->irq = platform_get_irq(pdev, 0);
|
||||||
if (data->irq < 0) {
|
if (data->irq < 0) {
|
||||||
dev_err(&pdev->dev, "platform_get_irq failed\n");
|
dev_err(&pdev->dev, "platform_get_irq failed\n");
|
||||||
ret = -ENODEV;
|
return -ENODEV;
|
||||||
goto err_no_irq;
|
|
||||||
}
|
}
|
||||||
data->buffer_virt = dma_alloc_coherent(&pdev->dev,
|
data->buffer_virt = dmam_alloc_coherent(&pdev->dev,
|
||||||
COMBINED_BUFFER_SIZE, &buf_addr, GFP_KERNEL);
|
COMBINED_BUFFER_SIZE, &buf_addr, GFP_KERNEL);
|
||||||
if (data->buffer_virt == 0) {
|
if (data->buffer_virt == 0) {
|
||||||
ret = -ENOMEM;
|
|
||||||
dev_err(&pdev->dev, "allocate buffer failed\n");
|
dev_err(&pdev->dev, "allocate buffer failed\n");
|
||||||
goto err_alloc_write_buffer_failed;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
data->buffer_phys = buf_addr;
|
data->buffer_phys = buf_addr;
|
||||||
data->write_buffer1 = data->buffer_virt;
|
data->write_buffer1 = data->buffer_virt;
|
||||||
data->write_buffer2 = data->buffer_virt + WRITE_BUFFER_SIZE;
|
data->write_buffer2 = data->buffer_virt + WRITE_BUFFER_SIZE;
|
||||||
data->read_buffer = data->buffer_virt + 2 * 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);
|
IRQF_SHARED, pdev->name, data);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
dev_err(&pdev->dev, "request_irq failed\n");
|
dev_err(&pdev->dev, "request_irq failed\n");
|
||||||
goto err_request_irq_failed;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = misc_register(&goldfish_audio_device);
|
ret = misc_register(&goldfish_audio_device);
|
||||||
|
@ -325,7 +318,7 @@ static int goldfish_audio_probe(struct platform_device *pdev)
|
||||||
dev_err(&pdev->dev,
|
dev_err(&pdev->dev,
|
||||||
"misc_register returned %d in goldfish_audio_init\n",
|
"misc_register returned %d in goldfish_audio_init\n",
|
||||||
ret);
|
ret);
|
||||||
goto err_misc_register_failed;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
AUDIO_WRITE64(data, AUDIO_SET_WRITE_BUFFER_1,
|
AUDIO_WRITE64(data, AUDIO_SET_WRITE_BUFFER_1,
|
||||||
|
@ -344,31 +337,11 @@ static int goldfish_audio_probe(struct platform_device *pdev)
|
||||||
|
|
||||||
audio_data = data;
|
audio_data = data;
|
||||||
return 0;
|
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)
|
static int goldfish_audio_remove(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
struct goldfish_audio *data = platform_get_drvdata(pdev);
|
|
||||||
|
|
||||||
misc_deregister(&goldfish_audio_device);
|
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;
|
audio_data = NULL;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue