Linux-Watchdog Archive on lore.kernel.org
 help / color / Atom feed
* watchdog ioctl inconsistencies
@ 2019-08-26 12:54 Rasmus Villemoes
  2019-08-27  0:19 ` Guenter Roeck
  0 siblings, 1 reply; 2+ messages in thread
From: Rasmus Villemoes @ 2019-08-26 12:54 UTC (permalink / raw)
  To: linux-watchdog

Hi,

uapi/linux/watchdog.h has these

#define WDIOC_SETOPTIONS        _IOR(WATCHDOG_IOCTL_BASE, 4, int)

This is a write from userspace perspective, so should have been _IOW.

#define WDIOC_KEEPALIVE         _IOR(WATCHDOG_IOCTL_BASE, 5, int)

This one doesn't actually take an argument, so should just have been an
_IO - or if anything, an _IOW. One could be misled to think that if the
int argument has 'V' somewhere (perhaps first or last byte, depending on
endianness) that would count as a magic close.

#define WDIOC_SETTIMEOUT        _IOWR(WATCHDOG_IOCTL_BASE, 6, int)
#define WDIOC_SETPRETIMEOUT     _IOWR(WATCHDOG_IOCTL_BASE, 8, int)

The SETTIMEOUT handling does fall through to the GETTIMEOUT case, so
that one is indeed a "write this, but tell me what value actually took
effect". The SETPRETIMEOUT case ends with a break, so that one is really
_IOW.

There's not much to do about these, I think, but perhaps one could add a
comment to the uapi header containing the magic explains-all phrase
"historical reasons".

Does any static checker actually know about these conventions and peek
inside the _IO*() macros when used as an argument to ioctl(), comparing
the type and constness of the third argument to the direction/type
implied by the macro?

Rasmus

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: watchdog ioctl inconsistencies
  2019-08-26 12:54 watchdog ioctl inconsistencies Rasmus Villemoes
@ 2019-08-27  0:19 ` Guenter Roeck
  0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2019-08-27  0:19 UTC (permalink / raw)
  To: Rasmus Villemoes, linux-watchdog

On 8/26/19 5:54 AM, Rasmus Villemoes wrote:
> Hi,
> 
> uapi/linux/watchdog.h has these
> 
> #define WDIOC_SETOPTIONS        _IOR(WATCHDOG_IOCTL_BASE, 4, int)
> 
> This is a write from userspace perspective, so should have been _IOW.
> 
> #define WDIOC_KEEPALIVE         _IOR(WATCHDOG_IOCTL_BASE, 5, int)
> 
> This one doesn't actually take an argument, so should just have been an
> _IO - or if anything, an _IOW. One could be misled to think that if the
> int argument has 'V' somewhere (perhaps first or last byte, depending on
> endianness) that would count as a magic close.
> 
> #define WDIOC_SETTIMEOUT        _IOWR(WATCHDOG_IOCTL_BASE, 6, int)
> #define WDIOC_SETPRETIMEOUT     _IOWR(WATCHDOG_IOCTL_BASE, 8, int)
> 
> The SETTIMEOUT handling does fall through to the GETTIMEOUT case, so
> that one is indeed a "write this, but tell me what value actually took
> effect". The SETPRETIMEOUT case ends with a break, so that one is really
> _IOW.
> 
> There's not much to do about these, I think, but perhaps one could add a
> comment to the uapi header containing the magic explains-all phrase
> "historical reasons".
> 
Those ioctls were imported into git when the git repository was created.
I don't think it is worth bothering about it now. I also don't think it
would add much if any value to add "historic reason" comments.

Guenter

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-26 12:54 watchdog ioctl inconsistencies Rasmus Villemoes
2019-08-27  0:19 ` Guenter Roeck

Linux-Watchdog Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-watchdog/0 linux-watchdog/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-watchdog linux-watchdog/ https://lore.kernel.org/linux-watchdog \
		linux-watchdog@vger.kernel.org linux-watchdog@archiver.kernel.org
	public-inbox-index linux-watchdog


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-watchdog


AGPL code for this site: git clone https://public-inbox.org/ public-inbox