Skip to contentSkip to conversation

tty: Drop duplicate NULL check in TTY port functions

PATCH New Andy Shevchenko 1 participant 1 message Feb 4, 2022 TTY layer and serial drivers

lore
Share & tools
lore
#0 lore raw

PATCH v2 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 operates on a separate member and doesn't rely on the FIFO itself to be allocated.

---
v2: updated note in commit message (Greg), added tag (Jiri)

 drivers/tty/tty_port.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/tty/tty_port.c +4 -7
index 4282895ede9e..880608a65773 100644
@@ -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