Patchwork [3/3] rtc: pcf8583: Convert to use devm_* API

login
register
mail settings
Submitter Axel Lin
Date April 14, 2013, 2:20 p.m.
Message ID <1365949220.16287.2.camel@phoenix>
Download mbox | patch
Permalink /patch/236445/
State New
Headers show

Comments

Axel Lin - April 14, 2013, 2:20 p.m.
Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
 drivers/rtc/rtc-pcf8583.c |   26 +++++++-------------------
 1 file changed, 7 insertions(+), 19 deletions(-)
Jingoo Han - April 15, 2013, 12:19 a.m.
On Sunday, April 14, 2013 11:20 PM, Axel Lin wrote:
> 
> Signed-off-by: Axel Lin <axel.lin@ingics.com>

Hi Axel Lin,

The similar patch was already submitted and will be 
merged to mm-tree.

http://lkml.org/lkml/2013/4/1/125


Best regards,
Jingoo Han

> ---
>  drivers/rtc/rtc-pcf8583.c |   26 +++++++-------------------
>  1 file changed, 7 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/rtc/rtc-pcf8583.c b/drivers/rtc/rtc-pcf8583.c
> index 5f97c61..cd4bddb 100644
> --- a/drivers/rtc/rtc-pcf8583.c
> +++ b/drivers/rtc/rtc-pcf8583.c
> @@ -39,7 +39,6 @@ struct pcf8583 {
>  #define CTRL_ALARM	0x02
>  #define CTRL_TIMER	0x01
> 
> -
>  static struct i2c_driver pcf8583_driver;
> 
>  #define get_ctrl(x)    ((struct pcf8583 *)i2c_get_clientdata(x))->ctrl
> @@ -268,39 +267,28 @@ static int pcf8583_probe(struct i2c_client *client,
>  				const struct i2c_device_id *id)
>  {
>  	struct pcf8583 *pcf8583;
> -	int err;
> 
>  	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
>  		return -ENODEV;
> 
> -	pcf8583 = kzalloc(sizeof(struct pcf8583), GFP_KERNEL);
> +	pcf8583 = devm_kzalloc(&client->dev, sizeof(struct pcf8583),
> +			       GFP_KERNEL);
>  	if (!pcf8583)
>  		return -ENOMEM;
> 
>  	i2c_set_clientdata(client, pcf8583);
> 
> -	pcf8583->rtc = rtc_device_register(pcf8583_driver.driver.name,
> -			&client->dev, &pcf8583_rtc_ops, THIS_MODULE);
> -
> -	if (IS_ERR(pcf8583->rtc)) {
> -		err = PTR_ERR(pcf8583->rtc);
> -		goto exit_kfree;
> -	}
> +	pcf8583->rtc = devm_rtc_device_register(&client->dev,
> +					   pcf8583_driver.driver.name,
> +					   &pcf8583_rtc_ops, THIS_MODULE);
> +	if (IS_ERR(pcf8583->rtc))
> +		return PTR_ERR(pcf8583->rtc);
> 
>  	return 0;
> -
> -exit_kfree:
> -	kfree(pcf8583);
> -	return err;
>  }
> 
>  static int pcf8583_remove(struct i2c_client *client)
>  {
> -	struct pcf8583 *pcf8583 = i2c_get_clientdata(client);
> -
> -	if (pcf8583->rtc)
> -		rtc_device_unregister(pcf8583->rtc);
> -	kfree(pcf8583);
>  	return 0;
>  }
> 
> --
> 1.7.10.4
>

Patch

diff --git a/drivers/rtc/rtc-pcf8583.c b/drivers/rtc/rtc-pcf8583.c
index 5f97c61..cd4bddb 100644
--- a/drivers/rtc/rtc-pcf8583.c
+++ b/drivers/rtc/rtc-pcf8583.c
@@ -39,7 +39,6 @@  struct pcf8583 {
 #define CTRL_ALARM	0x02
 #define CTRL_TIMER	0x01
 
-
 static struct i2c_driver pcf8583_driver;
 
 #define get_ctrl(x)    ((struct pcf8583 *)i2c_get_clientdata(x))->ctrl
@@ -268,39 +267,28 @@  static int pcf8583_probe(struct i2c_client *client,
 				const struct i2c_device_id *id)
 {
 	struct pcf8583 *pcf8583;
-	int err;
 
 	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
 		return -ENODEV;
 
-	pcf8583 = kzalloc(sizeof(struct pcf8583), GFP_KERNEL);
+	pcf8583 = devm_kzalloc(&client->dev, sizeof(struct pcf8583),
+			       GFP_KERNEL);
 	if (!pcf8583)
 		return -ENOMEM;
 
 	i2c_set_clientdata(client, pcf8583);
 
-	pcf8583->rtc = rtc_device_register(pcf8583_driver.driver.name,
-			&client->dev, &pcf8583_rtc_ops, THIS_MODULE);
-
-	if (IS_ERR(pcf8583->rtc)) {
-		err = PTR_ERR(pcf8583->rtc);
-		goto exit_kfree;
-	}
+	pcf8583->rtc = devm_rtc_device_register(&client->dev,
+					   pcf8583_driver.driver.name,
+					   &pcf8583_rtc_ops, THIS_MODULE);
+	if (IS_ERR(pcf8583->rtc))
+		return PTR_ERR(pcf8583->rtc);
 
 	return 0;
-
-exit_kfree:
-	kfree(pcf8583);
-	return err;
 }
 
 static int pcf8583_remove(struct i2c_client *client)
 {
-	struct pcf8583 *pcf8583 = i2c_get_clientdata(client);
-
-	if (pcf8583->rtc)
-		rtc_device_unregister(pcf8583->rtc);
-	kfree(pcf8583);
 	return 0;
 }