Skip to content

kerndat: remove redundant ret check in root_only_init() - #3130

Closed
Goyamjain06 wants to merge 1 commit into
checkpoint-restore:criu-devfrom
Goyamjain06:fix/kerndat-redundant-ret-check
Closed

kerndat: remove redundant ret check in root_only_init()#3130
Goyamjain06 wants to merge 1 commit into
checkpoint-restore:criu-devfrom
Goyamjain06:fix/kerndat-redundant-ret-check

Conversation

@Goyamjain06

Copy link
Copy Markdown

What problem does this solve?

Codacy static analysis (pattern 2237, "condition is always true/false") flags a redundant condition in root_only_init() in criu/kerndat.c, tracked in #2120.

What changed

The first check in root_only_init() was:

if (!ret && kerndat_loginuid()) {

Since ret is freshly initialized to 0 immediately before this check, and no code path between the initialization and this check can change it, !ret is always true here — making the check dead/redundant.

Changed to:

if (kerndat_loginuid()) {

All subsequent !ret && kerndat_*() checks later in the same function are intentionally left untouched, since they correctly guard against proceeding after an earlier failure (short-circuit "stop on first error" pattern).

How to test

  1. Build CRIU: make — compiles cleanly with -Werror, no warnings.
  2. Run criu check — behaves identically before/after this change (verified in a Docker-based Ubuntu 22.04 environment).
  3. This is a pure control-flow simplification with no behavioral change, so no test suite specifically covers this function. root_only_init() is exercised indirectly any time CRIU runs kerndat initialization as root.

Related issue

Relates to #2120 (Codacy pattern 2237). This is one of several redundant conditions flagged by that issue; a previous attempt to fix several of them (#2141) went stale and was closed unmerged due to messy/unrebased commit history. This PR addresses just the kerndat.c instance cleanly, as a first, minimal, reviewable step.

The first !ret check in root_only_init() is always true, since ret
is freshly initialized to 0 immediately before this check and no
prior code path can change it. This makes the check redundant and
was flagged by Codacy (pattern 2237, 'condition is always true/false',
see issue checkpoint-restore#2120).

Subsequent !ret && kerndat_*() checks later in the same function are
untouched, as they correctly guard against proceeding after an
earlier failure.

Assisted-by: Claude Code:claude-sonnet-5
Signed-off-by: Goyam Jain <goyam24224@iiitd.ac.in>
@avagin

avagin commented Sep 1, 2026

Copy link
Copy Markdown
Member

I actually like the current form, because it looks like other checks in this function, so it is easier to read this code.

@avagin avagin closed this Sep 1, 2026
@Goyamjain06

Copy link
Copy Markdown
Author

Totally fair — appreciate the quick review! Makes sense to prioritize consistency with the surrounding checks over the strict redundancy. I'll leave this as-is and look at the other patterns flagged under #2120 with that same lens before proposing anything else. Thanks for the feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants