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

From: Jakub Kicinski <[email-masked]>
Date: Wed, 4 Mar 2026 17:39:56 -0800

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..