Skip to content

Commit 24ce048

Browse files
Paul Fulghumgregkh
authored andcommitted
tty: synclink_gt: unwind actions in error path of net device open
Resent again, last attempt still altered the plain text. Zhengchao Shao <[email protected]> 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:Paul Fulghum <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 0d114e9 commit 24ce048

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

drivers/tty/synclink_gt.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,16 +1433,8 @@ static int hdlcdev_open(struct net_device *dev)
14331433
int rc;
14341434
unsigned long flags;
14351435

1436-
if (!try_module_get(THIS_MODULE))
1437-
return -EBUSY;
1438-
14391436
DBGINFO(("%s hdlcdev_open\n", dev->name));
14401437

1441-
/* generic HDLC layer open processing */
1442-
rc = hdlc_open(dev);
1443-
if (rc)
1444-
return rc;
1445-
14461438
/* arbitrate between network and tty opens */
14471439
spin_lock_irqsave(&info->netlock, flags);
14481440
if (info->port.count != 0 || info->netcount != 0) {
@@ -1461,6 +1453,16 @@ static int hdlcdev_open(struct net_device *dev)
14611453
return rc;
14621454
}
14631455

1456+
/* generic HDLC layer open processing */
1457+
rc = hdlc_open(dev);
1458+
if (rc) {
1459+
shutdown(info);
1460+
spin_lock_irqsave(&info->netlock, flags);
1461+
info->netcount = 0;
1462+
spin_unlock_irqrestore(&info->netlock, flags);
1463+
return rc;
1464+
}
1465+
14641466
/* assert RTS and DTR, apply hardware settings */
14651467
info->signals |= SerialSignal_RTS | SerialSignal_DTR;
14661468
program_hw(info);
@@ -1506,7 +1508,6 @@ static int hdlcdev_close(struct net_device *dev)
15061508
info->netcount=0;
15071509
spin_unlock_irqrestore(&info->netlock, flags);
15081510

1509-
module_put(THIS_MODULE);
15101511
return 0;
15111512
}
15121513

0 commit comments

Comments
 (0)