From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lj1-f175.google.com (mail-lj1-f175.google.com [209.85.208.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 260B83EEAF4 for ; Mon, 10 Aug 2026 14:13:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786371216; cv=none; b=nkraBki0x9ymMAQyG2Dd6KfncQjZxzGV7CY2jxES8rgCaQ2B9M5c+dHDl4kphCieo+6RHIUwFwNhf1SYGgm2FyOKx6rDDi99KhXgA8+WV+0AIjqLuWknhRmjHo3rrNY/2HIQOK1htimGo6/zcE6aMCwuFXE7CZqqIijxoCENKas= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786371216; c=relaxed/simple; bh=meearREFXdp/CGm2YFn0/RkjSyxzP4BssfIuK8nuSgs=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=MWvvd8fXBwtPn+2MH+srfLve0M5/MOrAGJ0lxpcCq796QJwHFyEZPsci5wFwEGqjUanluXxkkA2alKI5MBijxwOc1pM/+yyxI9WPP53tX6H1ZDGitvmekvVYakIapFDT1jKABPSpS49Ba8O9zLW6o1fY37BldUfdULcavUtNd3Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=MJXbGqj3; arc=none smtp.client-ip=209.85.208.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MJXbGqj3" Received: by mail-lj1-f175.google.com with SMTP id 38308e7fff4ca-39c95395230so15896971fa.2 for ; Mon, 10 Aug 2026 07:13:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786371213; x=1786976013; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=3+7dwwupXsqHgZrhPAZdkaTsGOaTCtAMuPI7NwqoOvE=; b=MJXbGqj3KFnuOUquoIfOhdrGvOtqiJYc6IVctLPdn/HDr1QOWdbDX/surdJWU8Ho0b 8ciSJtZ2bIhfA89TAbpfJjT/vuFWOfp/4bPLvEMQgL/TeAyKFz9zbPbyoJeQZsv4G5h5 XxzgIqvvE1lIwCR91v65a0xBkjelLy5116wOVHoDJCC1yoLRsSUrsg4NVl4f3tTkJtZQ /t+Ff4Y1lV5tDY8xozoFq6l92E9YQ5v7MPJg3sB2Bp5pehL9xQmMA7jXyqho/Q5OWEW9 absYsW4Iz1zwv366AEgo8EiFCx0Ozw154mvj1p5MvsIiyvpN9N4KpfFXyvP3Epk4JECW TRjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786371213; x=1786976013; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=3+7dwwupXsqHgZrhPAZdkaTsGOaTCtAMuPI7NwqoOvE=; b=eqIjsFnh3zpVj8bc937joJpCChQkz05w+it8kVNbMpoHo2vCX2bwStwWNwsEvwRnIL 3lt4aCgTqiMfpWWWdMWTsYnDF8QxBgMTEPa64jZijgsbkForIyj3dd7o+SLdT9kQgHdj GIhHrkc5zr1hadqhOsWTcuecotJAAkO3BOd8Mh/TNriK9JfZYW3x+gWZuHItENz29Ke3 m7Jp7Pq809emowwRAoikffwMFOwkDMwi4yZLdZjAxMlEVOtWRbK/YqpGzbRvlMgDoj17 e/MR11elMqIy0H4zmZkVcC5Tgu9Rw2K9lXkUX4940f7bJ2w3SUBYa8awkgvU+qVrIxdK +Zjg== X-Forwarded-Encrypted: i=1; AHgh+RqyG6Wnfh2wETCFVMK+dnZKG9FuXbjBce+EQHOruebv5706rpxnNHZCK420Ftm3/beSVo9W2iN6tSYIP/Q=@vger.kernel.org X-Gm-Message-State: AOJu0YzACH4PDFw+Af9qCJZ3/L04bU5lqrDwQdJjjS27OOtqLcvaBKQ4 Lp0iBWU/4lZo4lXC5ZtIYpyrXkezyIm/RAcTYaKC/22QcN6igw6Q3o2z X-Gm-Gg: AR+sD100s3ATAKW+hbOekTXis3Vd6pxIrdgKKPIuo7AxYK1siI1GnTjAiTMZBxHSdaB qNg1TCafQb8rH+kmM2Qtk7qYXyUK8bJnN+KAY3AER1Y0yVa4xaPWUa6OelYEvdTvJXTLLBGT5fg AaEDvKGZOFoGbCd2RCpP6Zq9Dqu0ruWvitHmuLjSlAv3zRQLxuvSiJGlmiUvFaQgoLQ/Dv3dZ5C DsC7wluKozfk5YWGH11m1swUktHtizrCoDOX2TcPVrTIoz3czITsF100I9K+2SXv7GjnSM7jZ8c CGxXvMjnIa1uu7Hfx4FoDbNH3KjQXo/lK9mh1HDk7oy5JTwnoQCuqX9klyKzf83ky7hi/YMO0eF 4+JMYBDZNzhu4kavQ+nJ8MzsDi5YwM2xqPhmHGIIk+7qAUKDagMvpGboSbZu5WjkoxNhoUr3KeQ sDpv440LtuxU8xnYuGxlI3iFCjgtnaJA02RbI855Gjnb1vPrKYwnffNaQ= X-Received: by 2002:a2e:be0e:0:b0:394:1254:10d2 with SMTP id 38308e7fff4ca-39fdefd0d29mr26019721fa.0.1786371213015; Mon, 10 Aug 2026 07:13:33 -0700 (PDT) Received: from localhost ([46.172.73.175]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-39fdda8010csm24552931fa.3.2026.08.10.07.13.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Aug 2026 07:13:32 -0700 (PDT) From: Dmitry Priz To: dtwlin@gmail.com, johan@kernel.org, elder@kernel.org, gregkh@linuxfoundation.org Cc: greybus-dev@lists.linaro.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, Dmitry Priz Subject: [PATCH] staging: greybus: uart: convert from IDR to XArray Date: Mon, 10 Aug 2026 17:10:43 +0300 Message-ID: <20260810141043.76948-1-dimahtms@gmail.com> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit IDR is deprecated in favor of XArray, which manages its own internal locking and provides a more consistent allocation API. Convert tty_minors from an IDR to an allocating XArray. Update the error check in gb_uart_probe() from -ENOSPC to -EBUSY, since that is the error xa_alloc() returns when the allocation range is exhausted, unlike idr_alloc() which returned -ENOSPC. Build-tested and verified via boot in QEMU: the module loads, registers with the greybus core, and unloads cleanly. Signed-off-by: Dmitry Priz --- drivers/staging/greybus/uart.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/drivers/staging/greybus/uart.c b/drivers/staging/greybus/uart.c index 7d060b4cd33d..edd6b0e25c8c 100644 --- a/drivers/staging/greybus/uart.c +++ b/drivers/staging/greybus/uart.c @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include #include @@ -67,7 +67,7 @@ struct gb_tty { }; static struct tty_driver *gb_tty_driver; -static DEFINE_IDR(tty_minors); +static DEFINE_XARRAY_ALLOC(tty_minors); static DEFINE_MUTEX(table_lock); static int gb_uart_receive_data_handler(struct gb_operation *op) @@ -342,7 +342,7 @@ static struct gb_tty *get_gb_by_minor(unsigned int minor) struct gb_tty *gb_tty; mutex_lock(&table_lock); - gb_tty = idr_find(&tty_minors, minor); + gb_tty = xa_load(&tty_minors, minor); if (gb_tty) { mutex_lock(&gb_tty->mutex); if (gb_tty->disconnected) { @@ -359,14 +359,19 @@ static struct gb_tty *get_gb_by_minor(unsigned int minor) static int alloc_minor(struct gb_tty *gb_tty) { - int minor; + u32 id; + int ret; mutex_lock(&table_lock); - minor = idr_alloc(&tty_minors, gb_tty, 0, GB_NUM_MINORS, GFP_KERNEL); + ret = xa_alloc(&tty_minors, &id, gb_tty, XA_LIMIT(0, GB_NUM_MINORS - 1), GFP_KERNEL); mutex_unlock(&table_lock); - if (minor >= 0) - gb_tty->minor = minor; - return minor; + + if (ret < 0) + return ret; + + gb_tty->minor = id; + + return id; } static void release_minor(struct gb_tty *gb_tty) @@ -375,7 +380,7 @@ static void release_minor(struct gb_tty *gb_tty) gb_tty->minor = 0; /* Maybe should use an invalid value instead */ mutex_lock(&table_lock); - idr_remove(&tty_minors, minor); + xa_erase(&tty_minors, minor); mutex_unlock(&table_lock); } @@ -854,7 +859,7 @@ static int gb_uart_probe(struct gbphy_device *gbphy_dev, minor = alloc_minor(gb_tty); if (minor < 0) { - if (minor == -ENOSPC) { + if (minor == -EBUSY) { dev_err(&gbphy_dev->dev, "no more free minor numbers\n"); retval = -ENODEV; @@ -984,7 +989,7 @@ static void gb_tty_exit(void) { tty_unregister_driver(gb_tty_driver); tty_driver_kref_put(gb_tty_driver); - idr_destroy(&tty_minors); + xa_destroy(&tty_minors); } static const struct gbphy_device_id gb_uart_id_table[] = { -- 2.53.0