On 06/16/2009 03:05 PM, Marcelo Tosatti wrote:
Do not allow invalid MTRR/PAT values in set_msr_mtrr.

Please review carefully.

Signed-off-by: Marcelo Tosatti<mtosa...@redhat.com>


+static unsigned mtrr_types[] = {0, 1, 4, 5, 6};
+static unsigned pat_types[] = {0, 1, 4, 5, 6, 7};
+
+static bool valid_mt(unsigned type, int len, unsigned array[len])
+{
+       int i;
+
+       for (i = 0; i<  len; i++)
+               if (type == array[i])
+                       return true;
+
+       return false;
+}
+
+#define valid_pat_type(a) valid_mt(a, ARRAY_SIZE(pat_types), pat_types)
+#define valid_mtrr_type(a) valid_mt(a, ARRAY_SIZE(mtrr_types), mtrr_types)
+

A little pointless since this is so performance-insensitive, but still:

valid_pat_type(t)
{
    return t < 8 && (1 << t) & 0xf3; /* 0, 1, 4, 5, 6, 7 */
}

valid_mtrr_type(t)
{
    return t < 8 && (1 << t) & 0x73; /* 0, 1, 4, 5, 6 */
}

--
error compiling committee.c: too many arguments to function

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to