From 0a409a7bce9c77cced95c8cb7e3883905b761f31 Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Fri, 3 Apr 2015 16:35:14 +0900 Subject: [PATCH] extcon: Do not invoke the update() if the status is the same as before Do not invoke the update func. if the status is the same as before. And do not printout error logs for not matched device. The information of not matched device is already printed out on booting time. So it's redundant logs. Change-Id: I8bd2696036bb4633eb05a128d5a9de46dc35fed1 Signed-off-by: Jiyoung Yun --- src/extcon/cradle.c | 2 +- src/extcon/earjack.c | 2 +- src/extcon/extcon.c | 9 ++++++--- src/extcon/extcon.h | 11 +++++++++-- src/extcon/hdmi.c | 2 +- src/usb/usb.c | 2 +- 6 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/extcon/cradle.c b/src/extcon/cradle.c index 6b4d6b2..6aabe5f 100644 --- a/src/extcon/cradle.c +++ b/src/extcon/cradle.c @@ -121,4 +121,4 @@ static struct extcon_ops cradle_extcon_ops = { .update = cradle_update, }; -EXTCON_OPS_REGISTER(&cradle_extcon_ops); +EXTCON_OPS_REGISTER(cradle_extcon_ops) diff --git a/src/extcon/earjack.c b/src/extcon/earjack.c index db2118c..c5deaeb 100644 --- a/src/extcon/earjack.c +++ b/src/extcon/earjack.c @@ -58,4 +58,4 @@ static struct extcon_ops earjack_extcon_ops = { .update = earjack_update, }; -EXTCON_OPS_REGISTER(&earjack_extcon_ops) +EXTCON_OPS_REGISTER(earjack_extcon_ops) diff --git a/src/extcon/extcon.c b/src/extcon/extcon.c index 3285aab..80ef738 100755 --- a/src/extcon/extcon.c +++ b/src/extcon/extcon.c @@ -85,12 +85,15 @@ static int extcon_update(const char *name, const char *value) return -EINVAL; dev = find_extcon(name); - if (!dev) { - _E("fail to find matched extcon device : name(%s)", name); + if (!dev) return -EINVAL; - } status = atoi(value); + + /* Do not invoke update func. if it's the same value */ + if (dev->status == status) + return 0; + _I("Changed %s device : %d -> %d", name, dev->status, status); dev->status = status; diff --git a/src/extcon/extcon.h b/src/extcon/extcon.h index b06c629..eb10fc9 100755 --- a/src/extcon/extcon.h +++ b/src/extcon/extcon.h @@ -45,11 +45,18 @@ struct extcon_ops { #define EXTCON_OPS_REGISTER(dev) \ static void __CONSTRUCTOR__ extcon_init(void) \ { \ - add_extcon(dev); \ + /** + * If there is no predefined status value, + * default status will set as a negative value(-1). + * It will be updated as the initial value in booting time. + */ \ + if (!dev.status) \ + dev.status = -1; \ + add_extcon(&dev); \ } \ static void __DESTRUCTOR__ extcon_exit(void) \ { \ - remove_extcon(dev); \ + remove_extcon(&dev); \ } void add_extcon(struct extcon_ops *dev); diff --git a/src/extcon/hdmi.c b/src/extcon/hdmi.c index 29fc511..5a6a1d8 100644 --- a/src/extcon/hdmi.c +++ b/src/extcon/hdmi.c @@ -118,4 +118,4 @@ static struct extcon_ops hdmi_extcon_ops = { .update = hdmi_update, }; -EXTCON_OPS_REGISTER(&hdmi_extcon_ops); +EXTCON_OPS_REGISTER(hdmi_extcon_ops) diff --git a/src/usb/usb.c b/src/usb/usb.c index 44d5d2d..c122ae9 100644 --- a/src/usb/usb.c +++ b/src/usb/usb.c @@ -206,4 +206,4 @@ struct extcon_ops extcon_usb_ops = { .update = usb_state_changed, }; -EXTCON_OPS_REGISTER(&extcon_usb_ops) +EXTCON_OPS_REGISTER(extcon_usb_ops) -- 2.7.4