linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Дилян Палаузов" <dilyan.palauzov@aegee.org>
To: Jiri Kosina <jikos@kernel.org>, Benjamin Tissoires <bentiss@kernel.org>
Cc: linux-input@vger.kernel.org
Subject: ioctl handler of the hidraw driver should return ENOIOCTLCMD for numbers it does not want to handle | tcgetattr() ⇔ ioctl(, TCGETS2, …) sets errno to undocumented EINVAL/22
Date: Tue, 04 Nov 2025 14:48:54 +0200	[thread overview]
Message-ID: <24eaed9105633d03eded13e11c5a994bd93a81aa.camel@aegee.org> (raw)

Hello,

With kernel 6.17.6 on x86_64 and glibc 2.42 the below program substitutes tcgetattr() with ioctl(…, TCGETS2, …) and sets errno to 22 / Invalid argument / EINVAL.  The only difference for kernel 6.6.60 on armv7l 2.26 is that the substitution has no 2, tcgetattr() translates to ioctl(…, TCGETS, …).

For tcgetattr() only errno EBADF and ENOTTY are documented at https://sourceware.org/glibc/manual/latest/html_mono/libc.html#index-tcgetattr , at https://man7.org/linux/man-pages/man3/tcgetattr.3p.html and at https://pubs.opengroup.org/onlinepubs/9799919799/functions/tcgetattr.html (Open Group Base Specifications Issue 8/year 2024).

In this concrete case changes to the man7.org documentation must be triggered by the Austin Group - https://lore.kernel.org/linux-man/dsb6oiv7q7ra3gbu4bovy3gah522lgsf3d6h3wxwe4ieuka6fh@g6u5qzlyoxf5/ and but https://sourceware.org/bugzilla/show_bug.cgi?id=33597 suggests this is a kernel bug.

For hidraw devices the possible ioctl commands are mentioned at https://docs.kernel.org/hid/hidraw.html#ioctl, TCGETS and TCGETS2 are not among them, so I was expecting a ENOTTY error.  This problem might also happen for to tcsetattr() - I have not checked it.

#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <termios.h>

void main() {
  int fd = open("/dev/hidraw0", O_RDWR | O_NONBLOCK |O_NOCTTY);
  struct termios s;
  errno = 0;
  int ret = tcgetattr(fd, &s);
  printf("Returned fd is %i ret is %i errno is %i %m\n", fd, ret, errno);
}

The above produces:

Returned fd is 3 ret is -1 errno is 22 Invalid argument

Kind regards // Дилян

                 reply	other threads:[~2025-11-04 12:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=24eaed9105633d03eded13e11c5a994bd93a81aa.camel@aegee.org \
    --to=dilyan.palauzov@aegee.org \
    --cc=bentiss@kernel.org \
    --cc=jikos@kernel.org \
    --cc=linux-input@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).