The legacy IDR API is deprecated in favor of the modern XArray API. Convert the tty_minors IDR to an XArray.
To prevent locking the entire gb_tty object while loading the minor, switch IDR to XArray and use the internal XArray's spinlock (xa_lock). To respect TTY encapsulation, use tty_port_get() instead of direct kref_get_unless_zero().
Signed-off-by: Aviv Levinson levinson.aviv@gmail.com --- drivers/staging/greybus/uart.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-)
diff --git a/drivers/staging/greybus/uart.c b/drivers/staging/greybus/uart.c index 2b1a5d4671dd..054bdc232942 100644 --- a/drivers/staging/greybus/uart.c +++ b/drivers/staging/greybus/uart.c @@ -339,24 +339,21 @@ static struct gb_tty *get_gb_by_minor(unsigned int minor) { struct gb_tty *gb_tty;
- rcu_read_lock(); + xa_lock(&tty_minors); gb_tty = xa_load(&tty_minors, minor); - if (gb_tty) { - if (!kref_get_unless_zero(&gb_tty->port.kref)) - gb_tty = NULL; - } - rcu_read_unlock(); + if (gb_tty) + tty_port_get(&gb_tty->port); + xa_unlock(&tty_minors);
- if (gb_tty) { - mutex_lock(&gb_tty->mutex); - if (gb_tty->disconnected) { - mutex_unlock(&gb_tty->mutex); - tty_port_put(&gb_tty->port); - gb_tty = NULL; - } else { - mutex_unlock(&gb_tty->mutex); - } + if (!gb_tty) + return NULL; + mutex_lock(&gb_tty->mutex); + if (gb_tty->disconnected) { + mutex_unlock(&gb_tty->mutex); + tty_port_put(&gb_tty->port); + return NULL; } + mutex_unlock(&gb_tty->mutex);
return gb_tty; }