From: Michael Zaidman <michael.zaidman@gmail.com>
To: Jiri Slaby <jirislaby@kernel.org>
Cc: Michael Zaidman <michael.zaidman@gmail.com>,
Jiri Kosina <jikos@kernel.org>,
Benjamin Tissoires <bentiss@kernel.org>,
Linus Walleij <linusw@kernel.org>,
Bartosz Golaszewski <brgl@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Raman Varabets <kernel-linux-20260610-80b7ab08@raman.v1.sg>,
Germain Hebert <germain.hebert@ca.abb.com>,
Christina Quast <contact@christina-quast.de>,
Rio Liu <rio@r26.me>, Bruno Giacomazzi <brunoceg1@gmail.com>,
Daniel Beer <daniel.beer@igorinstitute.com>,
linux-input@vger.kernel.org, linux-serial@vger.kernel.org,
linux-gpio@vger.kernel.org, linux-i2c@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 01/16] HID: ft260: add serial driver
Date: Wed, 18 Nov 2026 18:38:50 +0200 [thread overview]
Message-ID: <20261118163935.28515-1-michael.zaidman@gmail.com> (raw)
In-Reply-To: <0c96e0ee-55e7-4999-922e-bc52aa516d2e@kernel.org>
On Wed, Nov 18, 2026 at 08:21:18AM +0100, Jiri Slaby wrote:
Thank you for the review.
First a question about where the fixes go. Patch 1/16 is Christina's
v4 serial driver [1], ported to the current kernel. It also has a few
fixes to her code; its commit message lists them. Patch 2/16 is my
own patch. It has the fixes her code needed on hardware and the fixes
for the review of the patch 1 code. Jiri Kosina agreed to this layout
in June; "As agreed with Jiri" in the cover letter means him. The goal
is that Christina stays the author of the code she wrote, and the
fixes on top of it are mine.
Some of your points are already fixed in patch 2. The others I will
fix in v5. Are you fine with the v5 fixes for the patch 1 code also
going in patch 2? Patch 1 then stays as it is, except for the two I2C
hunks that you asked to move out (see below).
[1] https://lore.kernel.org/all/20231218093153.192268-1-contact@christina-quast.de/
>> +#include <linux/serial.h>
>> +#include <linux/serial_core.h>
>> +#include <linux/kfifo.h>
>> +#include <linux/tty_flip.h>
>> +#include <linux/minmax.h>
>> +#include <linux/unaligned.h>
>
> Sort these.
Will do in v5. Patches 3, 4, 8 and 11 also add includes out of order.
Patch 2 sorts the list, and the later patches add their includes in
order.
>> + struct kfifo xmit_fifo;
>
> Why not to use port.xmit_fifo?
v5 uses port.xmit_fifo, with tty_port_alloc_xmit_buf(). More on the
size below.
>> - hid_err(hdev, "%s: failed to start transfer, ret %d\n",
>> + hid_dbg(hdev, "%s: failed to start transfer, ret %d\n",
[...]
>> - pr_info("%s: off %#x rlen %d wlen %d\n", __func__,
>> + ft260_dbg("%s: off %#x rlen %d wlen %d\n", __func__,
>
> There should be likely a separate patch with the above two hunks.
Agreed. In v5 both hunks leave patch 1. The pr_info() to ft260_dbg()
change goes in patch 6, which lowers the severity of other I2C
messages. The hid_err() stays: patch 6 keeps it for transport
failures.
>> -static int ft260_is_interface_enabled(struct hid_device *hdev)
>> +static int ft260_get_interface_type(struct hid_device *hdev, struct ft260_device *dev)
>
> Switch int to the enum then?
I would like to keep int. The function also returns the negative errno
of ft260_get_system_config(). The enum has no negative values, so GCC
gives it an unsigned type, and a "ret < 0" check in the caller would
not see the error.
>> +static DEFINE_MUTEX(ft260_uart_list_lock);
>> +static LIST_HEAD(ft260_uart_device_list);
>
> Is IDR or IDA not a better fit?
Yes, an IDR. The driver needs the lowest free index and also the port
for an index, so an IDA alone is not enough. v5 uses idr_alloc() and
idr_find() in place of the list walks, as cdc-acm does.
>> + spin_lock_init(&port->write_lock);
>
> Should this be initialized when the port is allocated. This is confusing.
In v5 it moves to ft260_uart_probe(), next to the other UART setup
(INIT_WORK(), timer_setup(), tty_port_init()), before the port is
added. The other choice is ft260_probe(), where the port is
allocated. But ft260_probe() allocates the struct for each
interface, I2C or UART, and only the UART code uses this lock.
>> + if (kfifo_alloc(&port->xmit_fifo, FIFO_SIZE, GFP_KERNEL))
>> + return -ENOMEM;
>
> tty_port_alloc_xmit_buf() then? Is PAGE_SIZE too much? Then refactor
> tty_port_alloc_xmit_buf() to allow size to be passed ;).
Yes. Patch 2 already sets the FIFO size to PAGE_SIZE, so
tty_port_alloc_xmit_buf() fits as it is, and tty_port_destructor()
frees the buffer.
>> + mutex_lock(&ft260_uart_list_lock);
>
> guard()
Patch 16 converts all mutex_lock() calls in the driver to guards, this
one included. The guards are in the last patch on purpose: I also
maintain an out-of-tree version of this driver for kernels older than
6.5, which do not have linux/cleanup.h, and it can leave that patch
out.
>> + mutex_lock(&ft260_uart_list_lock);
>> + list_del(&port->device_list);
>> + mutex_unlock(&ft260_uart_list_lock);
>> +
>> + tty_port_tty_vhangup(&port->port);
>> +
>> + spin_lock(&port->write_lock);
>> + kfifo_free(&port->xmit_fifo);
>> + spin_unlock(&port->write_lock);
>
> scoped_guard() × 2.
Patch 2 moves the list_del() to the port destructor, and patch 16
puts it in scoped_guard(). The spin_lock() pairs on this lock, now
xmit_fifo_lock, are not converted yet. In v5 patch 2 makes all users
of the lock take it with irqsave: a line discipline can call ->write
from softirq (ppp_async does, from a tasklet), and ->write takes this
lock. Patch 16 then puts them in guards, together with the other
spinlock of the driver, read_lock.
>> + tty = tty_port_tty_get(&port->port);
>
> scoped_guard(tty_port_tty)
Will do in v5 in patch 16, here and in ft260_uart_change_speed().
These are the only two tty_port_tty_get() calls in the driver.
>> + len = kfifo_in_locked(&port->xmit_fifo, buf, count, &port->write_lock);
>
> So you put it into kfifo, and:
>
>> + ft260_dbg("count: %zu, len: %d", count, len);
>> +
>> + ret = ft260_uart_transmit_chars(port);
>
> remove it from the fifo immediately? What's the reason to do this double
> copy?
>
> Oh, the fifo can have more than fits into the HW fifo? Did I miss where
> ft260_uart_transmit_chars() is called to send the remaining bits?
Patch 2 changes this. In patch 1, ft260_uart_transmit_chars() sends
the rest in a loop in the same call, but the send sleeps, and ->write
must not sleep. From patch 2 on, ft260_uart_write() only copies the
data into the kfifo and schedules tx_work. The work sends the kfifo in
reports of up to 60 bytes until it is empty. So the copy is needed:
the data waits in the kfifo until the work sends it.
>> + seq_printf(m, "ft260 info:1.0 driver%s%s revision:%s\n",
>> + "", "", "");
>
> Does HID require wrap at 80 cols? This should be on one line these days.
Patch 2 puts it on one line.
>> + if (port) {
>
> Perhaps invert the condition, add a "continue" and save one indent level?
Will do in v5.
>> + // FIXME: Do I need that if I have cancel_work_sync?
>> + // FIXME: are all kfifo access secured by lock? with irq or not?
>
> YOU FIX then :).
Patches 2 and 3 remove both comments. The answers:
The reschedule_work flag is needed. cancel_work_sync() runs only when
the device goes away. The flag switches the wakeup workaround on and
off while the port is in use, when the chip has power saving enabled:
it is set above 4800 baud and cleared at port shutdown. The timer
arms again, and the work sends its report, only while the flag is
set.
No. Even at the end of the series, ft260_uart_write_room() and
ft260_uart_chars_in_buffer() read the kfifo with no lock, and four
paths take the lock with spin_lock(). In v5 every access takes it,
with irqsave.
>> + /* We cannot used devm_kzalloc here, because port has to survive until
>> + * destroy function call
>
> multiline comments are introduced by /* on its own line.
> "used" -> "use".
Patch 2 fixes both.
>> + hid_info(hdev, "chip code: %02x%02x %02x%02x\n",
>> + version.chip_code[0], version.chip_code[1],
>> + version.chip_code[2], version.chip_code[3]);
>
> Is this dump useful?
I would like to keep it. It was in the driver before this series, and
it is the only place that prints the chip version.
>> + if (!dev->ft260_is_serial) {
>
> Inverting the condition would make more sense for me.
Already done in patch 2.
>> + pr_err("tty_alloc_driver failed: %d\n",
>> + (int)PTR_ERR(ft260_tty_driver));
>
> Why the cast? Use %ld.
Will do in v5.
Thanks,
Michael
next prev parent reply other threads:[~2026-11-18 16:39 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 20:04 [PATCH v4 00/16] HID: ft260: add UART and GPIO support, plus I2C fixes Michael Zaidman
2026-11-17 20:04 ` [PATCH v4 01/16] HID: ft260: add serial driver Michael Zaidman
2026-11-18 7:21 ` Jiri Slaby
2026-11-18 16:38 ` Michael Zaidman [this message]
2026-11-17 20:04 ` [PATCH v4 02/16] HID: ft260: uart: fix " Michael Zaidman
2026-11-17 20:04 ` [PATCH v4 03/16] HID: ft260: add GPIO support Michael Zaidman
2026-11-17 20:04 ` [PATCH v4 04/16] HID: ft260: i2c: reduce driver module loading time Michael Zaidman
2026-11-17 20:04 ` [PATCH v4 05/16] HID: ft260: fix sysfs store failure notice for big numbers Michael Zaidman
2026-11-17 20:04 ` [PATCH v4 06/16] HID: ft260: i2c: reduce bus-error message severity Michael Zaidman
2026-11-17 20:04 ` [PATCH v4 07/16] HID: ft260: uart: enable flow control Michael Zaidman
2026-11-17 20:04 ` [PATCH v4 08/16] HID: ft260: uart: add modem pins control via ioctl Michael Zaidman
2026-11-17 23:56 ` Maarten Brock
2026-11-18 16:40 ` Michael Zaidman
2026-11-17 20:04 ` [PATCH v4 09/16] HID: ft260: group sysfs attrs per HID interface Michael Zaidman
2026-11-17 20:04 ` [PATCH v4 10/16] HID: ft260: i2c: fix large write transaction failure Michael Zaidman
2026-11-17 20:04 ` [PATCH v4 11/16] HID: ft260: workaround for TN_189 errata endpoint STALL after enumeration Michael Zaidman
2026-11-17 20:04 ` [PATCH v4 12/16] HID: ft260: i2c: abort in-flight transfers with STOP before reset Michael Zaidman
2026-11-17 20:04 ` [PATCH v4 13/16] HID: ft260: i2c: reject an I2C clock outside the supported range Michael Zaidman
2026-11-17 20:04 ` [PATCH v4 14/16] HID: ft260: i2c: fix i2c_reset sysfs store return value Michael Zaidman
2026-11-17 20:04 ` [PATCH v4 15/16] HID: ft260: i2c: recover a bus held by a slave Michael Zaidman
2026-11-17 20:04 ` [PATCH v4 16/16] HID: ft260: use lock guards Michael Zaidman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261118163935.28515-1-michael.zaidman@gmail.com \
--to=michael.zaidman@gmail.com \
--cc=bentiss@kernel.org \
--cc=brgl@kernel.org \
--cc=brunoceg1@gmail.com \
--cc=contact@christina-quast.de \
--cc=daniel.beer@igorinstitute.com \
--cc=germain.hebert@ca.abb.com \
--cc=gregkh@linuxfoundation.org \
--cc=jikos@kernel.org \
--cc=jirislaby@kernel.org \
--cc=kernel-linux-20260610-80b7ab08@raman.v1.sg \
--cc=linusw@kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=rio@r26.me \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®