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>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Sat, 17 Oct 2020 13:06:14 +0000
From:   Barnabás Pőcze <pobrn@...tonmail.com>
To:     Coiby Xu <coiby.xu@...il.com>
Cc:     "linux-input@...r.kernel.org" <linux-input@...r.kernel.org>,
        Helmut Stult <helmut.stult@...info.de>,
        "stable@...r.kernel.org" <stable@...r.kernel.org>,
        Jiri Kosina <jikos@...nel.org>,
        Benjamin Tissoires <benjamin.tissoires@...hat.com>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v2] HID: i2c-hid: add polling mode based on connected GPIO chip's pin status

Hi

> [...]
> >> +static int get_gpio_pin_state(struct irq_desc *irq_desc)
> >> +{
> >> +	struct gpio_chip *gc = irq_data_get_irq_chip_data(&irq_desc->irq_data);
> >> +
> >> +	return gc->get(gc, irq_desc->irq_data.hwirq);
> >> +}
> >> +
> >> +static bool interrupt_line_active(struct i2c_client *client)
> >> +{
> >> +	unsigned long trigger_type = irq_get_trigger_type(client->irq);
> >> +	struct irq_desc *irq_desc = irq_to_desc(client->irq);
> >> +
> >> +	/*
> >> +	 * According to Windows Precsiontion Touchpad's specs
> >> +	 * https://docs.microsoft.com/en-us/windows-hardware/design/component-guidelines/windows-precision-touchpad-device-bus-connectivity,
> >> +	 * GPIO Interrupt Assertion Leve could be either ActiveLow or
> >> +	 * ActiveHigh.
> >> +	 */
> >> +	if (trigger_type & IRQF_TRIGGER_LOW)
> >> +		return !get_gpio_pin_state(irq_desc);
> >> +
> >> +	return get_gpio_pin_state(irq_desc);
> >> +}
> >
> >Excuse my ignorance, but I think some kind of error handling regarding the return
> >value of `get_gpio_pin_state()` should be present here.
> >
> What kind of errors would you expect? It seems (struct gpio_chip *)->get
> only return 0 or 1.
> >

I read the code of a couple gpio chips and - I may be wrong, but - it seems they
can return an arbitrary errno.


> >> +
> >> +static int i2c_hid_polling_thread(void *i2c_hid)
> >> +{
> >> +	struct i2c_hid *ihid = i2c_hid;
> >> +	struct i2c_client *client = ihid->client;
> >> +	unsigned int polling_interval_idle;
> >> +
> >> +	while (1) {
> >> +		/*
> >> +		 * re-calculate polling_interval_idle
> >> +		 * so the module parameters polling_interval_idle_ms can be
> >> +		 * changed dynamically through sysfs as polling_interval_active_us
> >> +		 */
> >> +		polling_interval_idle = polling_interval_idle_ms * 1000;
> >> +		if (test_bit(I2C_HID_READ_PENDING, &ihid->flags))
> >> +			usleep_range(50000, 100000);
> >> +
> >> +		if (kthread_should_stop())
> >> +			break;
> >> +
> >> +		while (interrupt_line_active(client)) {
> >
> >I realize it's quite unlikely, but can't this be a endless loop if data is coming
> >in at a high enough rate? Maybe the maximum number of iterations could be limited here?
> >
> If we find HID reports are constantly read and send to front-end
> application like libinput, won't it help expose the problem of the I2C
> HiD device?
> >

I'm not sure I completely understand your point. The reason why I wrote what I wrote
is that this kthread could potentially could go on forever (since `kthread_should_stop()`
is not checked in the inner while loop) if the data is supplied at a high enough rate.
That's why I said, to avoid this problem, only allow a certain number of iterations
for the inner loop, to guarantee that the kthread can stop in any case.


> >> +			i2c_hid_get_input(ihid);
> >> +			usleep_range(polling_interval_active_us,
> >> +				     polling_interval_active_us + 100);
> >> +		}
> >> +
> >> +		usleep_range(polling_interval_idle,
> >> +			     polling_interval_idle + 1000);
> >> +	}
> >> +
> >> +	do_exit(0);
> >> +	return 0;
> >> +}
> [...]
> >Excuse my ignorance, but I do not understand why the following two changes are not enough:
> >
> >in `i2c_hid_suspend()`:
> > if (polling_mode == I2C_POLLING_DISABLED)
> >   disable_irq(client->irq);
> >
> >in `i2c_hid_resume()`:
> > if (polling_mode == I2C_POLLING_DISABLED)
> >   enable_irq(client->irq);
> >
> I think we shouldn't call enable/disable_irq_wake in polling mode
> where we don't set up irq.

I think I now understand what you mean. I'm not sure, but it seems logical to me
that you can enable/disable irq wake regardless whether any irq handlers are
registered or not. Therefore, I figure it makes sense to take the safe path,
and don't touch irq wake when polling, just as you did.


> [...]


Regards,
Barnabás Pőcze

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ