Re: [LTP] [PATCH v2 1/2] lib: tst_rtctime: close RTC fd on the ioctl() error path

Andrea Cervesato via ltp <[email protected]> Tue, 21 Jul 2026 13:02:22 +0000
Newsgroups it.linux.lists.ltp
Message-ID <[email protected]>
Hi Kuba,

>  	ret = ioctl(rtc_fd, request, rtc_tm);
>  
> -	if (ret != 0)
> -		return -1;
> +	if (ret != 0) {
> +		int saved_errno = errno;
>  
> -	if (rtc_fd > 0)
>  		SAFE_CLOSE(rtc_fd);
> +		errno = saved_errno;
> +		return -1;
> +	}
> +
> +	SAFE_CLOSE(rtc_fd);
>  
>  	return 0;
>  }

Why do we need to store the errno? Simply call SAFE_CLOSE() before
returning -1. If SAFE_CLOSE() fails, test will break anyway..

--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp