lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Date:   Mon, 25 Oct 2021 15:57:06 +0300
From:   "andriy.shevchenko" <andriy.shevchenko@...ux.intel.com>
To:     "changlianzhi@...ontech.com" <changlianzhi@...ontech.com>
Cc:     linux-kernel <linux-kernel@...r.kernel.org>,
        "dmitry.torokhov" <dmitry.torokhov@...il.com>,
        gregkh <gregkh@...uxfoundation.org>,
        jirislaby <jirislaby@...nel.org>, 282827961 <282827961@...com>
Subject: Re: [PATCH v6] tty: Fix the keyboard led light display problem

On Mon, Oct 25, 2021 at 12:24:45PM +0800, changlianzhi@...ontech.com wrote:
> On Mon, Oct 25, 2021 at 01:29:18AM +0800, changlianzhi@...ontech.com wrote:
> > > >>On Thu, Oct 21, 2021 at 10:05:11AM +0800, lianzhi chang wrote:

...

> > > >> +	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!
> 
> Hello, I did not do that. For the complete code, please check the
> "patch v6" email I sent earlier. My code is like this:

> +static void kbd_update_ledstate(struct input_dev *dev)
> +{
> +	unsigned long leds;
> +
> +	leds = (unsigned long)ledstate;
> +
> +	if (!!test_bit(LED_NUML, dev->led) != !!test_bit(VC_NUMLOCK, &leds))
> +	ledstate ^= BIT(VC_NUMLOCK);
> +	if (!!test_bit(LED_CAPSL, dev->led) != !!test_bit(VC_CAPSLOCK, &leds))
> +	ledstate ^= BIT(VC_CAPSLOCK);
> +	if (!!test_bit(LED_SCROLLL, dev->led) != !!test_bit(VC_SCROLLOCK, &leds))
> +	ledstate ^= BIT(VC_SCROLLOCK);
> +}

> I mean, the second parameter of test_bit is "volatile unsigned long *addr",
> which is a pointer. And ledstate is an unsigned int type, so I defined an
> unsigned long type leds, assign the ledstate to the leds after forced
> conversion, and then when calling the test_bit function, get the address
> of the leds as a parameter.

This all is fine, but why casting is needed? I didn't still get.

-- 
With Best Regards,
Andy Shevchenko


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ