diff mbox series

[08/14] media: wl128x-radio: use device managed memory allocation

Message ID 20181221011752.25627-9-sre@kernel.org (mailing list archive)
State New, archived
Headers show
Series Add support for FM radio in hcill and kill TI_ST | expand

Commit Message

Sebastian Reichel Dec. 21, 2018, 1:17 a.m. UTC
From: Sebastian Reichel <sebastian.reichel@collabora.com>

This simplifies memory allocation and removes a few useless
errors in case of -ENOMEM errors.

Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
---
 drivers/media/radio/wl128x/fmdrv_common.c | 41 +++++++----------------
 1 file changed, 13 insertions(+), 28 deletions(-)

Comments

Pavel Machek Dec. 22, 2018, 7:20 p.m. UTC | #1
On Fri 2018-12-21 02:17:46, Sebastian Reichel wrote:
> From: Sebastian Reichel <sebastian.reichel@collabora.com>
> 
> This simplifies memory allocation and removes a few useless
> errors in case of -ENOMEM errors.
> 
> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>

Acked-by: Pavel Machek <pavel@ucw.cz>
diff mbox series

Patch

diff --git a/drivers/media/radio/wl128x/fmdrv_common.c b/drivers/media/radio/wl128x/fmdrv_common.c
index 9526613adf91..3f189d093eeb 100644
--- a/drivers/media/radio/wl128x/fmdrv_common.c
+++ b/drivers/media/radio/wl128x/fmdrv_common.c
@@ -1614,55 +1614,40 @@  int fmc_release(struct fmdev *fmdev)
 	return ret;
 }
 
-static int wl128x_fm_probe(struct platform_device *dev)
+static int wl128x_fm_probe(struct platform_device *pdev)
 {
-	struct fmdev *fmdev = NULL;
-	int ret = -ENOMEM;
-
-	fmdbg("FM driver\n");
+	struct fmdev *fmdev;
+	int ret;
 
 	/* Allocate memory for FM driver context and RX RDS buffer. */
-	fmdev = kzalloc(sizeof(struct fmdev), GFP_KERNEL);
-	if (NULL == fmdev) {
-		fmerr("Can't allocate operation structure memory\n");
-		return ret;
-	}
+	fmdev = devm_kzalloc(&pdev->dev, sizeof(*fmdev), GFP_KERNEL);
+	if (!fmdev)
+		return -ENOMEM;
+	platform_set_drvdata(pdev, fmdev);
+
 	fmdev->rx.rds.buf_size = default_rds_buf * FM_RDS_BLK_SIZE;
-	fmdev->rx.rds.buff = kzalloc(fmdev->rx.rds.buf_size, GFP_KERNEL);
-	if (NULL == fmdev->rx.rds.buff) {
-		fmerr("Can't allocate rds ring buffer\n");
-		goto rel_dev;
-	}
+	fmdev->rx.rds.buff = devm_kzalloc(&pdev->dev, fmdev->rx.rds.buf_size, GFP_KERNEL);
+	if (!fmdev->rx.rds.buff)
+		return -ENOMEM;
 
 	/* Ask FM V4L module to register video device. */
 	ret = fm_v4l2_init_video_device(fmdev, radio_nr);
 	if (ret < 0)
-		goto rel_rdsbuf;
+		return ret;
 
 	fmdev->irq_info.handlers = int_handler_table;
 	fmdev->curr_fmmode = FM_MODE_OFF;
 	fmdev->tx_data.pwr_lvl = FM_PWR_LVL_DEF;
 	fmdev->tx_data.preemph = FM_TX_PREEMPH_50US;
 	return ret;
-
-rel_rdsbuf:
-	kfree(fmdev->rx.rds.buff);
-rel_dev:
-	kfree(fmdev);
-
-	return ret;
 }
 
-static int wl128x_fm_remove(struct platform_device *dev)
+static int wl128x_fm_remove(struct platform_device *pdev)
 {
 	struct fmdev *fmdev = platform_get_drvdata(pdev);
 
 	/* Ask FM V4L module to unregister video device */
 	fm_v4l2_deinit_video_device(fmdev);
-	if (fmdev != NULL) {
-		kfree(fmdev->rx.rds.buff);
-		kfree(fmdev);
-	}
 
 	return 0;
 }