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 PHC | |
Open Source and information security mailing list archives
| ||
|
Date: Sun, 22 Nov 2020 13:33:01 +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 v3] HID: i2c-hid: add polling mode based on connected GPIO chip's pin status Hi 2020. november 22., vasárnap 11:15 keltezéssel, Coiby Xu írta: > [...] > >> +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); > >> +} > [...] > >> + ssize_t status = get_gpio_pin_state(irq_desc); > > > >`get_gpio_pin_state()` returns an `int`, so I am not sure why `ssize_t` is used here. > > > > I used `ssize_t` because I found gpiolib-sysfs.c uses `ssize_t` > > // drivers/gpio/gpiolib-sysfs.c > static ssize_t value_show(struct device *dev, > struct device_attribute *attr, char *buf) > { > struct gpiod_data *data = dev_get_drvdata(dev); > struct gpio_desc *desc = data->desc; > ssize_t status; > > mutex_lock(&data->mutex); > > status = gpiod_get_value_cansleep(desc); > ... > return status; > } > > According to the book Advanced Programming in the UNIX Environment by > W. Richard Stevens, > With the 1990 POSIX.1 standard, the primitive system data type > ssize_t was introduced to provide the signed return value... > > So ssize_t is fairly common, for example, the read and write syscall > return a value of type ssize_t. But I haven't found out why ssize_t is > better int. > > Sorry if I wasn't clear, what prompted me to ask that question is the following: `gc->get()` returns `int`, `get_gpio_pin_state()` returns `int`, yet you still save the return value of `get_gpio_pin_state()` into a variable with type `ssize_t` for no apparent reason. In the example you cited, `ssize_t` is used because the show() callback of a sysfs attribute must return `ssize_t`, but here, `interrupt_line_active()` returns `bool`, so I don't see any advantage over a plain `int`. Anyways, I believe either one is fine, I just found it odd. > >> + > >> + if (status < 0) { > >> + dev_warn(&client->dev, > >> + "Failed to get GPIO Interrupt line status for %s", > >> + client->name); > > > >I think it's possible that the kernel message buffer is flooded with these > >messages, which is not optimal in my opinion. > > > Thank you! Replaced with dev_dbg in v4. > [...] Have you looked at `dev_{warn,dbg,...}_ratelimited()`? Regards, Barnabás Pőcze
Powered by blists - more mailing lists