Re: power_management: rewrite runpwtests04.sh in C

[email protected]
Newsgroups gmane.linux.ltp
Message-ID <[email protected]>
Hi Jinseok,

On Mon, May 25, 2026, Jinseok Kim wrote:
> power_management: rewrite runpwtests04.sh in C

> +static void verify_cpuidle(unsigned int i)
> +{
> +	int fd;
> +	char path[PATH_MAX];
> +	char buf[32];
> +
> +	snprintf(path, sizeof(path), "%s/%s", CPUIDLE_PATH, tcases[i].name);
> +
> +	fd = SAFE_OPEN(path, O_RDONLY);
> +
> +	SAFE_READ(0, fd, buf, sizeof(buf));
> +	SAFE_CLOSE(fd);

If SAFE_READ() triggers tst_brk(), execution jumps to cleanup but
there is no cleanup registered, so fd is never closed.

The LTP convention is to track file descriptors in a static variable
initialized to -1 and close them in a .cleanup handler:

  static int fd = -1;

  static void verify_cpuidle(unsigned int i)
  {
          ...
          fd = SAFE_OPEN(path, O_RDONLY);
          SAFE_READ(0, fd, buf, sizeof(buf));
          SAFE_CLOSE(fd);

          tst_res(TPASS, "%s read successfully", path);
  }

  static void cleanup(void)
  {
          if (fd != -1)
                  SAFE_CLOSE(fd);
  }

  static struct tst_test test = {
          .setup = setup,
          .cleanup = cleanup,
          ...
  };

Verdict: Needs revision

---
Note:

The agent can sometimes produce false positives although often its
findings are genuine. If you find issues with the review, please
comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.