Re: [PATCH v6] tty: Fix the keyboard led light display problem

From: andriy.shevchenko
Date: Mon Oct 25 2021 - 08:03:34 EST


On Mon, Oct 25, 2021 at 01:29:18AM +0800, changlianzhi@xxxxxxxxxxxxx wrote:
> >>On Thu, Oct 21, 2021 at 10:05:11AM +0800, lianzhi chang wrote:
> >> Switching from the desktop environment to the tty environment,
> >> the state of the keyboard led lights and the state of the keyboard
> >> lock are inconsistent. This is because the attribute kb->kbdmode
> >> of the tty bound in the desktop environment (xorg) is set to
> >> VC_OFF, which causes the ledstate and kb->ledflagstate
> >> values of the bound tty to always be 0, which causes the switch
> >> from the desktop When to the tty environment, the LED light
> >> status is inconsistent with the keyboard lock status.
>
> >...
>
> >> + unsigned long leds;
> >> +
> >> + leds = (unsigned long)ledstate;
>
> >Can be one line.
>
> >But most important question you are ignoring to answer / address is why do you
> >use casting?

> >>But most important question you are ignoring to answer / address is why do you
> >>use casting?
> Casting is used here because:
> The second parameter of test_bit is "volatile unsigned long *addr" (see constant_test_bit() in /arch/x86/include/asm/bitops.h), but ledstate is an "unsigned int" type. If casting is not used,
> compile Will report an error.

Wait, you are casting pointer to an integer?!
This is completely wrong in this case!

--
With Best Regards,
Andy Shevchenko