[LTP] power_management: rewrite runpwtests04.sh in C
linuxtestproject.agent@gmail.com
linuxtestproject.agent@gmail.com
Tue Jun 9 10:02:53 CEST 2026
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
More information about the ltp
mailing list