Page MenuHomeFreeBSD

hkbd: remove erorr detection in KDSKBSTATE ioctl
ClosedPublic

Authored by aokblast on Thu, Aug 21, 5:34 PM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Aug 26, 10:08 PM
Unknown Object (File)
Tue, Aug 26, 12:09 PM
Unknown Object (File)
Tue, Aug 26, 9:53 AM
Unknown Object (File)
Mon, Aug 25, 10:10 PM
Unknown Object (File)
Mon, Aug 25, 10:00 PM
Unknown Object (File)
Mon, Aug 25, 9:09 PM
Unknown Object (File)
Mon, Aug 25, 8:51 PM
Unknown Object (File)
Mon, Aug 25, 8:21 PM

Details

Summary

The KDSKBSTATE ioctl brings the LED up. However, some keyboard (like qemu
keyboard) may not have LED. Therefore, we remove the error check as ukbd
does to allow the keyboard works correctly in kbdcontrol and vt console.

Sponsored by: The FreeBSD Foundation

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 66444
Build 63327: arc lint + arc unit

Event Timeline

aokblast edited the summary of this revision. (Show Details)
sys/dev/hid/hkbd.c
1573

When explicitly ignoring errors, you should cast the return value to void and ideally add some comment explaining why, if it's not already obvious.

And, what if the KDSETLED is being invoked directly, not through KDSKBSTATE? Presumably we shouldn't hide the error in that case. It looks like it's the KDSKBSTATE ioctl that should be hiding the error.

Adjusted commit message:

The KDSKBSTATE ioctl brings the LED up. However, some keyboards (like qemu
keyboard) may not have LED. Therefore, removing the error check as ukbd(4)
does allow the keyboard works correctly with kbdcontrol(4).

MFC planned?

My second thought is that it seems hkbd_set_leds() has a check if there is no leds and return 0, why it doesn't work with qemu?

Also, I think we can even remove the HID_DEBUG check around hkbd_no_leds. (This seems not a very descriptive name, though...)

sys/dev/hid/hkbd.c
1573

I guess we want to cast to void suppress the compiler warning, and I feel it's good to have a comment to explicitly mention that we intentionally ignore the error.

This comment was removed by aokblast.

Fix in caller instead of fixing in callee

The previous comment is incorrect. I check the HID document. HID has a usage page to locate the LED stuff. And FreeBSD kernel does check if such usage page exists. The problem maybe comes from qemu.

The previous comment is incorrect. I check the HID document. HID has a usage page to locate the LED stuff. And FreeBSD kernel does check if such usage page exists. The problem maybe comes from qemu.

Ok, yes, I was wondering why the /* figure out leds on keyboard */ part in hkbd_parse_hid() doesn't work. If it works then hkbd_set_leds() should work as our expectation.

I mentioned perhaps making hkbd_no_leds a normal sysctl is that it can be used as a workaround for people in ticket 288968.

The previous comment is incorrect. I check the HID document. HID has a usage page to locate the LED stuff. And FreeBSD kernel does check if such usage page exists. The problem maybe comes from qemu.

Ok, yes, I was wondering why the /* figure out leds on keyboard */ part in`hkbd_parse_hid() doesn't work. If it works then hkbd_set_leds()` should work as our expectation.

I mentioned perhaps making hkbd_no_leds a normal sysctl is that it can be used as a workaround for people in ticket 288968.

I locate the problem inside qemu and do some modification then it works. I will submit a patch to qemu later.

I mentioned perhaps making hkbd_no_leds a normal sysctl is that it can be used as a workaround for people in ticket 288968.

I locate the problem inside qemu and do some modification then it works. I will submit a patch to qemu later.

That's great. I feel then we have one more reason to have that sysctl to let people to workaround it before qemu having a new release and being deployed to the production environments.

I mentioned perhaps making hkbd_no_leds a normal sysctl is that it can be used as a workaround for people in ticket 288968.

I locate the problem inside qemu and do some modification then it works. I will submit a patch to qemu later.

That's great. I feel then we have one more reason to have that sysctl to let people to workaround it before qemu having a new release and being deployed to the production environments.

Wouldn't it means I need to create another patch for that? Why not just use the fix in here?

I mentioned perhaps making hkbd_no_leds a normal sysctl is that it can be used as a workaround for people in ticket 288968.

I locate the problem inside qemu and do some modification then it works. I will submit a patch to qemu later.

That's great. I feel then we have one more reason to have that sysctl to let people to workaround it before qemu having a new release and being deployed to the production environments.

Wouldn't it means I need to create another patch for that? Why not just use the fix in here?

In most of case we want to avoid ignoring the return error entirely, as this implicitly hides the error in other places, which might cause other issues in the future.

Hmm, I am on the fence now, indeed it's also not good to ask people to manually set a workaround, even it's just a simple sysctl.

I guess I should accept this, as we can fix qemu but probably harder for Parallel.

After all, can we add some DPRINTF() in KDSKBSTATE or hkbd_set_leds() or KDSETLED to indicate that an error occurs?

I mentioned perhaps making hkbd_no_leds a normal sysctl is that it can be used as a workaround for people in ticket 288968.

I locate the problem inside qemu and do some modification then it works. I will submit a patch to qemu later.

That's great. I feel then we have one more reason to have that sysctl to let people to workaround it before qemu having a new release and being deployed to the production environments.

Wouldn't it means I need to create another patch for that? Why not just use the fix in here?

In most of case we want to avoid ignoring the return error entirely, as this implicitly hides the error in other places, which might cause other issues in the future.

Hmm, I am on the fence now, indeed it's also not good to ask people to manually set a workaround, even it's just a simple sysctl.

I guess I should accept this, as we can fix qemu but probably harder for Parallel.

After all, can we add some DPRINTF() in KDSKBSTATE or hkbd_set_leds() or KDSETLED to indicate that an error occurs?

I don't think it is necessary since we ignore the return value of this ioctl in all other place of kernel and kernel module but I still do it. It also fixes the Parallel according to the PR reply. I think we should let it go ASAP. It affect part of the qemu user (even VPS who use qemu) and all of the Parallel user.

Suggested commit message:

hkbd: Ignore error of setting keyboard LED in KDSKBSTATE ioctl

The KDSKBSTATE ioctl brings the LED up. However, some keyboards (like qemu
keyboard) may not have LEDs. Therefore, removing the error check as ukbd(4)
does allow the keyboard works correctly with kbdcontrol(4).

Also move hw.hid.hkbd.no_leds sysctl out of HID_DEBUG thus users can disable
setting LEDs.

PR: 288968
MFC after 1 week
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D52101
This revision is now accepted and ready to land.Fri, Aug 22, 3:48 AM
ronald_klop.ws added inline comments.
sys/dev/hid/hkbd.c
1601

I think the comment should say “why” it ignores the error. May I suggest something like
/* set LEDs and quit.

Ignore error as some emulators don’t have an actual led and error out. PR: xyz */

Looks ok to me.

sys/dev/hid/hkbd.c
1601

Generally we avoid referencing external resources like bugzilla PRs from sources. The code should be self-contained. But yes it would be nice to include a sentence explaining why this matters.

sys/dev/hid/hkbd.c
1601

Be specific. Which rmulators, what versions, etc. 5 years from now soneone will think they have to rip this out. Knowing the scope of the problem, when it happened, and why the emulators got it wrong are all important details when we are working around quieky hardware

sys/dev/hid/hkbd.c
1601

Also, in this case a PR can provide the context our future selves will need should we revisit the code.

This revision now requires review to proceed.Fri, Aug 22, 3:05 PM
sys/dev/hid/hkbd.c
1601

Does it looks better now?

I believe this is good enough. Let's have this in -CURRENT first and if we still want to modify the comment, we can do that in the MFC waiting period and then MFC all the changes together.

This revision is now accepted and ready to land.Fri, Aug 22, 7:35 PM