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-next>] [day] [month] [year] [list]
Date:	Thu, 12 Dec 2013 18:54:52 +0530
From:	Laxman Dewangan <ldewangan@...dia.com>
To:	<robh+dt@...nel.org>, <pawel.moll@....com>, <mark.rutland@....com>,
	<grant.likely@...aro.org>
CC:	<ijc+devicetree@...lion.org.uk>, <galak@...eaurora.org>,
	<linux-kernel@...r.kernel.org>, <devicetree@...r.kernel.org>,
	<swarren@...dia.com>, <kerwinw@...dia.com>,
	Laxman Dewangan <ldewangan@...dia.com>,
	<david@...son.dropbear.id.au>
Subject: [PATCH 1/2] of: add support for reading s32 property value

Add of_property_read_s32() to read the signed 32bit number
from dt property value. This supports to pass the -ve numbers
from dt. Use 2's complement method for represnting negative number
and passed as u32 from dts. When reading back the value, again
converted to 2's complement if msb shows as 1.

Signed-off-by: Laxman Dewangan <ldewangan@...dia.com>
CC: david@...son.dropbear.id.au
CC: swarren@...dia.com
---
We required to pass the -ve value from DT and after looking the discussion
http://www.mail-archive.com/linux-arm-msm@vger.kernel.org/msg05108.html
I created this patch.
I CCed to David and Stephen on this.


 include/linux/of.h |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/include/linux/of.h b/include/linux/of.h
index 276c546..17c0327 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -601,6 +601,22 @@ static inline int of_property_read_u32(const struct device_node *np,
 	return of_property_read_u32_array(np, propname, out_value, 1);
 }
 
+static inline int of_property_read_s32(const struct device_node *np,
+				       const char *propname,
+				       s32 *out_value)
+{
+	u32 val;
+	int ret;
+
+	ret = of_property_read_u32(np, propname, &val);
+	if (ret < 0)
+		return ret;
+
+	/* 2's complement if MSB is 1 */
+	*out_value = (val & 0x80000000U) ? -((val ^ 0xFFFFFFFFU) + 1) : val;
+	return ret;
+}
+
 #define of_property_for_each_u32(np, propname, prop, p, u)	\
 	for (prop = of_find_property(np, propname, NULL),	\
 		p = of_prop_next_u32(prop, NULL, &u);		\
-- 
1.7.0.4

--
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