From: Sangjung <sangjung.woo@samsung.com>
To: Chanwoo Choi <cwchoi00@gmail.com>
Cc: MyungJoo Ham <myungjoo.ham@samsung.com>,
Chanwoo Choi <cw00.choi@samsung.com>,
linux-kernel <linux-kernel@vger.kernel.org>,
Krzysztof Kozlowski <k.kozlowski@samsung.com>,
Seung-Woo Kim <sw0312.kim@samsung.com>
Subject: Re: [PATCHv2 1/8] extcon: Add resource-managed extcon register function
Date: Fri, 18 Apr 2014 09:12:32 +0900 [thread overview]
Message-ID: <53506DF0.8050209@samsung.com> (raw)
In-Reply-To: <CAGTfZH1YtzQ0jZS3N-JgX8GYzSx753v_yO0dYM_E+B1bnJvqEQ@mail.gmail.com>
Hi Chanwoo
On 04/18/2014 12:26 AM, Chanwoo Choi wrote:
> Hi Sangjung,
>
> This patch(v2) is same as previous patch(v1).
> I think you sent previous patch(v1) instead of v2.
You're right. I made a big mistake.
I will send the fixed one as v3.
Thank you.
Sangjung
>
> Thanks
> Chanwoo Choi
>
> On Thu, Apr 17, 2014 at 7:09 PM, Sangjung Woo <sangjung.woo@samsung.com> wrote:
>> Add resource-managed extcon device register function for convenience.
>> For example, if a extcon device is attached with new
>> devm_extcon_dev_register(), that extcon device is automatically
>> unregistered on driver detach.
>>
>> Signed-off-by: Sangjung Woo <sangjung.woo@samsung.com>
>> ---
>> drivers/extcon/extcon-class.c | 83 +++++++++++++++++++++++++++++++++++++++++
>> include/linux/extcon.h | 8 ++++
>> 2 files changed, 91 insertions(+)
>>
>> diff --git a/drivers/extcon/extcon-class.c b/drivers/extcon/extcon-class.c
>> index 7ab21aa..accb49c 100644
>> --- a/drivers/extcon/extcon-class.c
>> +++ b/drivers/extcon/extcon-class.c
>> @@ -32,6 +32,7 @@
>> #include <linux/slab.h>
>> #include <linux/sysfs.h>
>> #include <linux/of.h>
>> +#include <linux/gfp.h>
>>
>> /*
>> * extcon_cable_name suggests the standard cable names for commonly used
>> @@ -819,6 +820,88 @@ void extcon_dev_unregister(struct extcon_dev *edev)
>> }
>> EXPORT_SYMBOL_GPL(extcon_dev_unregister);
>>
>> +
>> +/*
>> + * Device resource management
>> + */
>> +
>> +struct extcon_devres {
>> + struct extcon_dev *edev;
>> +};
>> +
>> +static void devm_extcon_release(struct device *dev, void *res)
>> +{
>> + struct extcon_devres *dr = (struct extcon_devres *)res;
>> +
>> + extcon_dev_unregister(dr->edev);
>> +}
>> +
>> +static int devm_extcon_match(struct device *dev, void *res, void *data)
>> +{
>> + struct extcon_devres *dr = (struct extcon_devres *)res;
>> + struct extcon_devres *match = (struct extcon_devres *)data;
>> +
>> + return dr->edev == match->edev;
>> +}
>> +
>> +/**
>> + * devm_extcon_dev_register() - Resource-managed extcon_dev_register()
>> + * @dev: device to allocate extcon device
>> + * @edev: the new extcon device to register
>> + *
>> + * Managed extcon_dev_register() function. If extcon device is attached with
>> + * this function, that extcon device is automatically unregistered on driver
>> + * detach. Internally this function calls extcon_dev_register() function.
>> + * To get more information, refer that function.
>> + *
>> + * If extcon device is registered with this function and the device needs to be
>> + * unregistered separately, devm_extcon_dev_unregister() should be used.
>> + *
>> + * RETURNS:
>> + * 0 on success, negative error number on failure.
>> + */
>> +int devm_extcon_dev_register(struct device *dev, struct extcon_dev *edev)
>> +{
>> + struct extcon_devres *dr;
>> + int rc;
>> +
>> + dr = devres_alloc(devm_extcon_release, sizeof(struct extcon_devres),
>> + GFP_KERNEL);
>> + if (!dr)
>> + return -ENOMEM;
>> +
>> + rc = extcon_dev_register(edev);
>> + if (rc) {
>> + devres_free(dr);
>> + return rc;
>> + }
>> +
>> + dr->edev = edev;
>> + devres_add(dev, dr);
>> +
>> + return 0;
>> +}
>> +EXPORT_SYMBOL_GPL(devm_extcon_dev_register);
>> +
>> +/**
>> + * devm_extcon_dev_unregister() - Resource-managed extcon_dev_unregister()
>> + * @dev: device the extcon belongs to
>> + * @edev: the extcon device to unregister
>> + *
>> + * Unregister extcon device that is registered with devm_extcon_dev_register()
>> + * function.
>> + */
>> +void devm_extcon_dev_unregister(struct device *dev, struct extcon_dev *edev)
>> +{
>> + struct extcon_devres match_dr = { edev };
>> +
>> + WARN_ON(devres_destroy(dev, devm_extcon_release,
>> + devm_extcon_match, &match_dr));
>> +
>> + extcon_dev_unregister(edev);
>> +}
>> +EXPORT_SYMBOL_GPL(devm_extcon_dev_unregister);
>> +
>> #ifdef CONFIG_OF
>> /*
>> * extcon_get_edev_by_phandle - Get the extcon device from devicetree
>> diff --git a/include/linux/extcon.h b/include/linux/extcon.h
>> index f488145..e1e85a1 100644
>> --- a/include/linux/extcon.h
>> +++ b/include/linux/extcon.h
>> @@ -188,6 +188,14 @@ extern void extcon_dev_unregister(struct extcon_dev *edev);
>> extern struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name);
>>
>> /*
>> + * Resource-managed extcon device register function.
>> + */
>> +extern int devm_extcon_dev_register(struct device *dev,
>> + struct extcon_dev *edev);
>> +extern void devm_extcon_dev_unregister(struct device *dev,
>> + struct extcon_dev *edev);
>> +
>> +/*
>> * get/set/update_state access the 32b encoded state value, which represents
>> * states of all possible cables of the multistate port. For example, if one
>> * calls extcon_set_state(edev, 0x7), it may mean that all the three cables
>> --
>> 1.7.9.5
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>> Please read the FAQ at http://www.tux.org/lkml/
next prev parent reply other threads:[~2014-04-18 0:12 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-17 10:09 [PATCHv2 0/8] Resource-managed extcon device register function Sangjung Woo
2014-04-17 10:09 ` [PATCHv2 1/8] extcon: Add resource-managed extcon " Sangjung Woo
2014-04-17 15:26 ` Chanwoo Choi
2014-04-18 0:12 ` Sangjung [this message]
2014-04-17 10:09 ` [PATCHv2 2/8] extcon: adc-jack: Use devm_extcon_dev_register() Sangjung Woo
2014-04-17 10:09 ` [PATCHv3 3/8] extcon: gpio: " Sangjung Woo
2014-04-17 10:09 ` [PATCHv2 4/8] extcon: max14577: " Sangjung Woo
2014-04-17 10:10 ` [PATCHv2 5/8] extcon: max77693: " Sangjung Woo
2014-04-17 10:10 ` [PATCHv2 6/8] extcon: max8997: " Sangjung Woo
2014-04-17 10:10 ` [PATCHv2 7/8] extcon: palmas: " Sangjung Woo
2014-04-17 10:10 ` [PATCHv2 8/8] extcon: arizona: " Sangjung Woo
2014-04-17 15:29 ` Chanwoo Choi
2014-04-18 0:09 ` Sangjung
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=53506DF0.8050209@samsung.com \
--to=sangjung.woo@samsung.com \
--cc=cw00.choi@samsung.com \
--cc=cwchoi00@gmail.com \
--cc=k.kozlowski@samsung.com \
--cc=linux-kernel@vger.kernel.org \
--cc=myungjoo.ham@samsung.com \
--cc=sw0312.kim@samsung.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