As linus said at the below commit, commit 07d106d0a33d6063d2061305903deb02489eba20 Author: Linus Torvalds <torva...@linux-foundation.org> Date: Thu Jan 5 15:40:12 2012 -0800
vfs: fix up ENOIOCTLCMD error handling We're doing some odd things there, which already messes up various users (see the net/socket.c code that this removes), and it was going to add yet more crud to the block layer because of the incorrect error code translation. ENOIOCTLCMD is not an error return that should be returned to user mode from the "ioctl()" system call, but it should *not* be translated as EINVAL ("Invalid argument"). It should be translated as ENOTTY ("Inappropriate ioctl for device"). That EINVAL confusion has apparently so permeated some code that the block layer actually checks for it, which is sad. We continue to do so for now, but add a big comment about how wrong that is, and we should remove it entirely eventually. In the meantime, this tries to keep the changes localized to just the EINVAL -> ENOTTY fix, and removing code that makes it harder to do the right thing. Signed-off-by: Linus Torvalds <torva...@linux-foundation.org> Return ENOTTY is right. And with the tty driver change with below commit, commit bbb63c514a3464342967237a51a21ea8f61ab951 Author: Wanlong Gao <gaowanl...@cn.fujitsu.com> Date: Mon Aug 27 15:23:12 2012 +0800 drivers:tty:fix up ENOIOCTLCMD error handling At commit 07d106d0, Linus pointed out that ENOIOCTLCMD should be translated as ENOTTY to user mode. For example: fd = open("/dev/tty", O_RDWR); ioctl(fd, -1, &argp); then the errno should be ENOTTY but not EINVAL. Signed-off-by: Wanlong Gao <gaowanl...@cn.fujitsu.com> Acked-by: Alan Cox <a...@linux.intel.com> Signed-off-by: Greg Kroah-Hartman <gre...@linuxfoundation.org> The tty driver will return the right ENOTTY in upstream kernel when passed a invalid ioctl command, so we fixed the LTP test case to suit this return value change. --- testcases/kernel/syscalls/ioctl/ioctl01.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/testcases/kernel/syscalls/ioctl/ioctl01.c b/testcases/kernel/syscalls/ioctl/ioctl01.c index 8b044e7..fdfc93b 100644 --- a/testcases/kernel/syscalls/ioctl/ioctl01.c +++ b/testcases/kernel/syscalls/ioctl/ioctl01.c @@ -86,8 +86,11 @@ struct test_case_t { { &fd, TCGETA, (struct termio *)-1, EFAULT}, /* command is invalid */ + /* This errno value was changed from EINVAL to ENOTTY + * by kernel commit 07d106d0 and bbb63c51 + */ { - &fd, INVAL_IOCTL, &termio, EINVAL}, + &fd, INVAL_IOCTL, &termio, ENOTTY}, /* file descriptor is for a regular file */ { &fd1, TCGETA, &termio, ENOTTY}, @@ -143,12 +146,18 @@ int main(int ac, char **av) TEST_ERROR_LOG(TEST_ERRNO); - if (TEST_ERRNO == TC[i].error) + if (TEST_ERRNO == TC[i].error) { tst_resm(TPASS|TTERRNO, "failed as expected"); - else - tst_resm(TFAIL|TTERRNO, - "failed unexpectedly; expected %d - %s", - TC[i].error, strerror(TC[i].error)); + } else { + if ((i == 2) && (TEST_ERRNO == EINVAL) && + (tst_kvercmp(3, 7, 0) < 0)) + tst_resm(TPASS|TTERRNO, + "failed as expected"); + else + tst_resm(TFAIL|TTERRNO, + "failed unexpectedly; expected %d - %s", + TC[i].error, strerror(TC[i].error)); + } } } cleanup(); -- 1.8.0 ------------------------------------------------------------------------------ LogMeIn Central: Instant, anywhere, Remote PC access and management. Stay in control, update software, and manage PCs from one command center Diagnose problems and improve visibility into emerging IT issues Automate, monitor and manage. Do more in less time with Central http://p.sf.net/sfu/logmein12331_d2d _______________________________________________ Ltp-list mailing list Ltp-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ltp-list