2012-11-20 05:28:55

by Sachin Kamat

[permalink] [raw]
Subject: [PATCH 0/7] extcon: Fixes and code updates

This series is build tested and based on linux-next (20121115) and extcon
tree at git://git.kernel.org/pub/scm/linux/kernel/git/chanwoo/extcon.git

Sachin Kamat (7):
extcon: max8997: Fix checkpatch error
extcon: max8997: Fix a typo
extcon: Fix return value in extcon-class.c
extcon: max8997: Fix incorrect error check and return value
extcon: max77693: Fix incorrect error check and return value
extcon: max8997: Use devm_kzalloc
extcon: max77693: Use devm_kzalloc

drivers/extcon/extcon-class.c | 2 +-
drivers/extcon/extcon-max77693.c | 33 ++++++++++++++-------------------
drivers/extcon/extcon-max8997.c | 28 ++++++++++++----------------
3 files changed, 27 insertions(+), 36 deletions(-)

--
1.7.4.1


2012-11-20 05:28:59

by Sachin Kamat

[permalink] [raw]
Subject: [PATCH 1/7] extcon: max8997: Fix checkpatch error

Fixes the following checkpatch error:
ERROR: space required after that ',' (ctx:VxV)
460: FILE: extcon/extcon-max8997.c:460:
ret = request_threaded_irq(virq, NULL,max8997_muic_irq_handler,
^

Signed-off-by: Sachin Kamat <[email protected]>
---
drivers/extcon/extcon-max8997.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/extcon/extcon-max8997.c b/drivers/extcon/extcon-max8997.c
index 77b66b0..c364794 100644
--- a/drivers/extcon/extcon-max8997.c
+++ b/drivers/extcon/extcon-max8997.c
@@ -457,7 +457,7 @@ static int __devinit max8997_muic_probe(struct platform_device *pdev)
goto err_irq;
muic_irq->virq = virq;

- ret = request_threaded_irq(virq, NULL,max8997_muic_irq_handler,
+ ret = request_threaded_irq(virq, NULL, max8997_muic_irq_handler,
0, muic_irq->name, info);
if (ret) {
dev_err(&pdev->dev,
--
1.7.4.1

2012-11-20 05:29:08

by Sachin Kamat

[permalink] [raw]
Subject: [PATCH 3/7] extcon: Fix return value in extcon-class.c

Return the value obtained from the function extcon_register_interest
instead of -EINVAL.

Silences the following warning:
drivers/extcon/extcon-class.c:475 extcon_register_interest() info:
why not propagate 'obj->cable_index' from extcon_find_cable_index()
instead of -22?

Signed-off-by: Sachin Kamat <[email protected]>
---
drivers/extcon/extcon-class.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/extcon/extcon-class.c b/drivers/extcon/extcon-class.c
index 8e577ed..60adc04 100644
--- a/drivers/extcon/extcon-class.c
+++ b/drivers/extcon/extcon-class.c
@@ -472,7 +472,7 @@ int extcon_register_interest(struct extcon_specific_cable_nb *obj,

obj->cable_index = extcon_find_cable_index(obj->edev, cable_name);
if (obj->cable_index < 0)
- return -EINVAL;
+ return obj->cable_index;

obj->user_nb = nb;

--
1.7.4.1

2012-11-20 05:29:19

by Sachin Kamat

[permalink] [raw]
Subject: [PATCH 7/7] extcon: max77693: Use devm_kzalloc

devm_kzalloc() is a device managed function. It makes error handling
and cleanup code a bit simpler.

Signed-off-by: Sachin Kamat <[email protected]>
---
drivers/extcon/extcon-max77693.c | 23 ++++++++---------------
1 files changed, 8 insertions(+), 15 deletions(-)

diff --git a/drivers/extcon/extcon-max77693.c b/drivers/extcon/extcon-max77693.c
index 2a0f397..3c29bb7 100644
--- a/drivers/extcon/extcon-max77693.c
+++ b/drivers/extcon/extcon-max77693.c
@@ -657,11 +657,11 @@ static int __devinit max77693_muic_probe(struct platform_device *pdev)
int ret, i;
u8 id;

- info = kzalloc(sizeof(struct max77693_muic_info), GFP_KERNEL);
+ info = devm_kzalloc(&pdev->dev, sizeof(struct max77693_muic_info),
+ GFP_KERNEL);
if (!info) {
dev_err(&pdev->dev, "failed to allocate memory\n");
- ret = -ENOMEM;
- goto err_kfree;
+ return -ENOMEM;
}
info->dev = &pdev->dev;
info->max77693 = max77693;
@@ -672,10 +672,9 @@ static int __devinit max77693_muic_probe(struct platform_device *pdev)
info->max77693->muic,
&max77693_muic_regmap_config);
if (IS_ERR(info->max77693->regmap_muic)) {
- ret = PTR_ERR(info->max77693->regmap_muic);
dev_err(max77693->dev,
"failed to allocate register map: %d\n", ret);
- goto err_regmap;
+ return PTR_ERR(info->max77693->regmap_muic);
}
}
platform_set_drvdata(pdev, info);
@@ -709,7 +708,8 @@ static int __devinit max77693_muic_probe(struct platform_device *pdev)
}

/* Initialize extcon device */
- info->edev = kzalloc(sizeof(struct extcon_dev), GFP_KERNEL);
+ info->edev = devm_kzalloc(&pdev->dev, sizeof(struct extcon_dev),
+ GFP_KERNEL);
if (!info->edev) {
dev_err(&pdev->dev, "failed to allocate memory for extcon\n");
ret = -ENOMEM;
@@ -720,7 +720,7 @@ static int __devinit max77693_muic_probe(struct platform_device *pdev)
ret = extcon_dev_register(info->edev, NULL);
if (ret) {
dev_err(&pdev->dev, "failed to register extcon device\n");
- goto err_extcon;
+ goto err_irq;
}

/* Initialize MUIC register by using platform data */
@@ -753,7 +753,7 @@ static int __devinit max77693_muic_probe(struct platform_device *pdev)
MAX77693_MUIC_REG_ID, &id);
if (ret < 0) {
dev_err(&pdev->dev, "failed to read revision number\n");
- goto err_extcon;
+ goto err_irq;
}
dev_info(info->dev, "device ID : 0x%x\n", id);

@@ -765,14 +765,9 @@ static int __devinit max77693_muic_probe(struct platform_device *pdev)

return ret;

-err_extcon:
- kfree(info->edev);
err_irq:
while (--i >= 0)
free_irq(muic_irqs[i].virq, info);
-err_regmap:
- kfree(info);
-err_kfree:
return ret;
}

@@ -785,8 +780,6 @@ static int __devexit max77693_muic_remove(struct platform_device *pdev)
free_irq(muic_irqs[i].virq, info);
cancel_work_sync(&info->irq_work);
extcon_dev_unregister(info->edev);
- kfree(info->edev);
- kfree(info);

return 0;
}
--
1.7.4.1

2012-11-20 05:29:15

by Sachin Kamat

[permalink] [raw]
Subject: [PATCH 5/7] extcon: max77693: Fix incorrect error check and return value

irq_create_mapping() returns 0 if it fails to provide a valid irq number.
'ret' needs to be updated with a negative error code before returning from
probe to signal probe failure. While at it, also corrected the 'virq' type to
unsigned from signed.

Signed-off-by: Sachin Kamat <[email protected]>
---
drivers/extcon/extcon-max77693.c | 10 ++++++----
1 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/extcon/extcon-max77693.c b/drivers/extcon/extcon-max77693.c
index a17d0d9..2a0f397 100644
--- a/drivers/extcon/extcon-max77693.c
+++ b/drivers/extcon/extcon-max77693.c
@@ -686,11 +686,13 @@ static int __devinit max77693_muic_probe(struct platform_device *pdev)
/* Support irq domain for MAX77693 MUIC device */
for (i = 0; i < ARRAY_SIZE(muic_irqs); i++) {
struct max77693_muic_irq *muic_irq = &muic_irqs[i];
- int virq = 0;
+ unsigned int virq = 0;

virq = irq_create_mapping(max77693->irq_domain, muic_irq->irq);
- if (!virq)
+ if (!virq) {
+ ret = -EINVAL;
goto err_irq;
+ }
muic_irq->virq = virq;

ret = request_threaded_irq(virq, NULL,
@@ -702,8 +704,6 @@ static int __devinit max77693_muic_probe(struct platform_device *pdev)
" error :%d)\n",
muic_irq->irq, ret);

- for (i = i - 1; i >= 0; i--)
- free_irq(muic_irq->virq, info);
goto err_irq;
}
}
@@ -768,6 +768,8 @@ static int __devinit max77693_muic_probe(struct platform_device *pdev)
err_extcon:
kfree(info->edev);
err_irq:
+ while (--i >= 0)
+ free_irq(muic_irqs[i].virq, info);
err_regmap:
kfree(info);
err_kfree:
--
1.7.4.1

2012-11-20 05:29:44

by Sachin Kamat

[permalink] [raw]
Subject: [PATCH 6/7] extcon: max8997: Use devm_kzalloc

devm_kzalloc() is a device managed function. It makes error handling
and cleanup code a bit simpler.

Signed-off-by: Sachin Kamat <[email protected]>
---
drivers/extcon/extcon-max8997.c | 18 ++++++------------
1 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/drivers/extcon/extcon-max8997.c b/drivers/extcon/extcon-max8997.c
index ffdbe8c..8059325 100644
--- a/drivers/extcon/extcon-max8997.c
+++ b/drivers/extcon/extcon-max8997.c
@@ -433,11 +433,11 @@ static int __devinit max8997_muic_probe(struct platform_device *pdev)
struct max8997_muic_info *info;
int ret, i;

- info = kzalloc(sizeof(struct max8997_muic_info), GFP_KERNEL);
+ info = devm_kzalloc(&pdev->dev, sizeof(struct max8997_muic_info),
+ GFP_KERNEL);
if (!info) {
dev_err(&pdev->dev, "failed to allocate memory\n");
- ret = -ENOMEM;
- goto err_kfree;
+ return -ENOMEM;
}

info->dev = &pdev->dev;
@@ -471,7 +471,8 @@ static int __devinit max8997_muic_probe(struct platform_device *pdev)
}

/* External connector */
- info->edev = kzalloc(sizeof(struct extcon_dev), GFP_KERNEL);
+ info->edev = devm_kzalloc(&pdev->dev, sizeof(struct extcon_dev),
+ GFP_KERNEL);
if (!info->edev) {
dev_err(&pdev->dev, "failed to allocate memory for extcon\n");
ret = -ENOMEM;
@@ -482,7 +483,7 @@ static int __devinit max8997_muic_probe(struct platform_device *pdev)
ret = extcon_dev_register(info->edev, NULL);
if (ret) {
dev_err(&pdev->dev, "failed to register extcon device\n");
- goto err_extcon;
+ goto err_irq;
}

/* Initialize registers according to platform data */
@@ -500,13 +501,9 @@ static int __devinit max8997_muic_probe(struct platform_device *pdev)

return ret;

-err_extcon:
- kfree(info->edev);
err_irq:
while (--i >= 0)
free_irq(muic_irqs[i].virq, info);
- kfree(info);
-err_kfree:
return ret;
}

@@ -521,9 +518,6 @@ static int __devexit max8997_muic_remove(struct platform_device *pdev)

extcon_dev_unregister(info->edev);

- kfree(info->edev);
- kfree(info);
-
return 0;
}

--
1.7.4.1

2012-11-20 05:29:07

by Sachin Kamat

[permalink] [raw]
Subject: [PATCH 2/7] extcon: max8997: Fix a typo

Electrnoics -> Electronics

Signed-off-by: Sachin Kamat <[email protected]>
---
drivers/extcon/extcon-max8997.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/extcon/extcon-max8997.c b/drivers/extcon/extcon-max8997.c
index c364794..af8a5bc 100644
--- a/drivers/extcon/extcon-max8997.c
+++ b/drivers/extcon/extcon-max8997.c
@@ -1,7 +1,7 @@
/*
* extcon-max8997.c - MAX8997 extcon driver to support MAX8997 MUIC
*
- * Copyright (C) 2012 Samsung Electrnoics
+ * Copyright (C) 2012 Samsung Electronics
* Donggeun Kim <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
--
1.7.4.1

2012-11-20 05:30:15

by Sachin Kamat

[permalink] [raw]
Subject: [PATCH 4/7] extcon: max8997: Fix incorrect error check and return value

irq_create_mapping() returns 0 if it fails to provide a valid irq number.
'ret' needs to be updated with a negative error code before returning from
probe to signal probe failure. While at it, also corrected the 'virq' type to
unsigned from signed.

Signed-off-by: Sachin Kamat <[email protected]>
---
drivers/extcon/extcon-max8997.c | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/extcon/extcon-max8997.c b/drivers/extcon/extcon-max8997.c
index af8a5bc..ffdbe8c 100644
--- a/drivers/extcon/extcon-max8997.c
+++ b/drivers/extcon/extcon-max8997.c
@@ -450,11 +450,13 @@ static int __devinit max8997_muic_probe(struct platform_device *pdev)

for (i = 0; i < ARRAY_SIZE(muic_irqs); i++) {
struct max8997_muic_irq *muic_irq = &muic_irqs[i];
- int virq = 0;
+ unsigned int virq = 0;

virq = irq_create_mapping(max8997->irq_domain, muic_irq->irq);
- if (!virq)
+ if (!virq) {
+ ret = -EINVAL;
goto err_irq;
+ }
muic_irq->virq = virq;

ret = request_threaded_irq(virq, NULL, max8997_muic_irq_handler,
--
1.7.4.1

2012-11-20 07:54:33

by Chanwoo Choi

[permalink] [raw]
Subject: Re: [PATCH 0/7] extcon: Fixes and code updates

On 11/20/2012 02:22 PM, Sachin Kamat wrote:
> This series is build tested and based on linux-next (20121115) and extcon
> tree at git://git.kernel.org/pub/scm/linux/kernel/git/chanwoo/extcon.git
>
> Sachin Kamat (7):
> extcon: max8997: Fix checkpatch error
> extcon: max8997: Fix a typo
> extcon: Fix return value in extcon-class.c
> extcon: max8997: Fix incorrect error check and return value
> extcon: max77693: Fix incorrect error check and return value
> extcon: max8997: Use devm_kzalloc
> extcon: max77693: Use devm_kzalloc
>
> drivers/extcon/extcon-class.c | 2 +-
> drivers/extcon/extcon-max77693.c | 33 ++++++++++++++-------------------
> drivers/extcon/extcon-max8997.c | 28 ++++++++++++----------------
> 3 files changed, 27 insertions(+), 36 deletions(-)
>
Applied, thanks.

You can check this patch on extcon tree:
- git://git.kernel.org/pub/scm/linux/kernel/git/chanwoo/extcon.git (for-next branch)

Chanwoo Choi

2012-11-20 07:54:43

by Chanwoo Choi

[permalink] [raw]
Subject: Re: [PATCH 3/7] extcon: Fix return value in extcon-class.c

On 11/20/2012 02:22 PM, Sachin Kamat wrote:
> Return the value obtained from the function extcon_register_interest
> instead of -EINVAL.
>
> Silences the following warning:
> drivers/extcon/extcon-class.c:475 extcon_register_interest() info:
> why not propagate 'obj->cable_index' from extcon_find_cable_index()
> instead of -22?
>
> Signed-off-by: Sachin Kamat <[email protected]>
> ---

I consolidate following two patches because of similar patch.

extcon: Fix return value in extcon-class.c
extcon: Redo: Fix return value in extcon_register_interest()

Thank you,
Chanwoo Choi

2012-11-20 08:03:51

by Sachin Kamat

[permalink] [raw]
Subject: Re: [PATCH 3/7] extcon: Fix return value in extcon-class.c

On 20 November 2012 13:24, Chanwoo Choi <[email protected]> wrote:
> On 11/20/2012 02:22 PM, Sachin Kamat wrote:
>> Return the value obtained from the function extcon_register_interest
>> instead of -EINVAL.
>>
>> Silences the following warning:
>> drivers/extcon/extcon-class.c:475 extcon_register_interest() info:
>> why not propagate 'obj->cable_index' from extcon_find_cable_index()
>> instead of -22?
>>
>> Signed-off-by: Sachin Kamat <[email protected]>
>> ---
>
> I consolidate following two patches because of similar patch.
>
> extcon: Fix return value in extcon-class.c
> extcon: Redo: Fix return value in extcon_register_interest()

You are right. Fair enough.

>
> Thank you,
> Chanwoo Choi



--
With warm regards,
Sachin