Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix tt_command_write()

1) unbalanced debugfs_file_get(). Not needed in the first place -
file_operations are accessed only via debugfs_create_file(), so
debugfs wrappers will take care of that itself.

2) kmalloc() for a buffer used only for duration of a function is not
a problem, but for a buffer no longer than 16 bytes?

3) strstr() is for finding substrings; for finding a character there's
strchr().

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Acked-by: "Rafael J. Wysocki" <rafael@kernel.org>
Link: https://lore.kernel.org/r/20250702212542.GH3406663@ZenIV
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Al Viro and committed by
Greg Kroah-Hartman
00bbe512 d9bc88aa

+10 -20
+10 -20
drivers/thermal/testing/command.c
··· 139 139 return ret; 140 140 } 141 141 142 - static ssize_t tt_command_process(struct dentry *dentry, const char __user *user_buf, 143 - size_t count) 142 + static ssize_t tt_command_process(char *s) 144 143 { 145 - char *buf __free(kfree); 146 144 char *arg; 147 145 int i; 148 146 149 - buf = kmalloc(count + 1, GFP_KERNEL); 150 - if (!buf) 151 - return -ENOMEM; 147 + strim(s); 152 148 153 - if (copy_from_user(buf, user_buf, count)) 154 - return -EFAULT; 155 - 156 - buf[count] = '\0'; 157 - strim(buf); 158 - 159 - arg = strstr(buf, ":"); 149 + arg = strchr(s, ':'); 160 150 if (arg) { 161 151 *arg = '\0'; 162 152 arg++; 163 153 } 164 154 165 155 for (i = 0; i < ARRAY_SIZE(tt_command_strings); i++) { 166 - if (!strcmp(buf, tt_command_strings[i])) 156 + if (!strcmp(s, tt_command_strings[i])) 167 157 return tt_command_exec(i, arg); 168 158 } 169 159 ··· 163 173 static ssize_t tt_command_write(struct file *file, const char __user *user_buf, 164 174 size_t count, loff_t *ppos) 165 175 { 166 - struct dentry *dentry = file->f_path.dentry; 176 + char buf[TT_COMMAND_SIZE]; 167 177 ssize_t ret; 168 178 169 179 if (*ppos) 170 180 return -EINVAL; 171 181 172 - if (count + 1 > TT_COMMAND_SIZE) 182 + if (count > TT_COMMAND_SIZE - 1) 173 183 return -E2BIG; 174 184 175 - ret = debugfs_file_get(dentry); 176 - if (unlikely(ret)) 177 - return ret; 185 + if (copy_from_user(buf, user_buf, count)) 186 + return -EFAULT; 187 + buf[count] = '\0'; 178 188 179 - ret = tt_command_process(dentry, user_buf, count); 189 + ret = tt_command_process(buf); 180 190 if (ret) 181 191 return ret; 182 192