* [PATCH v1 1/1] tty: Drop duplicate NULL check in TTY port functions
@ 2022-02-02 16:57 Andy Shevchenko
2022-02-03 8:36 ` Jiri Slaby
0 siblings, 1 reply; 5+ messages in thread
From: Andy Shevchenko @ 2022-02-02 16:57 UTC (permalink / raw)
To: Greg Kroah-Hartman, Jiri Slaby, linux-kernel; +Cc: Andy Shevchenko
The free_page(addr), which becomes free_pages(addr, 0) checks addr against 0.
No need to repeat this check in the callers, i.e. tty_port_free_xmit_buf()
and tty_port_destructor().
Note, INIT_KFIFO() is safe without that check, because it's aware of kfifo PTR
versus embedded kfifo.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/tty/tty_port.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
index 4282895ede9e..880608a65773 100644
--- a/drivers/tty/tty_port.c
+++ b/drivers/tty/tty_port.c
@@ -240,11 +240,9 @@ EXPORT_SYMBOL(tty_port_alloc_xmit_buf);
void tty_port_free_xmit_buf(struct tty_port *port)
{
mutex_lock(&port->buf_mutex);
- if (port->xmit_buf != NULL) {
- free_page((unsigned long)port->xmit_buf);
- port->xmit_buf = NULL;
- INIT_KFIFO(port->xmit_fifo);
- }
+ free_page((unsigned long)port->xmit_buf);
+ port->xmit_buf = NULL;
+ INIT_KFIFO(port->xmit_fifo);
mutex_unlock(&port->buf_mutex);
}
EXPORT_SYMBOL(tty_port_free_xmit_buf);
@@ -271,8 +269,7 @@ static void tty_port_destructor(struct kref *kref)
/* check if last port ref was dropped before tty release */
if (WARN_ON(port->itty))
return;
- if (port->xmit_buf)
- free_page((unsigned long)port->xmit_buf);
+ free_page((unsigned long)port->xmit_buf);
tty_port_destroy(port);
if (port->ops && port->ops->destruct)
port->ops->destruct(port);
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v1 1/1] tty: Drop duplicate NULL check in TTY port functions
2022-02-02 16:57 [PATCH v1 1/1] tty: Drop duplicate NULL check in TTY port functions Andy Shevchenko
@ 2022-02-03 8:36 ` Jiri Slaby
2022-02-03 10:40 ` Andy Shevchenko
0 siblings, 1 reply; 5+ messages in thread
From: Jiri Slaby @ 2022-02-03 8:36 UTC (permalink / raw)
To: Andy Shevchenko, Greg Kroah-Hartman, linux-kernel
On 02. 02. 22, 17:57, Andy Shevchenko wrote:
> The free_page(addr), which becomes free_pages(addr, 0) checks addr against 0.
> No need to repeat this check in the callers, i.e. tty_port_free_xmit_buf()
> and tty_port_destructor().
>
> Note, INIT_KFIFO() is safe without that check, because it's aware of kfifo PTR
> versus embedded kfifo.
Not sure what you mean here ^^^? But it might be one of the morning
brain parser errors.
Acked-by: Jiri Slaby <jirislaby@kernel.org>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
> drivers/tty/tty_port.c | 11 ++++-------
> 1 file changed, 4 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
> index 4282895ede9e..880608a65773 100644
> --- a/drivers/tty/tty_port.c
> +++ b/drivers/tty/tty_port.c
> @@ -240,11 +240,9 @@ EXPORT_SYMBOL(tty_port_alloc_xmit_buf);
> void tty_port_free_xmit_buf(struct tty_port *port)
> {
> mutex_lock(&port->buf_mutex);
> - if (port->xmit_buf != NULL) {
> - free_page((unsigned long)port->xmit_buf);
> - port->xmit_buf = NULL;
> - INIT_KFIFO(port->xmit_fifo);
> - }
> + free_page((unsigned long)port->xmit_buf);
> + port->xmit_buf = NULL;
> + INIT_KFIFO(port->xmit_fifo);
> mutex_unlock(&port->buf_mutex);
> }
> EXPORT_SYMBOL(tty_port_free_xmit_buf);
> @@ -271,8 +269,7 @@ static void tty_port_destructor(struct kref *kref)
> /* check if last port ref was dropped before tty release */
> if (WARN_ON(port->itty))
> return;
> - if (port->xmit_buf)
> - free_page((unsigned long)port->xmit_buf);
> + free_page((unsigned long)port->xmit_buf);
> tty_port_destroy(port);
> if (port->ops && port->ops->destruct)
> port->ops->destruct(port);
--
js
suse labs
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v1 1/1] tty: Drop duplicate NULL check in TTY port functions
2022-02-03 8:36 ` Jiri Slaby
@ 2022-02-03 10:40 ` Andy Shevchenko
2022-02-04 14:42 ` Greg Kroah-Hartman
0 siblings, 1 reply; 5+ messages in thread
From: Andy Shevchenko @ 2022-02-03 10:40 UTC (permalink / raw)
To: Jiri Slaby; +Cc: Greg Kroah-Hartman, linux-kernel
On Thu, Feb 03, 2022 at 09:36:55AM +0100, Jiri Slaby wrote:
> On 02. 02. 22, 17:57, Andy Shevchenko wrote:
> > The free_page(addr), which becomes free_pages(addr, 0) checks addr against 0.
> > No need to repeat this check in the callers, i.e. tty_port_free_xmit_buf()
> > and tty_port_destructor().
> >
> > Note, INIT_KFIFO() is safe without that check, because it's aware of kfifo PTR
> > versus embedded kfifo.
>
> Not sure what you mean here ^^^? But it might be one of the morning brain
> parser errors.
Or maybe my evening weren't working...
Actually INIT_KFIFO() can be outside of that check from day 1 because it
operates on a separate member and does not rely on the FIFO itself to be
allocated.
I tried to explain that, while kfifo allocation goes together with buffer,
there is no dependency to any of those allocations.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v1 1/1] tty: Drop duplicate NULL check in TTY port functions
2022-02-03 10:40 ` Andy Shevchenko
@ 2022-02-04 14:42 ` Greg Kroah-Hartman
2022-02-04 15:27 ` Andy Shevchenko
0 siblings, 1 reply; 5+ messages in thread
From: Greg Kroah-Hartman @ 2022-02-04 14:42 UTC (permalink / raw)
To: Andy Shevchenko; +Cc: Jiri Slaby, linux-kernel
On Thu, Feb 03, 2022 at 12:40:00PM +0200, Andy Shevchenko wrote:
> On Thu, Feb 03, 2022 at 09:36:55AM +0100, Jiri Slaby wrote:
> > On 02. 02. 22, 17:57, Andy Shevchenko wrote:
> > > The free_page(addr), which becomes free_pages(addr, 0) checks addr against 0.
> > > No need to repeat this check in the callers, i.e. tty_port_free_xmit_buf()
> > > and tty_port_destructor().
> > >
> > > Note, INIT_KFIFO() is safe without that check, because it's aware of kfifo PTR
> > > versus embedded kfifo.
> >
> > Not sure what you mean here ^^^? But it might be one of the morning brain
> > parser errors.
>
> Or maybe my evening weren't working...
>
> Actually INIT_KFIFO() can be outside of that check from day 1 because it
> operates on a separate member and does not rely on the FIFO itself to be
> allocated.
>
> I tried to explain that, while kfifo allocation goes together with buffer,
> there is no dependency to any of those allocations.
Can you rewrite the changelog to say this?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v1 1/1] tty: Drop duplicate NULL check in TTY port functions
2022-02-04 14:42 ` Greg Kroah-Hartman
@ 2022-02-04 15:27 ` Andy Shevchenko
0 siblings, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2022-02-04 15:27 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: Jiri Slaby, linux-kernel
On Fri, Feb 04, 2022 at 03:42:15PM +0100, Greg Kroah-Hartman wrote:
> On Thu, Feb 03, 2022 at 12:40:00PM +0200, Andy Shevchenko wrote:
> > On Thu, Feb 03, 2022 at 09:36:55AM +0100, Jiri Slaby wrote:
> > > On 02. 02. 22, 17:57, Andy Shevchenko wrote:
...
> > > > Note, INIT_KFIFO() is safe without that check, because it's aware of kfifo PTR
> > > > versus embedded kfifo.
> > >
> > > Not sure what you mean here ^^^? But it might be one of the morning brain
> > > parser errors.
> >
> > Or maybe my evening weren't working...
> >
> > Actually INIT_KFIFO() can be outside of that check from day 1 because it
> > operates on a separate member and does not rely on the FIFO itself to be
> > allocated.
> >
> > I tried to explain that, while kfifo allocation goes together with buffer,
> > there is no dependency to any of those allocations.
>
> Can you rewrite the changelog to say this?
Sure!
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-02-04 15:28 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-02 16:57 [PATCH v1 1/1] tty: Drop duplicate NULL check in TTY port functions Andy Shevchenko
2022-02-03 8:36 ` Jiri Slaby
2022-02-03 10:40 ` Andy Shevchenko
2022-02-04 14:42 ` Greg Kroah-Hartman
2022-02-04 15:27 ` Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox