From be31cc0bc9e6d24d7bd069a4eae81aa9fcf5d2cd Mon Sep 17 00:00:00 2001 From: Alexey Khoroshilov Date: Mon, 5 Nov 2012 17:11:41 +0900 Subject: [PATCH 01/12] extcon: arizona: unlock mutex on error path in arizona_micdet() If regmap_read() failed, arizona_micdet() returns IRQ_NONE leaving &info->lock mutex locked as opposed to all other return paths. Found by Linux Driver Verification project (linuxtesting.org). Signed-off-by: Alexey Khoroshilov Acked-by: Mark Brown Signed-off-by: Chanwoo Choi Signed-off-by: Myungjoo Ham --- drivers/extcon/extcon-arizona.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/extcon/extcon-arizona.c b/drivers/extcon/extcon-arizona.c index cdab9e59829..d876a54a8bd 100644 --- a/drivers/extcon/extcon-arizona.c +++ b/drivers/extcon/extcon-arizona.c @@ -166,6 +166,7 @@ static irqreturn_t arizona_micdet(int irq, void *data) ret = regmap_read(arizona->regmap, ARIZONA_MIC_DETECT_3, &val); if (ret != 0) { dev_err(arizona->dev, "Failed to read MICDET: %d\n", ret); + mutex_unlock(&info->lock); return IRQ_NONE; } From d851718f65d646c5033a28fa60631440c6dc0d4f Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Thu, 8 Nov 2012 18:39:41 +0900 Subject: [PATCH 02/12] extcon: Add missing header file to extcon.h This patch add missing header file(sysfs.h/device.h) to extcon.h because 'struct extcon_dev' define attribute field(attr_g_muex/ attrs_muex/d_attrs_mues) and device_type field(extcon_dev_type). Signed-off-by: Chanwoo Choi Signed-off-by: Myungjoo Ham --- include/linux/extcon.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/linux/extcon.h b/include/linux/extcon.h index 2c26c14cd71..54c00ce9ce7 100644 --- a/include/linux/extcon.h +++ b/include/linux/extcon.h @@ -23,7 +23,9 @@ #ifndef __LINUX_EXTCON_H__ #define __LINUX_EXTCON_H__ +#include #include +#include #define SUPPORTED_CABLE_MAX 32 #define CABLE_NAME_MAX 30 From c0c078c363a578543826bb8bfc9af47c7cc9321b Mon Sep 17 00:00:00 2001 From: Sachin Kamat Date: Tue, 20 Nov 2012 16:30:31 +0900 Subject: [PATCH 03/12] extcon: Fix return value in extcon-class.c Return the value obtained from the function extcon_register_interest instead of -ENODEV. Signed-off-by: Sachin Kamat Signed-off-by: Chanwoo Choi Signed-off-by: Myungjoo Ham --- drivers/extcon/extcon-class.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/extcon/extcon-class.c b/drivers/extcon/extcon-class.c index d398821097f..60adc04b056 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 -ENODEV; + return obj->cable_index; obj->user_nb = nb; From 68c9274d0fd1f66c6d105c52a61268d943e30862 Mon Sep 17 00:00:00 2001 From: Sachin Kamat Date: Tue, 20 Nov 2012 15:46:41 +0900 Subject: [PATCH 04/12] 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 Signed-off-by: Chanwoo Choi Signed-off-by: Myungjoo Ham --- drivers/extcon/extcon-max8997.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/extcon/extcon-max8997.c b/drivers/extcon/extcon-max8997.c index 77b66b0cc8f..a46c82f3183 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, From 00af4b16e098f7899d78c7009f0b525c9c512f94 Mon Sep 17 00:00:00 2001 From: Sachin Kamat Date: Tue, 20 Nov 2012 15:46:44 +0900 Subject: [PATCH 05/12] 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 Signed-off-by: Chanwoo Choi Signed-off-by: Myungjoo Ham --- drivers/extcon/extcon-max77693.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/extcon/extcon-max77693.c b/drivers/extcon/extcon-max77693.c index a17d0d91ada..2a0f397885f 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: From 1967fa08d902cbf1967a29acd2e82628cfb7c7f4 Mon Sep 17 00:00:00 2001 From: Sachin Kamat Date: Wed, 21 Nov 2012 10:04:58 +0530 Subject: [PATCH 06/12] extcon: max77693: Fix coding style As per kernel coding style, if one branch of conditional statement has braces, the other one should have too. Signed-off-by: Sachin Kamat --- drivers/extcon/extcon-max77693.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/extcon/extcon-max77693.c b/drivers/extcon/extcon-max77693.c index 2a0f397885f..d844be3009f 100644 --- a/drivers/extcon/extcon-max77693.c +++ b/drivers/extcon/extcon-max77693.c @@ -665,9 +665,9 @@ static int __devinit max77693_muic_probe(struct platform_device *pdev) } info->dev = &pdev->dev; info->max77693 = max77693; - if (info->max77693->regmap_muic) + if (info->max77693->regmap_muic) { dev_dbg(&pdev->dev, "allocate register map\n"); - else { + } else { info->max77693->regmap_muic = devm_regmap_init_i2c( info->max77693->muic, &max77693_muic_regmap_config); From 8117cc3a0cf31533b31fb106663c2529410726df Mon Sep 17 00:00:00 2001 From: Sachin Kamat Date: Tue, 20 Nov 2012 15:46:30 +0900 Subject: [PATCH 07/12] 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 Signed-off-by: Chanwoo Choi Signed-off-by: Myungjoo Ham --- drivers/extcon/extcon-max8997.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/extcon/extcon-max8997.c b/drivers/extcon/extcon-max8997.c index a46c82f3183..f06e60a3cb8 100644 --- a/drivers/extcon/extcon-max8997.c +++ b/drivers/extcon/extcon-max8997.c @@ -459,7 +459,7 @@ static int __devinit max8997_muic_probe(struct platform_device *pdev) } 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, From 2ca36f4afd0b0c3b9f99e1c03bbfafeb39516cf6 Mon Sep 17 00:00:00 2001 From: Sachin Kamat Date: Tue, 20 Nov 2012 15:46:33 +0900 Subject: [PATCH 08/12] extcon: max8997: Fix a typo Electrnoics -> Electronics Signed-off-by: Sachin Kamat Signed-off-by: Chanwoo Choi Signed-off-by: Myungjoo Ham --- drivers/extcon/extcon-max8997.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/extcon/extcon-max8997.c b/drivers/extcon/extcon-max8997.c index f06e60a3cb8..ffdbe8c962a 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 * * This program is free software; you can redistribute it and/or modify From 0b672e9b21942fdfa63519fb66df4a40d6fafe35 Mon Sep 17 00:00:00 2001 From: Sachin Kamat Date: Tue, 20 Nov 2012 15:46:47 +0900 Subject: [PATCH 09/12] 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 Signed-off-by: Chanwoo Choi Signed-off-by: Myungjoo Ham --- drivers/extcon/extcon-max8997.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/drivers/extcon/extcon-max8997.c b/drivers/extcon/extcon-max8997.c index ffdbe8c962a..8059325ce7d 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; } From f4bb5cb54eb97fee9b4e076df8df68b91861b934 Mon Sep 17 00:00:00 2001 From: Sachin Kamat Date: Tue, 20 Nov 2012 15:46:50 +0900 Subject: [PATCH 10/12] 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 Signed-off-by: Chanwoo Choi Signed-off-by: Myungjoo Ham --- drivers/extcon/extcon-max77693.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/drivers/extcon/extcon-max77693.c b/drivers/extcon/extcon-max77693.c index d844be3009f..93ca93f26f4 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; } From 3bf742ffd48e7d1cea864741a123203207b33b80 Mon Sep 17 00:00:00 2001 From: Sachin Kamat Date: Wed, 21 Nov 2012 10:04:57 +0530 Subject: [PATCH 11/12] extcon: max77693: Fix uninitialised variable warning Signed-off-by: Sachin Kamat --- drivers/extcon/extcon-max77693.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/extcon/extcon-max77693.c b/drivers/extcon/extcon-max77693.c index 93ca93f26f4..8bf5e4835b4 100644 --- a/drivers/extcon/extcon-max77693.c +++ b/drivers/extcon/extcon-max77693.c @@ -672,9 +672,10 @@ 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); - return PTR_ERR(info->max77693->regmap_muic); + return ret; } } platform_set_drvdata(pdev, info); From df072eb97dcfb819390227649f6b7c07a90aa2df Mon Sep 17 00:00:00 2001 From: MyungJoo Ham Date: Tue, 20 Nov 2012 19:22:33 +0900 Subject: [PATCH 12/12] extcon: kernel_doc style fix Corrected kernel_doc entries. Signed-off-by: MyungJoo Ham --- include/linux/extcon.h | 48 +++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/include/linux/extcon.h b/include/linux/extcon.h index 54c00ce9ce7..fcb51c88319 100644 --- a/include/linux/extcon.h +++ b/include/linux/extcon.h @@ -76,12 +76,12 @@ struct extcon_cable; /** * struct extcon_dev - An extcon device represents one external connector. - * @name The name of this extcon device. Parent device name is used + * @name: The name of this extcon device. Parent device name is used * if NULL. - * @supported_cable Array of supported cable names ending with NULL. + * @supported_cable: Array of supported cable names ending with NULL. * If supported_cable is NULL, cable name related APIs * are disabled. - * @mutually_exclusive Array of mutually exclusive set of cables that cannot + * @mutually_exclusive: Array of mutually exclusive set of cables that cannot * be attached simultaneously. The array should be * ending with NULL or be NULL (no mutually exclusive * cables). For example, if it is { 0x7, 0x30, 0}, then, @@ -89,21 +89,21 @@ struct extcon_cable; * be attached simulataneously. {0x7, 0} is equivalent to * {0x3, 0x6, 0x5, 0}. If it is {0xFFFFFFFF, 0}, there * can be no simultaneous connections. - * @print_name An optional callback to override the method to print the + * @print_name: An optional callback to override the method to print the * name of the extcon device. - * @print_state An optional callback to override the method to print the + * @print_state: An optional callback to override the method to print the * status of the extcon device. - * @dev Device of this extcon. Do not provide at register-time. - * @state Attach/detach state of this extcon. Do not provide at + * @dev: Device of this extcon. Do not provide at register-time. + * @state: Attach/detach state of this extcon. Do not provide at * register-time - * @nh Notifier for the state change events from this extcon - * @entry To support list of extcon devices so that users can search + * @nh: Notifier for the state change events from this extcon + * @entry: To support list of extcon devices so that users can search * for extcon devices based on the extcon name. - * @lock - * @max_supported Internal value to store the number of cables. - * @extcon_dev_type Device_type struct to provide attribute_groups + * @lock: + * @max_supported: Internal value to store the number of cables. + * @extcon_dev_type: Device_type struct to provide attribute_groups * customized for each extcon device. - * @cables Sysfs subdirectories. Each represents one cable. + * @cables: Sysfs subdirectories. Each represents one cable. * * In most cases, users only need to provide "User initializing data" of * this struct when registering an extcon. In some exceptional cases, @@ -139,12 +139,12 @@ struct extcon_dev { /** * struct extcon_cable - An internal data for each cable of extcon device. - * @edev The extcon device - * @cable_index Index of this cable in the edev - * @attr_g Attribute group for the cable - * @attr_name "name" sysfs entry - * @attr_state "state" sysfs entry - * @attrs Array pointing to attr_name and attr_state for attr_g + * @edev: The extcon device + * @cable_index: Index of this cable in the edev + * @attr_g: Attribute group for the cable + * @attr_name: "name" sysfs entry + * @attr_state: "state" sysfs entry + * @attrs: Array pointing to attr_name and attr_state for attr_g */ struct extcon_cable { struct extcon_dev *edev; @@ -160,11 +160,11 @@ struct extcon_cable { /** * struct extcon_specific_cable_nb - An internal data for * extcon_register_interest(). - * @internal_nb a notifier block bridging extcon notifier and cable notifier. - * @user_nb user provided notifier block for events from a specific cable. - * @cable_index the target cable. - * @edev the target extcon device. - * @previous_value the saved previous event value. + * @internal_nb: a notifier block bridging extcon notifier and cable notifier. + * @user_nb: user provided notifier block for events from a specific cable. + * @cable_index: the target cable. + * @edev: the target extcon device. + * @previous_value: the saved previous event value. */ struct extcon_specific_cable_nb { struct notifier_block internal_nb;