 +
 +		default:
 +			dev_err(gpu->dev, "%s: op %s (%u) not permitted at offset %u\n",
++					__func__, opcode_to_str(op), op, buf - start);
++			return false;
++		}
++
++		if (len < 0) {
++			dev_err(gpu->dev, "%s: op %s (%u) at offset %u is not valid\n",
 +					__func__, opcode_to_str(op), op, buf - start);
 +			return false;
 +		}

+}
diff --git a/drivers/staging/etnaviv/etnaviv_cmd_parser.c b/drivers/staging/etnaviv/etnaviv_cmd_parser.c
new file mode 100644
index 0000000..65de403
--- /dev/null
+++ b/drivers/staging/etnaviv/etnaviv_cmd_parser.c
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2015 Etnaviv Project
+ * Author: Russell King <rmk+kernel@arm.linux.org.uk>

+    return "UNKOWN OPCODE";
+}
+
+static int validate_load_state(u32 cmd, u32 *data)
+{
+	unsigned int count, off;
+
+	count = VIV_FE_LOAD_STATE_HEADER_COUNT(cmd);
+	off = VIV_FE_LOAD_STATE_HEADER_OFFSET(cmd);
+
+	if (count == 0x0)
+		return -EINVAL;
+
+	/* TODO: validate offset */
+
+	return count + 1;
+}
+
+bool etnaviv_cmd_validate(struct etnaviv_gpu *gpu,
+	struct etnaviv_gem_object *obj, unsigned int size)
+{
