* [f2fs-dev] [bug report] f2fs: add gc_urgent_high_remaining sysfs node
@ 2021-12-09 15:07 Dan Carpenter
0 siblings, 0 replies; only message in thread
From: Dan Carpenter @ 2021-12-09 15:07 UTC (permalink / raw)
To: daehojeong; +Cc: linux-f2fs-devel
Hello Daeho Jeong,
The patch 38f953da2e35: "f2fs: add gc_urgent_high_remaining sysfs
node" from Dec 7, 2021, leads to the following Smatch static checker
warning:
fs/f2fs/sysfs.c:490 __sbi_store()
warn: unsigned 't' is never less than zero.
fs/f2fs/sysfs.c
332 static ssize_t __sbi_store(struct f2fs_attr *a,
333 struct f2fs_sb_info *sbi,
334 const char *buf, size_t count)
335 {
336 unsigned char *ptr;
337 unsigned long t;
^^^^^^^^^^^^^^^^
338 unsigned int *ui;
339 ssize_t ret;
340
341 ptr = __struct_ptr(sbi, a->struct_type);
342 if (!ptr)
343 return -EINVAL;
344
345 if (!strcmp(a->attr.name, "extension_list")) {
346 const char *name = strim((char *)buf);
347 bool set = true, hot;
348
349 if (!strncmp(name, "[h]", 3))
350 hot = true;
351 else if (!strncmp(name, "[c]", 3))
352 hot = false;
353 else
354 return -EINVAL;
355
356 name += 3;
357
358 if (*name == '!') {
359 name++;
360 set = false;
361 }
362
363 if (!strlen(name) || strlen(name) >= F2FS_EXTENSION_LEN)
364 return -EINVAL;
365
366 down_write(&sbi->sb_lock);
367
368 ret = f2fs_update_extension_list(sbi, name, hot, set);
369 if (ret)
370 goto out;
371
372 ret = f2fs_commit_super(sbi, false);
373 if (ret)
374 f2fs_update_extension_list(sbi, name, hot, !set);
375 out:
376 up_write(&sbi->sb_lock);
377 return ret ? ret : count;
378 }
379
380 if (!strcmp(a->attr.name, "ckpt_thread_ioprio")) {
381 const char *name = strim((char *)buf);
382 struct ckpt_req_control *cprc = &sbi->cprc_info;
383 int class;
384 long data;
385 int ret;
386
387 if (!strncmp(name, "rt,", 3))
388 class = IOPRIO_CLASS_RT;
389 else if (!strncmp(name, "be,", 3))
390 class = IOPRIO_CLASS_BE;
391 else
392 return -EINVAL;
393
394 name += 3;
395 ret = kstrtol(name, 10, &data);
396 if (ret)
397 return ret;
398 if (data >= IOPRIO_NR_LEVELS || data < 0)
399 return -EINVAL;
400
401 cprc->ckpt_thread_ioprio = IOPRIO_PRIO_VALUE(class, data);
402 if (test_opt(sbi, MERGE_CHECKPOINT)) {
403 ret = set_task_ioprio(cprc->f2fs_issue_ckpt,
404 cprc->ckpt_thread_ioprio);
405 if (ret)
406 return ret;
407 }
408
409 return count;
410 }
411
412 ui = (unsigned int *)(ptr + a->offset);
413
414 ret = kstrtoul(skip_spaces(buf), 0, &t);
^^^
"t" set here.
415 if (ret < 0)
416 return ret;
417 #ifdef CONFIG_F2FS_FAULT_INJECTION
418 if (a->struct_type == FAULT_INFO_TYPE && t >= (1 << FAULT_MAX))
419 return -EINVAL;
420 if (a->struct_type == FAULT_INFO_RATE && t >= UINT_MAX)
421 return -EINVAL;
422 #endif
423 if (a->struct_type == RESERVED_BLOCKS) {
424 spin_lock(&sbi->stat_lock);
425 if (t > (unsigned long)(sbi->user_block_count -
426 F2FS_OPTION(sbi).root_reserved_blocks)) {
427 spin_unlock(&sbi->stat_lock);
428 return -EINVAL;
429 }
430 *ui = t;
431 sbi->current_reserved_blocks = min(sbi->reserved_blocks,
432 sbi->user_block_count - valid_user_blocks(sbi));
433 spin_unlock(&sbi->stat_lock);
434 return count;
435 }
436
437 if (!strcmp(a->attr.name, "discard_granularity")) {
438 if (t == 0 || t > MAX_PLIST_NUM)
439 return -EINVAL;
440 if (!f2fs_block_unit_discard(sbi))
441 return -EINVAL;
442 if (t == *ui)
443 return count;
444 *ui = t;
445 return count;
446 }
447
448 if (!strcmp(a->attr.name, "migration_granularity")) {
449 if (t == 0 || t > sbi->segs_per_sec)
450 return -EINVAL;
451 }
452
453 if (!strcmp(a->attr.name, "trim_sections"))
454 return -EINVAL;
455
456 if (!strcmp(a->attr.name, "gc_urgent")) {
457 if (t == 0) {
458 sbi->gc_mode = GC_NORMAL;
459 } else if (t == 1) {
460 sbi->gc_mode = GC_URGENT_HIGH;
461 if (sbi->gc_thread) {
462 sbi->gc_thread->gc_wake = 1;
463 wake_up_interruptible_all(
464 &sbi->gc_thread->gc_wait_queue_head);
465 wake_up_discard_thread(sbi, true);
466 }
467 } else if (t == 2) {
468 sbi->gc_mode = GC_URGENT_LOW;
469 } else {
470 return -EINVAL;
471 }
472 return count;
473 }
474 if (!strcmp(a->attr.name, "gc_idle")) {
475 if (t == GC_IDLE_CB) {
476 sbi->gc_mode = GC_IDLE_CB;
477 } else if (t == GC_IDLE_GREEDY) {
478 sbi->gc_mode = GC_IDLE_GREEDY;
479 } else if (t == GC_IDLE_AT) {
480 if (!sbi->am.atgc_enabled)
481 return -EINVAL;
482 sbi->gc_mode = GC_AT;
483 } else {
484 sbi->gc_mode = GC_NORMAL;
485 }
486 return count;
487 }
488
489 if (!strcmp(a->attr.name, "gc_urgent_high_remaining")) {
--> 490 if (t < 0)
^^^^^
impossible.
491 return -EINVAL;
492
493 spin_lock(&sbi->gc_urgent_high_lock);
494 sbi->gc_urgent_high_limited = t == 0 ? false : true;
495 sbi->gc_urgent_high_remaining = t;
496 spin_unlock(&sbi->gc_urgent_high_lock);
497
498 return count;
499 }
regards,
dan carpenter
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-12-09 15:07 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-12-09 15:07 [f2fs-dev] [bug report] f2fs: add gc_urgent_high_remaining sysfs node Dan Carpenter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).