diff options
author | Julia Lawall <Julia.Lawall@lip6.fr> | 2012-07-31 04:21:35 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2012-08-13 15:29:31 -0400 |
commit | d91e0139351b040ec558accab84bf59d5cef5552 (patch) | |
tree | a64d081eabd076987b404b61d30baa1a98899355 /drivers/media/radio/radio-wl1273.c | |
parent | 2f20c490aa3d8725305cb6333520b1c6a39858e0 (diff) |
[media] drivers/media/radio/radio-wl1273.c: use devm_ functions
The various devm_ functions allocate memory that is released when a driver
detaches. This patch uses these functions for data that is allocated in
the probe function of a platform device and is only freed in the remove
function.
In two cases, the original memory allocation function was kmalloc, which
has been changed to a zeroing allocation to benefit from the devm function.
Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/radio/radio-wl1273.c')
-rw-r--r-- | drivers/media/radio/radio-wl1273.c | 23 |
1 files changed, 7 insertions, 16 deletions
diff --git a/drivers/media/radio/radio-wl1273.c b/drivers/media/radio/radio-wl1273.c index e8428f573ccd..a22ad1c1f3d5 100644 --- a/drivers/media/radio/radio-wl1273.c +++ b/drivers/media/radio/radio-wl1273.c | |||
@@ -1983,9 +1983,6 @@ static int wl1273_fm_radio_remove(struct platform_device *pdev) | |||
1983 | v4l2_ctrl_handler_free(&radio->ctrl_handler); | 1983 | v4l2_ctrl_handler_free(&radio->ctrl_handler); |
1984 | video_unregister_device(&radio->videodev); | 1984 | video_unregister_device(&radio->videodev); |
1985 | v4l2_device_unregister(&radio->v4l2dev); | 1985 | v4l2_device_unregister(&radio->v4l2dev); |
1986 | kfree(radio->buffer); | ||
1987 | kfree(radio->write_buf); | ||
1988 | kfree(radio); | ||
1989 | 1986 | ||
1990 | return 0; | 1987 | return 0; |
1991 | } | 1988 | } |
@@ -2005,7 +2002,7 @@ static int __devinit wl1273_fm_radio_probe(struct platform_device *pdev) | |||
2005 | goto pdata_err; | 2002 | goto pdata_err; |
2006 | } | 2003 | } |
2007 | 2004 | ||
2008 | radio = kzalloc(sizeof(*radio), GFP_KERNEL); | 2005 | radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL); |
2009 | if (!radio) { | 2006 | if (!radio) { |
2010 | r = -ENOMEM; | 2007 | r = -ENOMEM; |
2011 | goto pdata_err; | 2008 | goto pdata_err; |
@@ -2013,11 +2010,11 @@ static int __devinit wl1273_fm_radio_probe(struct platform_device *pdev) | |||
2013 | 2010 | ||
2014 | /* RDS buffer allocation */ | 2011 | /* RDS buffer allocation */ |
2015 | radio->buf_size = rds_buf * RDS_BLOCK_SIZE; | 2012 | radio->buf_size = rds_buf * RDS_BLOCK_SIZE; |
2016 | radio->buffer = kmalloc(radio->buf_size, GFP_KERNEL); | 2013 | radio->buffer = devm_kzalloc(&pdev->dev, radio->buf_size, GFP_KERNEL); |
2017 | if (!radio->buffer) { | 2014 | if (!radio->buffer) { |
2018 | pr_err("Cannot allocate memory for RDS buffer.\n"); | 2015 | pr_err("Cannot allocate memory for RDS buffer.\n"); |
2019 | r = -ENOMEM; | 2016 | r = -ENOMEM; |
2020 | goto err_kmalloc; | 2017 | goto pdata_err; |
2021 | } | 2018 | } |
2022 | 2019 | ||
2023 | radio->core = *core; | 2020 | radio->core = *core; |
@@ -2043,7 +2040,7 @@ static int __devinit wl1273_fm_radio_probe(struct platform_device *pdev) | |||
2043 | if (r) { | 2040 | if (r) { |
2044 | dev_err(radio->dev, WL1273_FM_DRIVER_NAME | 2041 | dev_err(radio->dev, WL1273_FM_DRIVER_NAME |
2045 | ": Cannot get platform data\n"); | 2042 | ": Cannot get platform data\n"); |
2046 | goto err_resources; | 2043 | goto pdata_err; |
2047 | } | 2044 | } |
2048 | 2045 | ||
2049 | dev_dbg(radio->dev, "irq: %d\n", radio->core->client->irq); | 2046 | dev_dbg(radio->dev, "irq: %d\n", radio->core->client->irq); |
@@ -2061,13 +2058,13 @@ static int __devinit wl1273_fm_radio_probe(struct platform_device *pdev) | |||
2061 | dev_err(radio->dev, WL1273_FM_DRIVER_NAME ": Core WL1273 IRQ" | 2058 | dev_err(radio->dev, WL1273_FM_DRIVER_NAME ": Core WL1273 IRQ" |
2062 | " not configured"); | 2059 | " not configured"); |
2063 | r = -EINVAL; | 2060 | r = -EINVAL; |
2064 | goto err_resources; | 2061 | goto pdata_err; |
2065 | } | 2062 | } |
2066 | 2063 | ||
2067 | init_completion(&radio->busy); | 2064 | init_completion(&radio->busy); |
2068 | init_waitqueue_head(&radio->read_queue); | 2065 | init_waitqueue_head(&radio->read_queue); |
2069 | 2066 | ||
2070 | radio->write_buf = kmalloc(256, GFP_KERNEL); | 2067 | radio->write_buf = devm_kzalloc(&pdev->dev, 256, GFP_KERNEL); |
2071 | if (!radio->write_buf) { | 2068 | if (!radio->write_buf) { |
2072 | r = -ENOMEM; | 2069 | r = -ENOMEM; |
2073 | goto write_buf_err; | 2070 | goto write_buf_err; |
@@ -2080,7 +2077,7 @@ static int __devinit wl1273_fm_radio_probe(struct platform_device *pdev) | |||
2080 | r = v4l2_device_register(&pdev->dev, &radio->v4l2dev); | 2077 | r = v4l2_device_register(&pdev->dev, &radio->v4l2dev); |
2081 | if (r) { | 2078 | if (r) { |
2082 | dev_err(&pdev->dev, "Cannot register v4l2_device.\n"); | 2079 | dev_err(&pdev->dev, "Cannot register v4l2_device.\n"); |
2083 | goto device_register_err; | 2080 | goto write_buf_err; |
2084 | } | 2081 | } |
2085 | 2082 | ||
2086 | /* V4L2 configuration */ | 2083 | /* V4L2 configuration */ |
@@ -2135,16 +2132,10 @@ static int __devinit wl1273_fm_radio_probe(struct platform_device *pdev) | |||
2135 | handler_init_err: | 2132 | handler_init_err: |
2136 | v4l2_ctrl_handler_free(&radio->ctrl_handler); | 2133 | v4l2_ctrl_handler_free(&radio->ctrl_handler); |
2137 | v4l2_device_unregister(&radio->v4l2dev); | 2134 | v4l2_device_unregister(&radio->v4l2dev); |
2138 | device_register_err: | ||
2139 | kfree(radio->write_buf); | ||
2140 | write_buf_err: | 2135 | write_buf_err: |
2141 | free_irq(radio->core->client->irq, radio); | 2136 | free_irq(radio->core->client->irq, radio); |
2142 | err_request_irq: | 2137 | err_request_irq: |
2143 | radio->core->pdata->free_resources(); | 2138 | radio->core->pdata->free_resources(); |
2144 | err_resources: | ||
2145 | kfree(radio->buffer); | ||
2146 | err_kmalloc: | ||
2147 | kfree(radio); | ||
2148 | pdata_err: | 2139 | pdata_err: |
2149 | return r; | 2140 | return r; |
2150 | } | 2141 | } |