From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933235AbcLSKNN (ORCPT ); Mon, 19 Dec 2016 05:13:13 -0500 Received: from mailout1.samsung.com ([203.254.224.24]:45839 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932960AbcLSKNB (ORCPT ); Mon, 19 Dec 2016 05:13:01 -0500 MIME-version: 1.0 Content-type: text/plain; charset=UTF-8 X-AuditID: cbfee61b-f79d86d00000197e-35-5857b2ab6a22 Content-transfer-encoding: 8BIT Message-id: <5857B2AA.3030403@samsung.com> Date: Mon, 19 Dec 2016 19:12:58 +0900 From: Chanwoo Choi Organization: Samsung Electronics User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 To: Hans de Goede , Sebastian Reichel , Chen-Yu Tsai , MyungJoo Ham Cc: "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 References: <20161219000731.10188-1-hdegoede@redhat.com> <20161219000731.10188-2-hdegoede@redhat.com> In-reply-to: <20161219000731.10188-2-hdegoede@redhat.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrEIsWRmVeSWpSXmKPExsVy+t9jQd3Vm8IjDCa/Yrd4c3w6k8XlXXPY LD73HmG0uN24gs3i4tdFrBand5dY/Dx0nsmB3WPDo9WsHptWdbJ5vN93lc2jb8sqRo/Pm+Q8 Zi2UDGCLcrPJSE1MSS1SSM1Lzk/JzEu3VQoNcdO1UFLIS8xNtVWK0PUNCVJSKEvMKQXyjAzQ gINzgHuwkr5dgltG66N/7AXzJCrO3f3K3sB4X7iLkZNDQsBE4vC/B4wQtpjEhXvr2UBsIYFZ jBLf7/mB2LwCghI/Jt9j6WLk4GAWkJc4cikbJMwsoC4xad4i5i5GLqDyB4wSPdf+sUDUa0k8 2vMNzGYRUJU4/XMtK4jNBhTf/+IG2Hx+AUWJqz8eM4LMFBWIkOg+UQkyR0RgCqNE589D7BAL yiVWLzwCdpuwQLDEk18dTBDLdjNKfHq2E2wQp4ClxOm5P1gmMArOQnLrLIRbZyG5dQEj8ypG idSC5ILipPRco7zUcr3ixNzi0rx0veT83E2M4Ph7Jr2D8fAu90OMAhyMSjy8E7jDI4RYE8uK K3MPMUpwMCuJ8LavAQrxpiRWVqUW5ccXleakFh9iNAV6diKzlGhyPjA15JXEG5qYm5gbG1iY W1qaGCmJ8zbOfhYuJJCeWJKanZpakFoE08fEwSnVwCg/l4dZ8O2MP/fOd0+4NMX0An/Pu5qX 115N3cwf079xT2iDQdbS45zGd+pKfu9ges1WdvBXkNvb8ElbI7O0v0+puL7g+QkzTu+Hiz/a ndHcUr71uXP14t2JybJZTZdi+i4eMurY+UWW/fvOfZpMCQeaZYOXXk2TbTldoH2T0/PsjxPH 4mOYQ1SUWIozEg21mIuKEwHBNJBf1QIAAA== X-MTR: 20000000000000000@CPGS Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > --- > 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