mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/1] extcon: deduplicate code in extcon_set_state_sync()
@ 2021-11-23 14:53 ` Alexander Stein
  2021-12-16  3:05   ` Chanwoo Choi
  0 siblings, 1 reply; 2+ messages in thread
From: Alexander Stein @ 2021-11-23 14:53 UTC (permalink / raw)
  To: MyungJoo Ham, Chanwoo Choi; +Cc: Alexander Stein, linux-kernel

Finding the cable index and checking for changed status is also done
in extcon_set_state(). So calling extcon_set_state_sync() will do these
checks twice. Remove them and use these checks from extcon_set_state().

Signed-off-by: Alexander Stein <alexander.stein@ew.tq-group.com>
---
I noticed this duplicated code while debugging an extcon related issue.
I do not know if it is allowed in the kernel to assume some behavior in
EXPORT_SYMBOL* functions, but as the two functions mentioned are in the
same source file it should be ok.
In the case it is not okay to assume some behaviour,
extcon_set_state_sync() is missing a check for !edev, like
extcon_set_state() does.

 drivers/extcon/extcon.c | 14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)

diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c
index e7a9561a826d..a09e704fd0fa 100644
--- a/drivers/extcon/extcon.c
+++ b/drivers/extcon/extcon.c
@@ -576,19 +576,7 @@ EXPORT_SYMBOL_GPL(extcon_set_state);
  */
 int extcon_set_state_sync(struct extcon_dev *edev, unsigned int id, bool state)
 {
-	int ret, index;
-	unsigned long flags;
-
-	index = find_cable_index_by_id(edev, id);
-	if (index < 0)
-		return index;
-
-	/* Check whether the external connector's state is changed. */
-	spin_lock_irqsave(&edev->lock, flags);
-	ret = is_extcon_changed(edev, index, state);
-	spin_unlock_irqrestore(&edev->lock, flags);
-	if (!ret)
-		return 0;
+	int ret;
 
 	ret = extcon_set_state(edev, id, state);
 	if (ret < 0)
-- 
2.25.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH 1/1] extcon: deduplicate code in extcon_set_state_sync()
  2021-11-23 14:53 ` [PATCH 1/1] extcon: deduplicate code in extcon_set_state_sync() Alexander Stein
@ 2021-12-16  3:05   ` Chanwoo Choi
  0 siblings, 0 replies; 2+ messages in thread
From: Chanwoo Choi @ 2021-12-16  3:05 UTC (permalink / raw)
  To: Alexander Stein, MyungJoo Ham; +Cc: linux-kernel

On 11/23/21 11:53 PM, Alexander Stein wrote:
> Finding the cable index and checking for changed status is also done
> in extcon_set_state(). So calling extcon_set_state_sync() will do these
> checks twice. Remove them and use these checks from extcon_set_state().
> 
> Signed-off-by: Alexander Stein <alexander.stein@ew.tq-group.com>
> ---
> I noticed this duplicated code while debugging an extcon related issue.
> I do not know if it is allowed in the kernel to assume some behavior in
> EXPORT_SYMBOL* functions, but as the two functions mentioned are in the
> same source file it should be ok.
> In the case it is not okay to assume some behaviour,
> extcon_set_state_sync() is missing a check for !edev, like
> extcon_set_state() does.
> 
>  drivers/extcon/extcon.c | 14 +-------------
>  1 file changed, 1 insertion(+), 13 deletions(-)
> 
> diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c
> index e7a9561a826d..a09e704fd0fa 100644
> --- a/drivers/extcon/extcon.c
> +++ b/drivers/extcon/extcon.c
> @@ -576,19 +576,7 @@ EXPORT_SYMBOL_GPL(extcon_set_state);
>   */
>  int extcon_set_state_sync(struct extcon_dev *edev, unsigned int id, bool state)
>  {
> -	int ret, index;
> -	unsigned long flags;
> -
> -	index = find_cable_index_by_id(edev, id);
> -	if (index < 0)
> -		return index;
> -
> -	/* Check whether the external connector's state is changed. */
> -	spin_lock_irqsave(&edev->lock, flags);
> -	ret = is_extcon_changed(edev, index, state);
> -	spin_unlock_irqrestore(&edev->lock, flags);
> -	if (!ret)
> -		return 0;
> +	int ret;
>  
>  	ret = extcon_set_state(edev, id, state);
>  	if (ret < 0)
> 

Applied it. Thanks.

-- 
Best Regards,
Chanwoo Choi
Samsung Electronics

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-12-16  2:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20211123145318epcas1p17f6567ed89ec7f8f3ab3c007c58b1fe0@epcas1p1.samsung.com>
2021-11-23 14:53 ` [PATCH 1/1] extcon: deduplicate code in extcon_set_state_sync() Alexander Stein
2021-12-16  3:05   ` Chanwoo Choi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®