Re: [PATCH v2] drivers/tty/serial: check the return value of uart_port_check()

From: Li Zhong
Date: Tue Aug 30 2022 - 03:00:13 EST


On Mon, Aug 29, 2022 at 12:09 AM Ilpo Järvinen
<ilpo.jarvinen@xxxxxxxxxxxxxxx> wrote:
>
> On Sun, 28 Aug 2022, Li Zhong wrote:
>
> > On Fri, Aug 26, 2022 at 9:01 AM Andy Shevchenko
> > <andy.shevchenko@xxxxxxxxx> wrote:
> > >
> > > On Fri, Aug 26, 2022 at 11:38 AM Li Zhong <floridsleeves@xxxxxxxxx> wrote:
> > > >
> > > > uart_port_check() will return NULL pointer when state->uart_port is
> > > > NULL. Check the return value before dereference it to avoid
> > > > null-pointer-dereference error.
> > >
> > > Have you taken the locking into consideration?
> > > If no, please do, if yes, expand your commit message to explain why
> > > the current locking scheme doesn't prevent an error from happening.
> > >
> >
> > The locking is taken into consideration but these three checks do not need to
> > unlock in error-handling because unlock() will be called in the callers. Will
> > add the comment in v2 patch.
>
> I think he meant you should indicate why the current locking doesn't cover
> the case you're fixing, not whether this function should call unlock() or
> not.
>

Thanks for clarifications. The locking does not guarantee the return value of
uart_port_check() is not NULL. Actually in line 773 of this file
(drivers/tty/serial/serial_core.c), uart_port_check() is also called in
critical section but still there is check on whether the return value is NULL.

> --
> i.
>