Commit f4e68d58 authored by Fabien Dessenne's avatar Fabien Dessenne Committed by Greg Kroah-Hartman

tty: fix NULL pointer issue when tty_port ops is not set

Unlike 'client_ops' which is initialized to 'default_client_ops', the
port operations 'ops' may be left to NULL.
Check the 'ops' value before checking the 'ops->x' value.
Signed-off-by: default avatarFabien Dessenne <fabien.dessenne@st.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 3ec80029
...@@ -325,7 +325,7 @@ static void tty_port_shutdown(struct tty_port *port, struct tty_struct *tty) ...@@ -325,7 +325,7 @@ static void tty_port_shutdown(struct tty_port *port, struct tty_struct *tty)
if (tty && C_HUPCL(tty)) if (tty && C_HUPCL(tty))
tty_port_lower_dtr_rts(port); tty_port_lower_dtr_rts(port);
if (port->ops->shutdown) if (port->ops && port->ops->shutdown)
port->ops->shutdown(port); port->ops->shutdown(port);
} }
out: out:
...@@ -398,7 +398,7 @@ EXPORT_SYMBOL_GPL(tty_port_tty_wakeup); ...@@ -398,7 +398,7 @@ EXPORT_SYMBOL_GPL(tty_port_tty_wakeup);
*/ */
int tty_port_carrier_raised(struct tty_port *port) int tty_port_carrier_raised(struct tty_port *port)
{ {
if (port->ops->carrier_raised == NULL) if (!port->ops || !port->ops->carrier_raised)
return 1; return 1;
return port->ops->carrier_raised(port); return port->ops->carrier_raised(port);
} }
...@@ -414,7 +414,7 @@ EXPORT_SYMBOL(tty_port_carrier_raised); ...@@ -414,7 +414,7 @@ EXPORT_SYMBOL(tty_port_carrier_raised);
*/ */
void tty_port_raise_dtr_rts(struct tty_port *port) void tty_port_raise_dtr_rts(struct tty_port *port)
{ {
if (port->ops->dtr_rts) if (port->ops && port->ops->dtr_rts)
port->ops->dtr_rts(port, 1); port->ops->dtr_rts(port, 1);
} }
EXPORT_SYMBOL(tty_port_raise_dtr_rts); EXPORT_SYMBOL(tty_port_raise_dtr_rts);
...@@ -429,7 +429,7 @@ EXPORT_SYMBOL(tty_port_raise_dtr_rts); ...@@ -429,7 +429,7 @@ EXPORT_SYMBOL(tty_port_raise_dtr_rts);
*/ */
void tty_port_lower_dtr_rts(struct tty_port *port) void tty_port_lower_dtr_rts(struct tty_port *port)
{ {
if (port->ops->dtr_rts) if (port->ops && port->ops->dtr_rts)
port->ops->dtr_rts(port, 0); port->ops->dtr_rts(port, 0);
} }
EXPORT_SYMBOL(tty_port_lower_dtr_rts); EXPORT_SYMBOL(tty_port_lower_dtr_rts);
...@@ -684,7 +684,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty, ...@@ -684,7 +684,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
if (!tty_port_initialized(port)) { if (!tty_port_initialized(port)) {
clear_bit(TTY_IO_ERROR, &tty->flags); clear_bit(TTY_IO_ERROR, &tty->flags);
if (port->ops->activate) { if (port->ops && port->ops->activate) {
int retval = port->ops->activate(port, tty); int retval = port->ops->activate(port, tty);
if (retval) { if (retval) {
mutex_unlock(&port->mutex); mutex_unlock(&port->mutex);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment