tty: Drop duplicate NULL check in TTY port functions
PATCH 1/1 tty: Drop duplicate NULL check in TTY port functions
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.
--- drivers/tty/tty_port.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/tty/tty_port.c +4 -7
@@ -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);
Signature · 1 line
2.34.1
Quoted 6 lines · Andy Shevchenko
The
free_page(addr), which becomesfree_pages(addr, 0)checks addr against 0. No need to repeat this check in the callers, i.e.tty_port_free_xmit_buf()andtty_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.
Quoted 34 lines
Signed-off-by Andy Shevchenko <[email protected]>--- drivers/tty/tty_port.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)drivers/tty/tty_port.c +4
-7@@ -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);
Signature · 2 lines
js suse labs
Quoted 10 lines · Jiri Slaby
Quoted 6 lines · Andy Shevchenko
The
free_page(addr), which becomesfree_pages(addr, 0)checks addr against 0. No need to repeat this check in the callers, i.e.tty_port_free_xmit_buf()andtty_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.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Greg Kroah-Hartman
maintainerQuoted 12 lines · Andy Shevchenko
Quoted 10 lines · Jiri Slaby
Quoted 6 lines · Andy Shevchenko
The
free_page(addr), which becomesfree_pages(addr, 0)checks addr against 0. No need to repeat this check in the callers, i.e.tty_port_free_xmit_buf()andtty_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.
Quoted 8 lines
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
Quoted 3 lines · Greg Kroah-Hartman
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Jiri Slaby
On 02. 02. 22, 17:57, Andy Shevchenko wrote:
...
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
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...
Quoted 8 lines
Quoted 6 lines
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!
Signature · 2 lines
With Best Regards, Andy Shevchenko