All of lore.kernel.org
 help / color / mirror / Atom feed
From: linuxtestproject.agent@gmail.com
To: Jinseok Kim <always.starving0@gmail.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] power_management: rewrite runpwtests04.sh in C
Date: Tue,  9 Jun 2026 08:02:53 +0000	[thread overview]
Message-ID: <20260609080253.4025-1-linuxtestproject.agent@gmail.com> (raw)
In-Reply-To: <20260524154221.2064-1-always.starving0@gmail.com>

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

  parent reply	other threads:[~2026-06-09  8:03 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-24 15:42 [LTP] [PATCH v2] power_management: rewrite runpwtests04.sh in C Jinseok Kim
2026-05-24 17:05 ` [LTP] " linuxtestproject.agent
2026-06-09  8:02 ` linuxtestproject.agent [this message]
2026-06-11  8:00 ` [LTP] [PATCH v2] " Andrea Cervesato via ltp
2026-06-12  9:17 ` Andrea Cervesato via ltp
  -- strict thread matches above, loose matches on Subject: below --
2026-06-12 17:13 [LTP] [PATCH v5] " Jinseok Kim
2026-06-12 19:09 ` [LTP] " linuxtestproject.agent
2026-06-12 12:20 [LTP] [PATCH v4] " Jinseok Kim
2026-06-12 16:22 ` [LTP] " linuxtestproject.agent
2026-05-16 20:00 [LTP] [PATCH] " Jinseok Kim
2026-05-17 17:13 ` [LTP] " linuxtestproject.agent

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260609080253.4025-1-linuxtestproject.agent@gmail.com \
    --to=linuxtestproject.agent@gmail.com \
    --cc=always.starving0@gmail.com \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.