20 Jan
2021
20 Jan
'21
4:51 p.m.
On Mon, 11 Jan 2021 14:05:54 +0100, Hui Wang wrote:
+static ssize_t sw_inject_enable_read(struct file *file,
char __user *to, size_t count, loff_t *ppos)
+{
- struct snd_jack_kctl *jack_kctl = file->private_data;
- char *buf;
- int len, ret;
- buf = kvzalloc(PAGE_SIZE, GFP_KERNEL);
- if (!buf)
return -ENOMEM;
- len = scnprintf(buf, PAGE_SIZE, "%s: %s\t\t%s: %i\n", "Jack", jack_kctl->kctl->id.name,
"Inject Enabled", jack_kctl->sw_inject_enable);
- ret = simple_read_from_buffer(to, count, ppos, buf, len);
For this size of a string buffer, you don't need to allocate via kvmalloc(). It can be on stack.
+static ssize_t sw_inject_enable_write(struct file *file,
const char __user *from, size_t count, loff_t *ppos)
+{
- struct snd_jack_kctl *jack_kctl = file->private_data;
- char *buf;
- int ret, err;
- unsigned long enable;
- buf = kvzalloc(count, GFP_KERNEL);
- if (!buf)
return -ENOMEM;
- ret = simple_write_to_buffer(buf, count, ppos, from, count);
- err = kstrtoul(buf, 0, &enable);
Ditto, it's just a single number and cannot be that big. (Also jackin_inject_write(), too.)
thanks,
Takashi