[PATCH 1/5] perf: Add dummy pmu module

Peter Zijlstra peterz at infradead.org
Wed Oct 16 08:51:02 UTC 2024


On Tue, Oct 08, 2024 at 01:34:57PM -0500, Lucas De Marchi wrote:
> +static int parse_device(const char __user *ubuf, size_t size, u32 *instance)
> +{
> +	char buf[16];
> +	ssize_t len;
> +
> +	if (size > sizeof(buf) - 1)
> +		return -E2BIG;
> +
> +	len = strncpy_from_user(buf, ubuf, sizeof(buf));
> +	if (len < 0 || len >= sizeof(buf) - 1)
> +		return -E2BIG;
> +
> +	if (kstrtou32(buf, 0, instance))
> +		return -EINVAL;
> +
> +	return size;
> +}

I had to change this to:

+static int parse_device(const char __user *ubuf, size_t size, u32 *instance)
+{
+       int ret = kstrtouint_from_user(ubuf, size, 0, instance);
+       if (ret) {
+               printk("suckage: %d\n", ret);
+               return ret;
+       }
+       return size;
+}

because otherwise it didn't want to work for me; I kept getting garbage
at the end and things failing. Specifically, it looked like the string
presented by userspace was not '\0' terminated, ubuf was pointing to
"1...garbage..." and size was 1.


More information about the dri-devel mailing list