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

Lucas De Marchi lucas.demarchi at intel.com
Fri Oct 18 19:30:49 UTC 2024


On Wed, Oct 16, 2024 at 10:51:02AM +0200, Peter Zijlstra wrote:
>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.

oh... it's the sysfs (that PCI drivers use) that is guaranteed to be
nul-terminated. debugfs is not. And it probably worked for me because of
CONFIG_INIT_STACK_ALL_ZERO=y that comes from my distro.

and this version is also shorter and simpler.

thanks
Lucas De Marchi


More information about the dri-devel mailing list