linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chanwoo Choi <cw00.choi@samsung.com>
To: Hans de Goede <hdegoede@redhat.com>,
	Sebastian Reichel <sre@kernel.org>, Chen-Yu Tsai <wens@csie.org>,
	MyungJoo Ham <myungjoo.ham@samsung.com>
Cc: "russianneuromancer @ ya . ru" <russianneuromancer@ya.ru>,
	linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 01/14] extcon: Add extcon_get_extcon_dev_by_cable_id function
Date: Mon, 19 Dec 2016 19:12:58 +0900	[thread overview]
Message-ID: <5857B2AA.3030403@samsung.com> (raw)
In-Reply-To: <20161219000731.10188-2-hdegoede@redhat.com>

Hi Hans,

On 2016년 12월 19일 09:07, Hans de Goede wrote:
> extcon_register_notifier() allows passing in a NULL pointer for the
> extcon_device, so that extcon consumers which want extcon events of a
> certain type, but do not know the extcon device name (e.g. because
> there are different implementation depending on the board), can still
> get such events.
> 
> But most drivers will also want to know the initial state of the cable.
> Rather then adding NULL edev argument support to extcon_get_state, which
> would require looking up the right edev each call, this commit allows
> drivers to get the first extcon device with a requested cable-id through
> a new extcon_get_extcon_dev_by_cable_id function.
> 
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
>  drivers/extcon/extcon.c | 24 ++++++++++++++++++++++++
>  include/linux/extcon.h  |  1 +
>  2 files changed, 25 insertions(+)
> 
> diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c
> index 7829846..505c272 100644
> --- a/drivers/extcon/extcon.c
> +++ b/drivers/extcon/extcon.c
> @@ -890,6 +890,30 @@ struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name)
>  EXPORT_SYMBOL_GPL(extcon_get_extcon_dev);
>  
>  /**
> + * extcon_get_extcon_dev_by_cable_id() - Get an extcon device by a cable id
> + * @id:		the unique id of each external connector in extcon enumeration.
> + */
> +struct extcon_dev *extcon_get_extcon_dev_by_cable_id(unsigned int id)
> +{
> +	struct extcon_dev *extd;
> +	int idx = -EINVAL;
> +
> +	mutex_lock(&extcon_dev_list_lock);
> +	list_for_each_entry(extd, &extcon_dev_list, entry) {
> +		idx = find_cable_index_by_id(extd, id);
> +		if (idx >= 0)
> +			break;
> +	}
> +	mutex_unlock(&extcon_dev_list_lock);
> +
> +	if (idx < 0)
> +		return NULL;
> +
> +	return extd;
> +}
> +EXPORT_SYMBOL_GPL(extcon_get_extcon_dev_by_cable_id);

This function do not guarantee the same operation on all of case.

For example,
The h/w board has multiple extcon provider which support the same external connector. When using this function, this function don't get the correct extcon instance. Just, this function returns the first extcon instance in the registered extcon list.

This function has the potential problem.

> +
> +/**
>   * extcon_register_notifier() - Register a notifiee to get notified by
>   *				any attach status changes from the extcon.
>   * @edev:	the extcon device that has the external connecotr.
> diff --git a/include/linux/extcon.h b/include/linux/extcon.h
> index b871c0c..51abda8 100644
> --- a/include/linux/extcon.h
> +++ b/include/linux/extcon.h
> @@ -230,6 +230,7 @@ extern int devm_extcon_dev_register(struct device *dev,
>  extern void devm_extcon_dev_unregister(struct device *dev,
>  				       struct extcon_dev *edev);
>  extern struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name);
> +extern struct extcon_dev *extcon_get_extcon_dev_by_cable_id(unsigned int id);
>  
>  /*
>   * Following APIs control the memory of extcon device.
> 


-- 
Regards,
Chanwoo Choi

  reply	other threads:[~2016-12-19 10:13 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-19  0:07 [PATCH 00/14] extcon api extension + axp288_charger fixes Hans de Goede
2016-12-19  0:07 ` [PATCH 01/14] extcon: Add extcon_get_extcon_dev_by_cable_id function Hans de Goede
2016-12-19 10:12   ` Chanwoo Choi [this message]
2016-12-19 11:42     ` Hans de Goede
2016-12-19 11:57       ` Chanwoo Choi
2016-12-19  0:07 ` [PATCH 02/14] extcon: Make extcon_register_notifier use extcon_get_extcon_dev_by_cable_id Hans de Goede
2016-12-19  0:07 ` [PATCH 03/14] power: supply: axp288_charger: Make charger_init_hw_regs propagate i2c errors Hans de Goede
2016-12-19  0:07 ` [PATCH 04/14] power: supply: axp288_charger: Drop platform_data dependency Hans de Goede
2016-12-19  0:07 ` [PATCH 05/14] power: supply: axp288_charger: use devm extcon / supply register Hans de Goede
2016-12-19  8:03   ` Chanwoo Choi
2016-12-19  8:42     ` Hans de Goede
2016-12-19  0:07 ` [PATCH 06/14] power: supply: axp288_charger: Register extcon notifers after power_supply Hans de Goede
2016-12-19  0:07 ` [PATCH 07/14] power: supply: axp288_charger: Move init_hw_regs call before supply registration Hans de Goede
2016-12-19  0:07 ` [PATCH 08/14] power: supply: axp288_charger: Actually get and use the USB_HOST extcon device Hans de Goede
2016-12-19 10:16   ` Chanwoo Choi
2016-12-19  0:07 ` [PATCH 09/14] power: supply: axp288_charger: Handle charger type changing without disconnect Hans de Goede
2016-12-19  0:07 ` [PATCH 10/14] power: supply: axp288_charger: Some minor cleanups Hans de Goede
2016-12-19  0:07 ` [PATCH 11/14] power: supply: axp288_charger: Get and process initial hardware-state Hans de Goede
2016-12-19  0:07 ` [PATCH 12/14] power: supply: axp288_charger: Fix wrong regmap_update_bits Hans de Goede
2016-12-19  0:07 ` [PATCH 13/14] power: supply: axp288_charger: Remove unnecessary irq?_en register writes Hans de Goede
2016-12-19  0:07 ` [PATCH 14/14] power: supply: axp288_charger: Fix the module not auto-loading Hans de Goede

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=5857B2AA.3030403@samsung.com \
    --to=cw00.choi@samsung.com \
    --cc=hdegoede@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=myungjoo.ham@samsung.com \
    --cc=russianneuromancer@ya.ru \
    --cc=sre@kernel.org \
    --cc=wens@csie.org \
    /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;
as well as URLs for NNTP newsgroup(s).