linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pavel Machek <pavel@ucw.cz>
To: Ivaylo Dimitrov <ivo.g.dimitrov.75@gmail.com>
Cc: pali.rohar@gmail.com, sre@kernel.org,
	kernel list <linux-kernel@vger.kernel.org>,
	linux-arm-kernel <linux-arm-kernel@lists.infradead.org>,
	linux-omap@vger.kernel.org, tony@atomide.com, khilman@kernel.org,
	aaro.koskinen@iki.fi, patrikbachan@gmail.com, serge@hallyn.com,
	linux-media@vger.kernel.org, mchehab@osg.samsung.com,
	sakari.ailus@iki.fi
Subject: Re: [PATCHv3] support for AD5820 camera auto-focus coil
Date: Tue, 24 May 2016 22:20:59 +0200	[thread overview]
Message-ID: <20160524202059.GB18536@amd> (raw)
In-Reply-To: <57441BF8.60606@gmail.com>

Hi!

> >>devm_regulator_get()?
> >
> >I'd rather avoid devm_ here. Driver is simple enough to allow it.
> >
> 
> Now thinking about it, what would happen here if regulator_get() returns
> -EPROBE_DEFER? Wouldn't it be better to move regulator_get to the probe()
> function, something like:

Ok, I can do it.

Oh, and don't try to complain about newlines before returns. It looks
better this way.

> static int ad5820_probe(struct i2c_client *client,
> 			const struct i2c_device_id *devid)
> {
> 	struct ad5820_device *coil;
> 	int ret = 0;
> 
> 	coil = devm_kzalloc(sizeof(*coil), GFP_KERNEL);
> 	if (coil == NULL)
> 		return -ENOMEM;
> 
> 	coil->vana = devm_regulator_get(&client->dev, NULL);
> 	if (IS_ERR(coil->vana)) {
> 		ret = PTR_ERR(coil->vana);
> 		if (ret != -EPROBE_DEFER)
> 			dev_err(&client->dev, "could not get regulator for vana\n");
> 		return ret;
> 	}
> 
> 	mutex_init(&coil->power_lock);
> ...
> 
> with the appropriate changes to remove() because of the devm API
> 			usage.

Something like this?

diff --git a/drivers/media/i2c/ad5820.c b/drivers/media/i2c/ad5820.c
index f956bd3..f871366 100644
--- a/drivers/media/i2c/ad5820.c
+++ b/drivers/media/i2c/ad5820.c
@@ -8,7 +8,7 @@
  * Copyright (C) 2016 Pavel Machek <pavel@ucw.cz>
  *
  * Contact: Tuukka Toivonen
- *          Sakari Ailus
+ *	    Sakari Ailus
  *
  * Based on af_d88.c by Texas Instruments.
  *
@@ -263,13 +263,6 @@ static int ad5820_init_controls(struct ad5820_device *coil)
 static int ad5820_registered(struct v4l2_subdev *subdev)
 {
 	struct ad5820_device *coil = to_ad5820_device(subdev);
-	struct i2c_client *client = v4l2_get_subdevdata(subdev);
-
-	coil->vana = regulator_get(&client->dev, "VANA");
-	if (IS_ERR(coil->vana)) {
-		dev_err(&client->dev, "could not get regulator for vana\n");
-		return -ENODEV;
-	}
 
 	return ad5820_init_controls(coil);
 }
@@ -367,10 +360,18 @@ static int ad5820_probe(struct i2c_client *client,
 	struct ad5820_device *coil;
 	int ret = 0;
 
-	coil = kzalloc(sizeof(*coil), GFP_KERNEL);
+	coil = devm_kzalloc(sizeof(*coil), GFP_KERNEL);
 	if (!coil)
 		return -ENOMEM;
 
+	coil->vana = devm_regulator_get(&client->dev, NULL);
+	if (IS_ERR(coil->vana)) {
+		ret = PTR_ERR(coil->vana);
+		if (ret != -EPROBE_DEFER)
+			dev_err(&client->dev, "could not get regulator for vana\n");
+		return ret;
+	}
+	
 	mutex_init(&coil->power_lock);
 
 	v4l2_i2c_subdev_init(&coil->subdev, client, &ad5820_ops);
@@ -390,10 +391,6 @@ static int ad5820_probe(struct i2c_client *client,
 
 cleanup:
 	media_entity_cleanup(&coil->subdev.entity);
-
-free:
-	kfree(coil);
-
 	return ret;
 }
 
@@ -405,11 +402,6 @@ static int __exit ad5820_remove(struct i2c_client *client)
 	v4l2_device_unregister_subdev(&coil->subdev);
 	v4l2_ctrl_handler_free(&coil->ctrls);
 	media_entity_cleanup(&coil->subdev.entity);
-	if (coil->vana)
-		regulator_put(coil->vana);
-
-	kfree(coil);
-
 	return 0;
 }
 


-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

  reply	other threads:[~2016-05-24 20:21 UTC|newest]

Thread overview: 73+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-17 18:19 [PATCH] support for AD5820 camera auto-focus coil Pavel Machek
2016-05-17 18:33 ` Marcus Folkesson
2016-05-18  8:30   ` Pavel Machek
2016-05-21  5:43 ` [PATCHv2] " Pavel Machek
2016-05-21  6:25   ` Ivaylo Dimitrov
2016-05-21 10:56     ` [PATCHv3] " Pavel Machek
2016-05-21 11:43       ` Ivaylo Dimitrov
2016-05-23  7:41         ` Pali Rohár
2016-05-24  9:04         ` Pavel Machek
2016-05-24  9:16           ` Ivaylo Dimitrov
2016-05-24 20:20             ` Pavel Machek [this message]
2016-05-26  3:46               ` Ivaylo Dimitrov
2016-05-24  9:17           ` [PATCHv4] " Pavel Machek
2016-05-25 21:26             ` Sakari Ailus
2016-05-27 20:33               ` Pavel Machek
2016-05-27 20:51               ` [PATCHv5] " Pavel Machek
2016-05-31 21:22                 ` Sakari Ailus
2016-05-31 21:34                   ` Pavel Machek
2016-06-01 15:24                     ` Sakari Ailus
2016-06-01 22:08                       ` Pavel Machek
2016-06-02  7:45                         ` Sakari Ailus
2016-06-02 19:27                           ` Pavel Machek
2016-06-02 21:23                             ` Sakari Ailus
2016-06-02 19:30                           ` [PATCH] device tree description " Pavel Machek
2016-06-02 21:27                             ` Sakari Ailus
2016-06-03  6:19                               ` Pavel Machek
2016-06-05 19:07                               ` [PATCH] userspace API definitions for " Pavel Machek
2016-06-06  6:06                                 ` Ivaylo Dimitrov
2016-06-06  7:21                                   ` Pavel Machek
2016-06-11 22:06                                   ` Sakari Ailus
2016-06-12  7:54                                     ` Pavel Machek
2016-06-17 21:28                                       ` Sakari Ailus
2016-06-12  8:48                                     ` Pavel Machek
2016-06-12 11:22                                       ` Sakari Ailus
2016-06-13 19:17                                         ` Pavel Machek
2016-06-17 21:35                                           ` Sakari Ailus
2016-06-18 15:37                                             ` [PATCHv4] support for AD5820 camera " Pavel Machek
2016-06-18 15:38                                             ` [PATCH] userspace API definitions for " Pavel Machek
2016-07-12 23:32                                               ` Mauro Carvalho Chehab
2016-07-13  6:57                                                 ` Pavel Machek
2016-07-13  7:26                                                 ` Pavel Machek
2016-06-06 13:29                             ` [PATCH] device tree description for AD5820 camera " Rob Herring
2016-06-07  7:10                             ` [PATCHv2] " Pavel Machek
2016-06-09 22:37                               ` Sakari Ailus
2016-06-04 23:27                 ` [PATCHv5] support " kbuild test robot
2016-06-05  0:46                 ` kbuild test robot
2016-06-12 20:41                 ` [PATCH 1/1] v4l: Add camera voice coil lens control class, current control Sakari Ailus
2016-06-12 21:48                   ` Ivaylo Dimitrov
2016-06-17 22:11                     ` Pavel Machek
2016-06-17 22:39                       ` Laurent Pinchart
2016-06-18 11:28                         ` Pavel Machek
2016-06-17 22:06                   ` Pavel Machek
2016-08-05 10:26                 ` [PATCHv6] support for AD5820 camera auto-focus coil Pavel Machek
2016-08-05 10:30                   ` Pali Rohár
2016-08-08  8:09                   ` Sakari Ailus
2016-08-08 21:41                     ` Pavel Machek
2016-08-10 12:01                       ` Sakari Ailus
2016-08-08 23:23                         ` Pavel Machek
2016-08-11 11:16                           ` Sakari Ailus
2016-08-18 10:45                             ` Pavel Machek
2016-08-18 20:26                               ` Sakari Ailus
2016-08-18 21:28                                 ` Pavel Machek
2016-11-03 10:27                                 ` Pavel Machek
2016-11-03 21:49                                   ` Sakari Ailus
2016-11-04  7:45                                     ` Pavel Machek
2016-11-04 14:49                                       ` Tony Lindgren
2016-12-14 13:38                       ` Pali Rohár
2016-12-14 15:08                         ` Tony Lindgren
2016-12-15  6:50                           ` Sakari Ailus
2016-12-19 22:23                             ` Pavel Machek
2016-08-10  7:34                     ` Pali Rohár
2016-08-08 21:40                       ` Pavel Machek
2016-08-10 12:00                       ` Sakari Ailus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160524202059.GB18536@amd \
    --to=pavel@ucw.cz \
    --cc=aaro.koskinen@iki.fi \
    --cc=ivo.g.dimitrov.75@gmail.com \
    --cc=khilman@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=mchehab@osg.samsung.com \
    --cc=pali.rohar@gmail.com \
    --cc=patrikbachan@gmail.com \
    --cc=sakari.ailus@iki.fi \
    --cc=serge@hallyn.com \
    --cc=sre@kernel.org \
    --cc=tony@atomide.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).