Re: [net,v4] serial: caif: hold tty->link reference in ldisc_open and ser_release

From: Jakub Kicinski

Date: Wed Mar 04 2026 - 20:41:27 EST


On Wed, 4 Mar 2026 20:23:20 -0500 Shuangpeng wrote:
> > Can this dereference NULL? The tty->link field is only set for PTY
> > (pseudo-terminal) pairs. For regular serial ports and other non-PTY
> > devices, tty->link is NULL.
> >
> > The CAIF line discipline can be attached to any TTY device via the
> > TIOCSETD ioctl. When ser_release() is called to clean up a ser_device
> > that was created for a non-PTY TTY device, tty->link would be NULL.
> >
> > Should this check for NULL before calling tty_kref_put()?
> >
>
> tty_kref_get() / tty_kref_put() are NULL-safe, so calling them with
> tty->link == NULL is not a functional issue.
>
> I can add explicit if (tty->link) guards to improve readability if you prefer.

Sorry, I should have checked, I'm surprised the AI agent got something
this basic wrong. Just the Fixes tag, then..