lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-id: <1397475984-28001-9-git-send-email-r.baldyga@samsung.com>
Date:	Mon, 14 Apr 2014 13:46:19 +0200
From:	Robert Baldyga <r.baldyga@...sung.com>
To:	unlisted-recipients:; (no To-header on input)
Cc:	robh+dt@...nel.org, pawel.moll@....com, mark.rutland@....com,
	ijc+devicetree@...lion.org.uk, galak@...eaurora.org,
	rob@...dley.net, myungjoo.ham@...sung.com, cw00.choi@...sung.com,
	dbaryshkov@...il.com, dwmw2@...radead.org, balbi@...com,
	gregkh@...uxfoundation.org, grant.likely@...aro.org,
	ldewangan@...dia.com, kishon@...com, gg@...mlogic.co.uk,
	anton@...msg.org, jonghwa3.lee@...sung.com, rongjun.ying@....com,
	linux@...ck-us.net, devicetree@...r.kernel.org,
	linux-doc@...r.kernel.org, linux-kernel@...r.kernel.org,
	patches@...nsource.wolfsonmicro.com, linux-usb@...r.kernel.org,
	linux-omap@...r.kernel.org, aaro.koskinen@....fi,
	m.szyprowski@...sung.com, t.figa@...sung.com,
	Robert Baldyga <r.baldyga@...sung.com>
Subject: [PATCH v2 08/13] extcon: extcon-class: simplify extcon_updata_state()
 function

This patch simplifies extcon_updata_state() function. There is greatly
simplified kobject_uevent preparation. Also meaning of variable passed
to raw_notifier_call_chain() (and in effect to _call_per_cable()) has
changed. Now positions on ones in variable 'val' in _call_per_cable()
indicates numbers of cables which changed their status. It allowed
to simplify also _call_per_cable() function.

Signed-off-by: Robert Baldyga <r.baldyga@...sung.com>
---
 drivers/extcon/extcon-class.c |   81 ++++++++++++++++-------------------------
 include/linux/extcon.h        |    1 -
 2 files changed, 31 insertions(+), 51 deletions(-)

diff --git a/drivers/extcon/extcon-class.c b/drivers/extcon/extcon-class.c
index e9e5e85..13993c6 100644
--- a/drivers/extcon/extcon-class.c
+++ b/drivers/extcon/extcon-class.c
@@ -206,59 +206,48 @@ int extcon_update_state(struct extcon_dev *edev, u32 mask, u32 state)
 {
 	char name_buf[120];
 	char state_buf[120];
-	char *prop_buf;
+	char *tmp;
 	char *envp[3];
 	int env_offset = 0;
 	int length;
 	unsigned long flags;
+	u32 change;
 
 	spin_lock_irqsave(&edev->lock, flags);
 
-	if (edev->state != ((edev->state & ~mask) | (state & mask))) {
-		u32 old_state = edev->state;
-
-		if (check_mutually_exclusive(edev, (edev->state & ~mask) |
-						   (state & mask))) {
+	change = (edev->state & mask) ^ (state & mask);
+	if (change) {
+		if (check_mutually_exclusive(edev, edev->state ^ change)) {
 			spin_unlock_irqrestore(&edev->lock, flags);
 			return -EPERM;
 		}
 
-		edev->state &= ~mask;
-		edev->state |= state & mask;
-
-		raw_notifier_call_chain(&edev->nh, old_state, edev);
-		/* This could be in interrupt handler */
-		prop_buf = (char *)get_zeroed_page(GFP_ATOMIC);
-		if (prop_buf) {
-			length = name_show(&edev->dev, NULL, prop_buf);
-			if (length > 0) {
-				if (prop_buf[length - 1] == '\n')
-					prop_buf[length - 1] = 0;
-				snprintf(name_buf, sizeof(name_buf),
-					"NAME=%s", prop_buf);
-				envp[env_offset++] = name_buf;
-			}
-			length = state_show(&edev->dev, NULL, prop_buf);
-			if (length > 0) {
-				if (prop_buf[length - 1] == '\n')
-					prop_buf[length - 1] = 0;
-				snprintf(state_buf, sizeof(state_buf),
-					"STATE=%s", prop_buf);
-				envp[env_offset++] = state_buf;
-			}
-			envp[env_offset] = NULL;
-			/* Unlock early before uevent */
-			spin_unlock_irqrestore(&edev->lock, flags);
+		edev->state ^= change;
 
-			kobject_uevent_env(&edev->dev.kobj, KOBJ_CHANGE, envp);
-			free_page((unsigned long)prop_buf);
-		} else {
-			/* Unlock early before uevent */
-			spin_unlock_irqrestore(&edev->lock, flags);
+		raw_notifier_call_chain(&edev->nh, change, edev);
+
+		tmp = name_buf + sprintf(name_buf, "NAME=");
+		length = name_show(&edev->dev, NULL, tmp);
+		if (length > 0) {
+			if (tmp[length - 1] == '\n')
+				tmp[length - 1] = 0;
+			envp[env_offset++] = name_buf;
+		}
 
-			dev_err(&edev->dev, "out of memory in extcon_set_state\n");
-			kobject_uevent(&edev->dev.kobj, KOBJ_CHANGE);
+		tmp = state_buf + sprintf(state_buf, "STATE=");
+		length = state_show(&edev->dev, NULL, tmp);
+		if (length > 0) {
+			if (tmp[length - 1] == '\n')
+				tmp[length - 1] = 0;
+			envp[env_offset++] = state_buf;
 		}
+
+		envp[env_offset] = NULL;
+
+		/* Unlock early before uevent */
+		spin_unlock_irqrestore(&edev->lock, flags);
+
+		kobject_uevent_env(&edev->dev.kobj, KOBJ_CHANGE, envp);
 	} else {
 		/* No changes */
 		spin_unlock_irqrestore(&edev->lock, flags);
@@ -511,18 +500,10 @@ static int _call_per_cable(struct notifier_block *nb, unsigned long val,
 {
 	struct extcon_cable_nb *obj = container_of(nb,
 			struct extcon_cable_nb, internal_nb);
-	struct extcon_dev *edev = ptr;
-
-	if ((val & (1 << obj->cable->cable_index)) !=
-			(edev->state & (1 << obj->cable->cable_index))) {
-		bool cable_state = true;
-
-		obj->previous_value = val;
-
-		if (val & (1 << obj->cable->cable_index))
-			cable_state = false;
 
-		return obj->notifier_function(obj, cable_state);
+	if ((1 << obj->cable->cable_index) & val) {
+		int state = extcon_get_cable_state(obj->cable);
+		return obj->notifier_function(obj, !!state);
 	}
 
 	return NOTIFY_OK;
diff --git a/include/linux/extcon.h b/include/linux/extcon.h
index 28e60fb..8792ca2 100644
--- a/include/linux/extcon.h
+++ b/include/linux/extcon.h
@@ -177,7 +177,6 @@ typedef int (*extcon_notifier_fn_t)(struct extcon_cable_nb *cable_nb,
  */
 struct extcon_cable_nb {
 	struct notifier_block internal_nb;
-	unsigned long previous_value;
 	extcon_notifier_fn_t notifier_function;
 	struct extcon_cable *cable;
 };
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ