Skip to content

Commit fc27ab4

Browse files
krzkkuba-moo
authored andcommitted
NFC: nci: uart: Set tty->disc_data only in success path
Setting tty->disc_data before opening the NCI device means we need to clean it up on error paths. This also opens some short window if device starts sending data, even before NCIUARTSETDRIVER IOCTL succeeded (broken hardware?). Close the window by exposing tty->disc_data only on the success path, when opening of the NCI device and try_module_get() succeeds. The code differs in error path in one aspect: tty->disc_data won't be ever assigned thus NULL-ified. This however should not be relevant difference, because of "tty->disc_data=NULL" in nci_uart_tty_open(). Cc: Linus Torvalds <[email protected]> Fixes: 9961127 ("NFC: nci: add generic uart support") Cc: <[email protected]> Signed-off-by: Krzysztof Kozlowski <[email protected]> Reviewed-by: Greg Kroah-Hartman <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 10876da commit fc27ab4

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

net/nfc/nci/uart.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,22 +119,22 @@ static int nci_uart_set_driver(struct tty_struct *tty, unsigned int driver)
119119

120120
memcpy(nu, nci_uart_drivers[driver], sizeof(struct nci_uart));
121121
nu->tty = tty;
122-
tty->disc_data = nu;
123122
skb_queue_head_init(&nu->tx_q);
124123
INIT_WORK(&nu->write_work, nci_uart_write_work);
125124
spin_lock_init(&nu->rx_lock);
126125

127126
ret = nu->ops.open(nu);
128127
if (ret) {
129-
tty->disc_data = NULL;
130128
kfree(nu);
129+
return ret;
131130
} else if (!try_module_get(nu->owner)) {
132131
nu->ops.close(nu);
133-
tty->disc_data = NULL;
134132
kfree(nu);
135133
return -ENOENT;
136134
}
137-
return ret;
135+
tty->disc_data = nu;
136+
137+
return 0;
138138
}
139139

140140
/* ------ LDISC part ------ */

0 commit comments

Comments
 (0)