[1/2] rtc: max77686: convert to devm_i2c_new_dummy_device()
diff mbox series

Message ID 20190820154239.8230-2-wsa+renesas@sang-engineering.com
State Superseded
Headers show
Series
  • rtc: convert two drivers to devm_i2c_new_dummy_device()
Related show

Commit Message

Wolfram Sang Aug. 20, 2019, 3:42 p.m. UTC
I was about to simplify the call to i2c_unregister_device() when I
realized that converting to devm_i2c_new_dummy_device() will simplify
the driver a lot. So I took this approach.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
Build tested only, buildbot is happy, too.

Please apply to your tree.

 drivers/rtc/rtc-max77686.c | 17 ++++-------------
 1 file changed, 4 insertions(+), 13 deletions(-)

Comments

Alexandre Belloni Aug. 29, 2019, 8:57 p.m. UTC | #1
On 20/08/2019 17:42:37+0200, Wolfram Sang wrote:
> I was about to simplify the call to i2c_unregister_device() when I
> realized that converting to devm_i2c_new_dummy_device() will simplify
> the driver a lot. So I took this approach.
> 
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
> ---
> Build tested only, buildbot is happy, too.
> 
> Please apply to your tree.
> 

I'm confused because I already applied:
https://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux.git/commit/?h=rtc-next&id=7150710f3084de8d35ce3221eeae2caee8813f92

>  drivers/rtc/rtc-max77686.c | 17 ++++-------------
>  1 file changed, 4 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/rtc/rtc-max77686.c b/drivers/rtc/rtc-max77686.c
> index d04fd1024697..4027b33034dc 100644
> --- a/drivers/rtc/rtc-max77686.c
> +++ b/drivers/rtc/rtc-max77686.c
> @@ -693,8 +693,8 @@ static int max77686_init_rtc_regmap(struct max77686_rtc_info *info)
>  		goto add_rtc_irq;
>  	}
>  
> -	info->rtc = i2c_new_dummy_device(parent_i2c->adapter,
> -				  info->drv_data->rtc_i2c_addr);
> +	info->rtc = devm_i2c_new_dummy_device(info->dev, parent_i2c->adapter,
> +					      info->drv_data->rtc_i2c_addr);
>  	if (IS_ERR(info->rtc)) {
>  		dev_err(info->dev, "Failed to allocate I2C device for RTC\n");
>  		return PTR_ERR(info->rtc);
> @@ -705,7 +705,7 @@ static int max77686_init_rtc_regmap(struct max77686_rtc_info *info)
>  	if (IS_ERR(info->rtc_regmap)) {
>  		ret = PTR_ERR(info->rtc_regmap);
>  		dev_err(info->dev, "Failed to allocate RTC regmap: %d\n", ret);
> -		goto err_unregister_i2c;
> +		return ret;
>  	}
>  
>  add_rtc_irq:
> @@ -715,15 +715,10 @@ static int max77686_init_rtc_regmap(struct max77686_rtc_info *info)
>  				  &info->rtc_irq_data);
>  	if (ret < 0) {
>  		dev_err(info->dev, "Failed to add RTC irq chip: %d\n", ret);
> -		goto err_unregister_i2c;
> +		return ret;
>  	}
>  
>  	return 0;
> -
> -err_unregister_i2c:
> -	if (info->rtc)
> -		i2c_unregister_device(info->rtc);
> -	return ret;
>  }
>  
>  static int max77686_rtc_probe(struct platform_device *pdev)
> @@ -786,8 +781,6 @@ static int max77686_rtc_probe(struct platform_device *pdev)
>  
>  err_rtc:
>  	regmap_del_irq_chip(info->rtc_irq, info->rtc_irq_data);
> -	if (info->rtc)
> -		i2c_unregister_device(info->rtc);
>  
>  	return ret;
>  }
> @@ -798,8 +791,6 @@ static int max77686_rtc_remove(struct platform_device *pdev)
>  
>  	free_irq(info->virq, info);
>  	regmap_del_irq_chip(info->rtc_irq, info->rtc_irq_data);
> -	if (info->rtc)
> -		i2c_unregister_device(info->rtc);
>  
>  	return 0;
>  }
> -- 
> 2.20.1
>
Wolfram Sang Aug. 30, 2019, 12:45 p.m. UTC | #2
On Thu, Aug 29, 2019 at 10:57:52PM +0200, Alexandre Belloni wrote:
> On 20/08/2019 17:42:37+0200, Wolfram Sang wrote:
> > I was about to simplify the call to i2c_unregister_device() when I
> > realized that converting to devm_i2c_new_dummy_device() will simplify
> > the driver a lot. So I took this approach.
> > 
> > Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
> > ---
> > Build tested only, buildbot is happy, too.
> > 
> > Please apply to your tree.
> > 
> 
> I'm confused because I already applied:
> https://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux.git/commit/?h=rtc-next&id=7150710f3084de8d35ce3221eeae2caee8813f92

The above was a mass conversion to i2c_new_dummy_device() to make sure
all in-kernel users use the API returning an ERRPTR. Mass conversion to
the devm_ variant of the same function was too troublesome.

With another series, I wanted to remove superfluous error checking of
i2c_unregister_device() because it is NULL-ptr safe, like here:

> > -	if (info->rtc)
> > -		i2c_unregister_device(info->rtc);

But for these two RTC drivers, I figured moving to devm_* is way easier
than fixing up the mass conversion result from coccinelle.
Alexandre Belloni Aug. 30, 2019, 12:53 p.m. UTC | #3
On 30/08/2019 14:45:54+0200, Wolfram Sang wrote:
> On Thu, Aug 29, 2019 at 10:57:52PM +0200, Alexandre Belloni wrote:
> > On 20/08/2019 17:42:37+0200, Wolfram Sang wrote:
> > > I was about to simplify the call to i2c_unregister_device() when I
> > > realized that converting to devm_i2c_new_dummy_device() will simplify
> > > the driver a lot. So I took this approach.
> > > 
> > > Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
> > > ---
> > > Build tested only, buildbot is happy, too.
> > > 
> > > Please apply to your tree.
> > > 
> > 
> > I'm confused because I already applied:
> > https://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux.git/commit/?h=rtc-next&id=7150710f3084de8d35ce3221eeae2caee8813f92
> 
> The above was a mass conversion to i2c_new_dummy_device() to make sure
> all in-kernel users use the API returning an ERRPTR. Mass conversion to
> the devm_ variant of the same function was too troublesome.
> 
> With another series, I wanted to remove superfluous error checking of
> i2c_unregister_device() because it is NULL-ptr safe, like here:
> 
> > > -	if (info->rtc)
> > > -		i2c_unregister_device(info->rtc);
> 
> But for these two RTC drivers, I figured moving to devm_* is way easier
> than fixing up the mass conversion result from coccinelle.
> 

Ok so should I drop the previous patches and apply those instead?
Wolfram Sang Aug. 30, 2019, 1 p.m. UTC | #4
> > > I'm confused because I already applied:
> > > https://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux.git/commit/?h=rtc-next&id=7150710f3084de8d35ce3221eeae2caee8813f92
> > 
> > The above was a mass conversion to i2c_new_dummy_device() to make sure
> > all in-kernel users use the API returning an ERRPTR. Mass conversion to
> > the devm_ variant of the same function was too troublesome.
> > 
> > With another series, I wanted to remove superfluous error checking of
> > i2c_unregister_device() because it is NULL-ptr safe, like here:
> > 
> > > > -	if (info->rtc)
> > > > -		i2c_unregister_device(info->rtc);
> > 
> > But for these two RTC drivers, I figured moving to devm_* is way easier
> > than fixing up the mass conversion result from coccinelle.
> > 
> 
> Ok so should I drop the previous patches and apply those instead?

Nope, they should be incremental, aren't they?
Alexandre Belloni Aug. 30, 2019, 1:06 p.m. UTC | #5
On 30/08/2019 15:00:35+0200, Wolfram Sang wrote:
> 
> > > > I'm confused because I already applied:
> > > > https://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux.git/commit/?h=rtc-next&id=7150710f3084de8d35ce3221eeae2caee8813f92
> > > 
> > > The above was a mass conversion to i2c_new_dummy_device() to make sure
> > > all in-kernel users use the API returning an ERRPTR. Mass conversion to
> > > the devm_ variant of the same function was too troublesome.
> > > 
> > > With another series, I wanted to remove superfluous error checking of
> > > i2c_unregister_device() because it is NULL-ptr safe, like here:
> > > 
> > > > > -	if (info->rtc)
> > > > > -		i2c_unregister_device(info->rtc);
> > > 
> > > But for these two RTC drivers, I figured moving to devm_* is way easier
> > > than fixing up the mass conversion result from coccinelle.
> > > 
> > 
> > Ok so should I drop the previous patches and apply those instead?
> 
> Nope, they should be incremental, aren't they?
> 
No, your patches don't apply on top of rtc-next
Wolfram Sang Aug. 30, 2019, 1:18 p.m. UTC | #6
> > Nope, they should be incremental, aren't they?
> > 
> No, your patches don't apply on top of rtc-next

Looks like you edited some whitespaces to match opening parens before
applying? I'll resend to match these.

Patch
diff mbox series

diff --git a/drivers/rtc/rtc-max77686.c b/drivers/rtc/rtc-max77686.c
index d04fd1024697..4027b33034dc 100644
--- a/drivers/rtc/rtc-max77686.c
+++ b/drivers/rtc/rtc-max77686.c
@@ -693,8 +693,8 @@  static int max77686_init_rtc_regmap(struct max77686_rtc_info *info)
 		goto add_rtc_irq;
 	}
 
-	info->rtc = i2c_new_dummy_device(parent_i2c->adapter,
-				  info->drv_data->rtc_i2c_addr);
+	info->rtc = devm_i2c_new_dummy_device(info->dev, parent_i2c->adapter,
+					      info->drv_data->rtc_i2c_addr);
 	if (IS_ERR(info->rtc)) {
 		dev_err(info->dev, "Failed to allocate I2C device for RTC\n");
 		return PTR_ERR(info->rtc);
@@ -705,7 +705,7 @@  static int max77686_init_rtc_regmap(struct max77686_rtc_info *info)
 	if (IS_ERR(info->rtc_regmap)) {
 		ret = PTR_ERR(info->rtc_regmap);
 		dev_err(info->dev, "Failed to allocate RTC regmap: %d\n", ret);
-		goto err_unregister_i2c;
+		return ret;
 	}
 
 add_rtc_irq:
@@ -715,15 +715,10 @@  static int max77686_init_rtc_regmap(struct max77686_rtc_info *info)
 				  &info->rtc_irq_data);
 	if (ret < 0) {
 		dev_err(info->dev, "Failed to add RTC irq chip: %d\n", ret);
-		goto err_unregister_i2c;
+		return ret;
 	}
 
 	return 0;
-
-err_unregister_i2c:
-	if (info->rtc)
-		i2c_unregister_device(info->rtc);
-	return ret;
 }
 
 static int max77686_rtc_probe(struct platform_device *pdev)
@@ -786,8 +781,6 @@  static int max77686_rtc_probe(struct platform_device *pdev)
 
 err_rtc:
 	regmap_del_irq_chip(info->rtc_irq, info->rtc_irq_data);
-	if (info->rtc)
-		i2c_unregister_device(info->rtc);
 
 	return ret;
 }
@@ -798,8 +791,6 @@  static int max77686_rtc_remove(struct platform_device *pdev)
 
 	free_irq(info->virq, info);
 	regmap_del_irq_chip(info->rtc_irq, info->rtc_irq_data);
-	if (info->rtc)
-		i2c_unregister_device(info->rtc);
 
 	return 0;
 }