Commit 24ce048b authored by Paul Fulghum's avatar Paul Fulghum Committed by Greg Kroah-Hartman

tty: synclink_gt: unwind actions in error path of net device open

Resent again, last attempt still altered the plain text.

Zhengchao Shao <shaozhengchao@huawei.com> identified by inspection bugs in the error path of hdlcdev_open() in synclink_gt.c

The function did not fully unwind actions in the error path. The use of try_module_get()/module_put() is unnecessary, potentially hazardous and is removed. The synclink_gt driver is already pinned any point the net device is registered, a requirement for calling this entry point.

The call hdlc_open() to init the generic HDLC layer is moved to after driver level init/checks and proper rollback of previous actions is added. This is a more sensible ordering as the most common error paths are at the driver level and the driver level rollbacks require less processing than hdlc_open()/hdlc_close().

This has been tested with supported hardware.
Signed-off-by: default avatarPaul Fulghum <paulkf@microgate.com>

Link: https://lore.kernel.org/r/7599F007-8985-4469-BE00-52BD1530210E@microgate.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 0d114e9f
......@@ -1433,16 +1433,8 @@ static int hdlcdev_open(struct net_device *dev)
int rc;
unsigned long flags;
if (!try_module_get(THIS_MODULE))
return -EBUSY;
DBGINFO(("%s hdlcdev_open\n", dev->name));
/* generic HDLC layer open processing */
rc = hdlc_open(dev);
if (rc)
return rc;
/* arbitrate between network and tty opens */
spin_lock_irqsave(&info->netlock, flags);
if (info->port.count != 0 || info->netcount != 0) {
......@@ -1461,6 +1453,16 @@ static int hdlcdev_open(struct net_device *dev)
return rc;
}
/* generic HDLC layer open processing */
rc = hdlc_open(dev);
if (rc) {
shutdown(info);
spin_lock_irqsave(&info->netlock, flags);
info->netcount = 0;
spin_unlock_irqrestore(&info->netlock, flags);
return rc;
}
/* assert RTS and DTR, apply hardware settings */
info->signals |= SerialSignal_RTS | SerialSignal_DTR;
program_hw(info);
......@@ -1506,7 +1508,6 @@ static int hdlcdev_close(struct net_device *dev)
info->netcount=0;
spin_unlock_irqrestore(&info->netlock, flags);
module_put(THIS_MODULE);
return 0;
}
......
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