fs/orangefs/orangefs-debugfs.c:244 orangefs_kernel_debug_init() warn: always true condition '(len >= 0) => (0-u64max >= 0)'
kernel test robot
build bottree: https://git.kernel.org/pub/scm/linux/kernel/git/hubcap/linux.git for-next head: fb0898b77656046fd25c5f08cf89cd6e3899e6db commit: 30b7c30781f0440e70a5e0c8943be423b57bbd9b [1/6] debugfs: take better advantage of strscpy. config: loongarch-randconfig-r073-20260407 (https://download.01.org/0day-ci/archive/20260407/[email protected]/config) compiler: clang version 23.0.0git (https://github.com/llvm/llvm-project c80443cd37b2e2788cba67ffa180a6331e5f0791) smatch: v0.5.0-9004-gb810ac53
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
smatch warnings:fs/orangefs/orangefs-debugfs.c:244 orangefs_kernel_debug_init() warn: always true condition '(len >= 0) => (0-u64max >= 0)' fs/orangefs/orangefs-debugfs.c:343 orangefs_client_debug_init() warn: always true condition '(len >= 0) => (0-u64max >= 0)'
vim +244 fs/orangefs/orangefs-debugfs.c
234
235 /*
236 * initialize the kernel-debug file.
237 */
238 static void orangefs_kernel_debug_init(void)
239 {
240 static char k_buffer[ORANGEFS_MAX_DEBUG_STRING_LEN] = { };
241 size_t len =
242 strscpy(k_buffer, kernel_debug_string, sizeof(k_buffer) - 1);
243
> 244 if (len >= 0) {
245 k_buffer[len] = '\n';
246 k_buffer[len + 1] = '\0';
247 } else {
248 strscpy(k_buffer, "none\n");
249 pr_info("%s: overflow 1!\n", __func__);
250 }
251
252 debugfs_create_file_aux_num(ORANGEFS_KMOD_DEBUG_FILE, 0444, debug_dir, k_buffer,
253 0, &kernel_debug_fops);
254 }
255
256
257 void orangefs_debugfs_cleanup(void)
258 {
259 debugfs_remove_recursive(debug_dir);
260 kfree(debug_help_string);
261 debug_help_string = NULL;
262 }
263
264 /* open ORANGEFS_KMOD_DEBUG_HELP_FILE */
265 static int orangefs_debug_help_open(struct inode *inode, struct file *file)
266 {
267 int rc = -ENODEV;
268 int ret;
269
270 gossip_debug(GOSSIP_DEBUGFS_DEBUG,
271 "orangefs_debug_help_open: start\n");
272
273 if (orangefs_debug_disabled)
274 goto out;
275
276 ret = seq_open(file, &help_debug_ops);
277 if (ret)
278 goto out;
279
280 ((struct seq_file *)(file->private_data))->private = inode->i_private;
281
282 rc = 0;
283
284 out:
285 gossip_debug(GOSSIP_DEBUGFS_DEBUG,
286 "orangefs_debug_help_open: rc:%d:\n",
287 rc);
288 return rc;
289 }
290
291 /*
292 * I think start always gets called again after stop. Start
293 * needs to return NULL when it is done. The whole "payload"
294 * in this case is a single (long) string, so by the second
295 * time we get to start (pos = 1), we're done.
296 */
297 static void *help_start(struct seq_file *m, loff_t *pos)
298 {
299 void *payload = NULL;
300
301 gossip_debug(GOSSIP_DEBUGFS_DEBUG, "help_start: start\n");
302
303 mutex_lock(&orangefs_help_file_lock);
304
305 if (*pos == 0)
306 payload = m->private;
307
308 return payload;
309 }
310
311 static void *help_next(struct seq_file *m, void *v, loff_t *pos)
312 {
313 (*pos)++;
314 gossip_debug(GOSSIP_DEBUGFS_DEBUG, "help_next: start\n");
315
316 return NULL;
317 }
318
319 static void help_stop(struct seq_file *m, void *p)
320 {
321 gossip_debug(GOSSIP_DEBUGFS_DEBUG, "help_stop: start\n");
322 mutex_unlock(&orangefs_help_file_lock);
323 }
324
325 static int help_show(struct seq_file *m, void *v)
326 {
327 gossip_debug(GOSSIP_DEBUGFS_DEBUG, "help_show: start\n");
328
329 seq_puts(m, v);
330
331 return 0;
332 }
333
334 /*
335 * initialize the client-debug file.
336 */
337 static void orangefs_client_debug_init(void)
338 {
339 static char c_buffer[ORANGEFS_MAX_DEBUG_STRING_LEN] = { };
340 size_t len =
341 strscpy(c_buffer, client_debug_string, sizeof(c_buffer) - 1);
342
> 343 if (len >= 0) {
344 c_buffer[len] = '\n';
345 c_buffer[len + 1] = '\0';
346 } else {
347 strscpy(c_buffer, "none\n");
348 pr_info("%s: overflow! 2\n", __func__);
349 }
350
351 client_debug_dentry = debugfs_create_file_aux_num(
352 ORANGEFS_CLIENT_DEBUG_FILE,
353 0444, debug_dir, c_buffer, 1,
354 &kernel_debug_fops); 355 }
356
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki