Skip to content

Commit cd20d59

Browse files
jhovoldgregkh
authored andcommitted
ipack: ipoctal: fix tty-registration error handling
Registration of the ipoctal tty devices is unlikely to fail, but if it ever does, make sure not to deregister a never registered tty device (and dereference a NULL pointer) when the driver is later unbound. Fixes: 2afb41d ("Staging: ipack/devices/ipoctal: Check tty_register_device return value.") Cc: [email protected] # 3.7 Acked-by: Samuel Iglesias Gonsalvez <[email protected]> Signed-off-by: Johan Hovold <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 65c001d commit cd20d59

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

drivers/ipack/devices/ipoctal.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ struct ipoctal_channel {
3333
unsigned int pointer_read;
3434
unsigned int pointer_write;
3535
struct tty_port tty_port;
36+
bool tty_registered;
3637
union scc2698_channel __iomem *regs;
3738
union scc2698_block __iomem *block_regs;
3839
unsigned int board_id;
@@ -396,9 +397,11 @@ static int ipoctal_inst_slot(struct ipoctal *ipoctal, unsigned int bus_nr,
396397
i, NULL, channel, NULL);
397398
if (IS_ERR(tty_dev)) {
398399
dev_err(&ipoctal->dev->dev, "Failed to register tty device.\n");
400+
tty_port_free_xmit_buf(&channel->tty_port);
399401
tty_port_destroy(&channel->tty_port);
400402
continue;
401403
}
404+
channel->tty_registered = true;
402405
}
403406

404407
/*
@@ -698,6 +701,10 @@ static void __ipoctal_remove(struct ipoctal *ipoctal)
698701

699702
for (i = 0; i < NR_CHANNELS; i++) {
700703
struct ipoctal_channel *channel = &ipoctal->channel[i];
704+
705+
if (!channel->tty_registered)
706+
continue;
707+
701708
tty_unregister_device(ipoctal->tty_drv, i);
702709
tty_port_free_xmit_buf(&channel->tty_port);
703710
tty_port_destroy(&channel->tty_port);

0 commit comments

Comments
 (0)