From 3aa7f6e29871c06537ab95bf2a14b5eb3ca6e847 Mon Sep 17 00:00:00 2001 From: Stefan Haberland Date: Thu, 27 Oct 2022 15:51:00 +0200 Subject: [PATCH] libdasd: fix ioctl macro to return also positive return codes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In case of an error the ioctl macro only returns errno to the calling function. This misses positive returncodes from ioctls. Change the macro to also return positive return codes. Signed-off-by: Stefan Haberland Reviewed-by: Jan Hoeppner Signed-off-by: Jan Höppner --- libdasd/dasd_ioctl.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libdasd/dasd_ioctl.c b/libdasd/dasd_ioctl.c index 40e726c8..3a36375b 100644 --- a/libdasd/dasd_ioctl.c +++ b/libdasd/dasd_ioctl.c @@ -28,11 +28,13 @@ #define RUN_IOCTL(fd, req, argp) \ do { \ - if (ioctl(fd, req, argp) != 0) { \ - int err = errno; \ - if (err != EBADF) \ + int rc = ioctl(fd, req, argp); \ + if (rc != 0) { \ + if (rc == -1) \ + rc = errno; \ + if (rc != EBADF) \ dasd_close_device(fd); \ - return err; \ + return rc; \ } \ } while (0)