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>] [day] [month] [year] [list]
Message-Id: <1413474876-28544-5-git-send-email-a.motakis@virtualopensystems.com>
Date:	Thu, 16 Oct 2014 17:54:36 +0200
From:	Antonios Motakis <a.motakis@...tualopensystems.com>
To:	kvmarm@...ts.cs.columbia.edu, iommu@...ts.linux-foundation.org,
	alex.williamson@...hat.com
Cc:	tech@...tualopensystems.com, christoffer.dall@...aro.org,
	eric.auger@...aro.org, kim.phillips@...escale.com,
	Antonios Motakis <a.motakis@...tualopensystems.com>,
	kvm@...r.kernel.org (open list:VFIO DRIVER),
	linux-kernel@...r.kernel.org (open list)
Subject: [RFC PATCH v2 4/4] vfio: platform: devtree: return arrays of u32, u16, or u8 data

Certain properties of a device tree node are accessible as an array
of unsigned integers, either u32, u16, or u8. Let the VFIO user query
this type of device node properties. Accessing u64 arrays is not yet
implemented in this RFC.

Signed-off-by: Antonios Motakis <a.motakis@...tualopensystems.com>
---
 drivers/vfio/platform/devtree.c | 55 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 54 insertions(+), 1 deletion(-)

diff --git a/drivers/vfio/platform/devtree.c b/drivers/vfio/platform/devtree.c
index 6d25f97..17f55d4 100644
--- a/drivers/vfio/platform/devtree.c
+++ b/drivers/vfio/platform/devtree.c
@@ -97,7 +97,60 @@ static int devtree_get_uint(struct device_node *np, char *name,
 			    uint32_t type, unsigned *lenp,
 			    void __user *datap, unsigned long datasz)
 {
-	return -EINVAL;
+	int ret, n;
+	size_t sz;
+	u8 *out;
+	int (*func)(const struct device_node *, const char *, void *, size_t)
+		= NULL;
+
+	switch (type) {
+	case VFIO_DEVTREE_TYPE_U32:
+		sz = sizeof(u32);
+		func = (int (*)(const struct device_node *,
+				const char *, void *, size_t))
+			of_property_read_u32_array;
+		break;
+	case VFIO_DEVTREE_TYPE_U16:
+		sz = sizeof(u16);
+		func = (int (*)(const struct device_node *,
+				const char *, void *, size_t))
+			of_property_read_u16_array;
+		break;
+	case VFIO_DEVTREE_TYPE_U8:
+		sz = sizeof(u8);
+		func = (int (*)(const struct device_node *,
+				const char *, void *, size_t))
+			of_property_read_u8_array;
+		break;
+
+	default:
+		return -EINVAL;
+	}
+
+	n = of_property_count_elems_of_size(np, name, sz);
+	if (n < 0)
+		return n;
+
+	if (lenp)
+		*lenp = n * sz;
+
+	if (n * sz > datasz)
+		return -EAGAIN;
+
+	out = kcalloc(n, sz, GFP_KERNEL);
+	if (!out)
+		return -EFAULT;
+
+	ret = func(np, name, out, n);
+	if (ret)
+		goto out;
+
+	if (copy_to_user(datap, out, n * sz))
+		ret = -EFAULT;
+
+out:
+	kfree(out);
+	return ret;
 }
 
 int vfio_platform_devtree_info(struct device_node *np,
-- 
2.1.1

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