* [PATCH] staging: greybus: Convert uart.c from IDR to XArray
@ 2021-08-14 17:56 Fabio M. De Francesco
0 siblings, 0 replies; 6+ messages in thread
From: Fabio M. De Francesco @ 2021-08-14 17:56 UTC (permalink / raw)
To: Johan Hovold, Alex Elder, Greg Kroah-Hartman, greybus-dev,
linux-staging, linux-kernel
Cc: Fabio M. De Francesco, kernel test robot
Convert greybus/uart.c from IDR to XArray. The abstract data type XArray
is more memory-efficient, parallelisable, and cache friendly. It takes
advantage of RCU to perform lookups without locking. Furthermore, IDR is
deprecated because XArray has a better (cleaner and more consistent) API.
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
---
v1->v2:
Fixed an issue found by the kernel test robot. It was due to
passing to xa_*lock() the same old mutex that IDR used with
the previous version of the code.
drivers/staging/greybus/uart.c | 29 ++++++++++++++---------------
1 file changed, 14 insertions(+), 15 deletions(-)
diff --git a/drivers/staging/greybus/uart.c b/drivers/staging/greybus/uart.c
index 73f01ed1e5b7..5bf993e40f84 100644
--- a/drivers/staging/greybus/uart.c
+++ b/drivers/staging/greybus/uart.c
@@ -22,7 +22,7 @@
#include <linux/serial.h>
#include <linux/tty_driver.h>
#include <linux/tty_flip.h>
-#include <linux/idr.h>
+#include <linux/xarray.h>
#include <linux/fs.h>
#include <linux/kdev_t.h>
#include <linux/kfifo.h>
@@ -33,6 +33,7 @@
#include "gbphy.h"
#define GB_NUM_MINORS 16 /* 16 is more than enough */
+#define GB_RANGE_MINORS XA_LIMIT(0, GB_NUM_MINORS)
#define GB_NAME "ttyGB"
#define GB_UART_WRITE_FIFO_SIZE PAGE_SIZE
@@ -67,8 +68,7 @@ struct gb_tty {
};
static struct tty_driver *gb_tty_driver;
-static DEFINE_IDR(tty_minors);
-static DEFINE_MUTEX(table_lock);
+static DEFINE_XARRAY(tty_minors);
static int gb_uart_receive_data_handler(struct gb_operation *op)
{
@@ -77,6 +77,7 @@ static int gb_uart_receive_data_handler(struct gb_operation *op)
struct tty_port *port = &gb_tty->port;
struct gb_message *request = op->request;
struct gb_uart_recv_data_request *receive_data;
+
u16 recv_data_size;
int count;
unsigned long tty_flags = TTY_NORMAL;
@@ -341,8 +342,8 @@ 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);
+ xa_lock(&tty_minors);
+ gb_tty = xa_load(&tty_minors, minor);
if (gb_tty) {
mutex_lock(&gb_tty->mutex);
if (gb_tty->disconnected) {
@@ -353,19 +354,19 @@ static struct gb_tty *get_gb_by_minor(unsigned int minor)
mutex_unlock(&gb_tty->mutex);
}
}
- mutex_unlock(&table_lock);
+ xa_unlock(&tty_minors);
return gb_tty;
}
static int alloc_minor(struct gb_tty *gb_tty)
{
int minor;
+ int ret;
- mutex_lock(&table_lock);
- minor = idr_alloc(&tty_minors, gb_tty, 0, GB_NUM_MINORS, GFP_KERNEL);
- mutex_unlock(&table_lock);
- if (minor >= 0)
- gb_tty->minor = minor;
+ ret = xa_alloc(&tty_minors, &minor, gb_tty, GB_RANGE_MINORS, GFP_KERNEL);
+ if (ret)
+ return ret;
+ gb_tty->minor = minor;
return minor;
}
@@ -374,9 +375,7 @@ static void release_minor(struct gb_tty *gb_tty)
int minor = gb_tty->minor;
gb_tty->minor = 0; /* Maybe should use an invalid value instead */
- mutex_lock(&table_lock);
- idr_remove(&tty_minors, minor);
- mutex_unlock(&table_lock);
+ xa_erase(&tty_minors, minor);
}
static int gb_tty_install(struct tty_driver *driver, struct tty_struct *tty)
@@ -982,7 +981,7 @@ static void gb_tty_exit(void)
{
tty_unregister_driver(gb_tty_driver);
put_tty_driver(gb_tty_driver);
- idr_destroy(&tty_minors);
+ xa_destroy(&tty_minors);
}
static const struct gbphy_device_id gb_uart_id_table[] = {
--
2.32.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] staging: greybus: Convert uart.c from IDR to XArray
2021-08-14 14:56 Fabio M. De Francesco
@ 2021-08-14 17:35 ` kernel test robot
2021-08-14 17:35 ` kernel test robot
1 sibling, 0 replies; 6+ messages in thread
From: kernel test robot @ 2021-08-14 17:35 UTC (permalink / raw)
To: Fabio M. De Francesco, Johan Hovold, Alex Elder,
Greg Kroah-Hartman, greybus-dev, linux-staging, linux-kernel
Cc: kbuild-all, Fabio M. De Francesco
[-- Attachment #1: Type: text/plain, Size: 15757 bytes --]
Hi "Fabio,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on staging/staging-testing]
url: https://github.com/0day-ci/linux/commits/Fabio-M-De-Francesco/staging-greybus-Convert-uart-c-from-IDR-to-XArray/20210814-225807
base: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging.git 0bd35146642bdc56f1b87d75f047b1c92bd2bd39
config: i386-randconfig-s002-20210814 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce:
# apt-get install sparse
# sparse version: v0.6.3-348-gf0e6938b-dirty
# https://github.com/0day-ci/linux/commit/901c5fde0540c767590bce646219889730c4a41b
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Fabio-M-De-Francesco/staging-greybus-Convert-uart-c-from-IDR-to-XArray/20210814-225807
git checkout 901c5fde0540c767590bce646219889730c4a41b
# save the attached .config to linux build tree
make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=i386 SHELL=/bin/bash drivers/staging/greybus/
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
All errors (new ones prefixed by >>):
In file included from include/linux/radix-tree.h:19,
from include/linux/idr.h:15,
from include/linux/kernfs.h:13,
from include/linux/sysfs.h:16,
from include/linux/kobject.h:20,
from include/linux/module.h:21,
from drivers/staging/greybus/uart.c:15:
drivers/staging/greybus/uart.c: In function 'get_gb_by_minor':
>> include/linux/xarray.h:530:39: error: 'struct mutex' has no member named 'xa_lock'; did you mean 'wait_lock'?
530 | #define xa_lock(xa) spin_lock(&(xa)->xa_lock)
| ^~~~~~~
drivers/staging/greybus/uart.c:346:2: note: in expansion of macro 'xa_lock'
346 | xa_lock(&table_lock);
| ^~~~~~~
include/linux/xarray.h:531:43: error: 'struct mutex' has no member named 'xa_lock'; did you mean 'wait_lock'?
531 | #define xa_unlock(xa) spin_unlock(&(xa)->xa_lock)
| ^~~~~~~
drivers/staging/greybus/uart.c:358:2: note: in expansion of macro 'xa_unlock'
358 | xa_unlock(&table_lock);
| ^~~~~~~~~
vim +530 include/linux/xarray.h
9b89a035514468 Matthew Wilcox 2017-11-10 420
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 421) /**
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 422) * xa_for_each_range() - Iterate over a portion of an XArray.
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 423) * @xa: XArray.
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 424) * @index: Index of @entry.
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 425) * @entry: Entry retrieved from array.
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 426) * @start: First index to retrieve from array.
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 427) * @last: Last index to retrieve from array.
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 428) *
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 429) * During the iteration, @entry will have the value of the entry stored
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 430) * in @xa at @index. You may modify @index during the iteration if you
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 431) * want to skip or reprocess indices. It is safe to modify the array
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 432) * during the iteration. At the end of the iteration, @entry will be set
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 433) * to NULL and @index will have a value less than or equal to max.
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 434) *
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 435) * xa_for_each_range() is O(n.log(n)) while xas_for_each() is O(n). You have
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 436) * to handle your own locking with xas_for_each(), and if you have to unlock
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 437) * after each iteration, it will also end up being O(n.log(n)).
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 438) * xa_for_each_range() will spin if it hits a retry entry; if you intend to
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 439) * see retry entries, you should use the xas_for_each() iterator instead.
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 440) * The xas_for_each() iterator will expand into more inline code than
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 441) * xa_for_each_range().
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 442) *
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 443) * Context: Any context. Takes and releases the RCU lock.
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 444) */
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 445) #define xa_for_each_range(xa, index, entry, start, last) \
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 446) for (index = start, \
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 447) entry = xa_find(xa, &index, last, XA_PRESENT); \
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 448) entry; \
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 449) entry = xa_find_after(xa, &index, last, XA_PRESENT))
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 450)
b803b42823d0d9 Matthew Wilcox 2017-11-14 451 /**
4a31896c5b5a27 Matthew Wilcox 2018-12-17 452 * xa_for_each_start() - Iterate over a portion of an XArray.
b803b42823d0d9 Matthew Wilcox 2017-11-14 453 * @xa: XArray.
4a31896c5b5a27 Matthew Wilcox 2018-12-17 454 * @index: Index of @entry.
b803b42823d0d9 Matthew Wilcox 2017-11-14 455 * @entry: Entry retrieved from array.
4a31896c5b5a27 Matthew Wilcox 2018-12-17 456 * @start: First index to retrieve from array.
4a31896c5b5a27 Matthew Wilcox 2018-12-17 457 *
4a31896c5b5a27 Matthew Wilcox 2018-12-17 458 * During the iteration, @entry will have the value of the entry stored
4a31896c5b5a27 Matthew Wilcox 2018-12-17 459 * in @xa at @index. You may modify @index during the iteration if you
4a31896c5b5a27 Matthew Wilcox 2018-12-17 460 * want to skip or reprocess indices. It is safe to modify the array
4a31896c5b5a27 Matthew Wilcox 2018-12-17 461 * during the iteration. At the end of the iteration, @entry will be set
4a31896c5b5a27 Matthew Wilcox 2018-12-17 462 * to NULL and @index will have a value less than or equal to max.
4a31896c5b5a27 Matthew Wilcox 2018-12-17 463 *
4a31896c5b5a27 Matthew Wilcox 2018-12-17 464 * xa_for_each_start() is O(n.log(n)) while xas_for_each() is O(n). You have
4a31896c5b5a27 Matthew Wilcox 2018-12-17 465 * to handle your own locking with xas_for_each(), and if you have to unlock
4a31896c5b5a27 Matthew Wilcox 2018-12-17 466 * after each iteration, it will also end up being O(n.log(n)).
4a31896c5b5a27 Matthew Wilcox 2018-12-17 467 * xa_for_each_start() will spin if it hits a retry entry; if you intend to
4a31896c5b5a27 Matthew Wilcox 2018-12-17 468 * see retry entries, you should use the xas_for_each() iterator instead.
4a31896c5b5a27 Matthew Wilcox 2018-12-17 469 * The xas_for_each() iterator will expand into more inline code than
4a31896c5b5a27 Matthew Wilcox 2018-12-17 470 * xa_for_each_start().
4a31896c5b5a27 Matthew Wilcox 2018-12-17 471 *
4a31896c5b5a27 Matthew Wilcox 2018-12-17 472 * Context: Any context. Takes and releases the RCU lock.
4a31896c5b5a27 Matthew Wilcox 2018-12-17 473 */
4a31896c5b5a27 Matthew Wilcox 2018-12-17 474 #define xa_for_each_start(xa, index, entry, start) \
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 475) xa_for_each_range(xa, index, entry, start, ULONG_MAX)
4a31896c5b5a27 Matthew Wilcox 2018-12-17 476
4a31896c5b5a27 Matthew Wilcox 2018-12-17 477 /**
4a31896c5b5a27 Matthew Wilcox 2018-12-17 478 * xa_for_each() - Iterate over present entries in an XArray.
4a31896c5b5a27 Matthew Wilcox 2018-12-17 479 * @xa: XArray.
b803b42823d0d9 Matthew Wilcox 2017-11-14 480 * @index: Index of @entry.
4a31896c5b5a27 Matthew Wilcox 2018-12-17 481 * @entry: Entry retrieved from array.
b803b42823d0d9 Matthew Wilcox 2017-11-14 482 *
4a31896c5b5a27 Matthew Wilcox 2018-12-17 483 * During the iteration, @entry will have the value of the entry stored
4a31896c5b5a27 Matthew Wilcox 2018-12-17 484 * in @xa at @index. You may modify @index during the iteration if you want
4a31896c5b5a27 Matthew Wilcox 2018-12-17 485 * to skip or reprocess indices. It is safe to modify the array during the
4a31896c5b5a27 Matthew Wilcox 2018-12-17 486 * iteration. At the end of the iteration, @entry will be set to NULL and
4a31896c5b5a27 Matthew Wilcox 2018-12-17 487 * @index will have a value less than or equal to max.
b803b42823d0d9 Matthew Wilcox 2017-11-14 488 *
b803b42823d0d9 Matthew Wilcox 2017-11-14 489 * xa_for_each() is O(n.log(n)) while xas_for_each() is O(n). You have
b803b42823d0d9 Matthew Wilcox 2017-11-14 490 * to handle your own locking with xas_for_each(), and if you have to unlock
b803b42823d0d9 Matthew Wilcox 2017-11-14 491 * after each iteration, it will also end up being O(n.log(n)). xa_for_each()
b803b42823d0d9 Matthew Wilcox 2017-11-14 492 * will spin if it hits a retry entry; if you intend to see retry entries,
b803b42823d0d9 Matthew Wilcox 2017-11-14 493 * you should use the xas_for_each() iterator instead. The xas_for_each()
b803b42823d0d9 Matthew Wilcox 2017-11-14 494 * iterator will expand into more inline code than xa_for_each().
b803b42823d0d9 Matthew Wilcox 2017-11-14 495 *
b803b42823d0d9 Matthew Wilcox 2017-11-14 496 * Context: Any context. Takes and releases the RCU lock.
b803b42823d0d9 Matthew Wilcox 2017-11-14 497 */
4a31896c5b5a27 Matthew Wilcox 2018-12-17 498 #define xa_for_each(xa, index, entry) \
4a31896c5b5a27 Matthew Wilcox 2018-12-17 499 xa_for_each_start(xa, index, entry, 0)
4a31896c5b5a27 Matthew Wilcox 2018-12-17 500
4a31896c5b5a27 Matthew Wilcox 2018-12-17 501 /**
4a31896c5b5a27 Matthew Wilcox 2018-12-17 502 * xa_for_each_marked() - Iterate over marked entries in an XArray.
4a31896c5b5a27 Matthew Wilcox 2018-12-17 503 * @xa: XArray.
4a31896c5b5a27 Matthew Wilcox 2018-12-17 504 * @index: Index of @entry.
4a31896c5b5a27 Matthew Wilcox 2018-12-17 505 * @entry: Entry retrieved from array.
4a31896c5b5a27 Matthew Wilcox 2018-12-17 506 * @filter: Selection criterion.
4a31896c5b5a27 Matthew Wilcox 2018-12-17 507 *
4a31896c5b5a27 Matthew Wilcox 2018-12-17 508 * During the iteration, @entry will have the value of the entry stored
4a31896c5b5a27 Matthew Wilcox 2018-12-17 509 * in @xa at @index. The iteration will skip all entries in the array
4a31896c5b5a27 Matthew Wilcox 2018-12-17 510 * which do not match @filter. You may modify @index during the iteration
4a31896c5b5a27 Matthew Wilcox 2018-12-17 511 * if you want to skip or reprocess indices. It is safe to modify the array
4a31896c5b5a27 Matthew Wilcox 2018-12-17 512 * during the iteration. At the end of the iteration, @entry will be set to
4a31896c5b5a27 Matthew Wilcox 2018-12-17 513 * NULL and @index will have a value less than or equal to max.
4a31896c5b5a27 Matthew Wilcox 2018-12-17 514 *
4a31896c5b5a27 Matthew Wilcox 2018-12-17 515 * xa_for_each_marked() is O(n.log(n)) while xas_for_each_marked() is O(n).
4a31896c5b5a27 Matthew Wilcox 2018-12-17 516 * You have to handle your own locking with xas_for_each(), and if you have
4a31896c5b5a27 Matthew Wilcox 2018-12-17 517 * to unlock after each iteration, it will also end up being O(n.log(n)).
4a31896c5b5a27 Matthew Wilcox 2018-12-17 518 * xa_for_each_marked() will spin if it hits a retry entry; if you intend to
4a31896c5b5a27 Matthew Wilcox 2018-12-17 519 * see retry entries, you should use the xas_for_each_marked() iterator
4a31896c5b5a27 Matthew Wilcox 2018-12-17 520 * instead. The xas_for_each_marked() iterator will expand into more inline
4a31896c5b5a27 Matthew Wilcox 2018-12-17 521 * code than xa_for_each_marked().
4a31896c5b5a27 Matthew Wilcox 2018-12-17 522 *
4a31896c5b5a27 Matthew Wilcox 2018-12-17 523 * Context: Any context. Takes and releases the RCU lock.
4a31896c5b5a27 Matthew Wilcox 2018-12-17 524 */
4a31896c5b5a27 Matthew Wilcox 2018-12-17 525 #define xa_for_each_marked(xa, index, entry, filter) \
4a31896c5b5a27 Matthew Wilcox 2018-12-17 526 for (index = 0, entry = xa_find(xa, &index, ULONG_MAX, filter); \
4a31896c5b5a27 Matthew Wilcox 2018-12-17 527 entry; entry = xa_find_after(xa, &index, ULONG_MAX, filter))
b803b42823d0d9 Matthew Wilcox 2017-11-14 528
f6bb2a2c0b81c4 Matthew Wilcox 2018-04-10 529 #define xa_trylock(xa) spin_trylock(&(xa)->xa_lock)
f6bb2a2c0b81c4 Matthew Wilcox 2018-04-10 @530 #define xa_lock(xa) spin_lock(&(xa)->xa_lock)
f6bb2a2c0b81c4 Matthew Wilcox 2018-04-10 531 #define xa_unlock(xa) spin_unlock(&(xa)->xa_lock)
f6bb2a2c0b81c4 Matthew Wilcox 2018-04-10 532 #define xa_lock_bh(xa) spin_lock_bh(&(xa)->xa_lock)
f6bb2a2c0b81c4 Matthew Wilcox 2018-04-10 533 #define xa_unlock_bh(xa) spin_unlock_bh(&(xa)->xa_lock)
f6bb2a2c0b81c4 Matthew Wilcox 2018-04-10 534 #define xa_lock_irq(xa) spin_lock_irq(&(xa)->xa_lock)
f6bb2a2c0b81c4 Matthew Wilcox 2018-04-10 535 #define xa_unlock_irq(xa) spin_unlock_irq(&(xa)->xa_lock)
f6bb2a2c0b81c4 Matthew Wilcox 2018-04-10 536 #define xa_lock_irqsave(xa, flags) \
f6bb2a2c0b81c4 Matthew Wilcox 2018-04-10 537 spin_lock_irqsave(&(xa)->xa_lock, flags)
f6bb2a2c0b81c4 Matthew Wilcox 2018-04-10 538 #define xa_unlock_irqrestore(xa, flags) \
f6bb2a2c0b81c4 Matthew Wilcox 2018-04-10 539 spin_unlock_irqrestore(&(xa)->xa_lock, flags)
82a958497dc912 Matthew Wilcox (Oracle 2020-01-17 540) #define xa_lock_nested(xa, subclass) \
82a958497dc912 Matthew Wilcox (Oracle 2020-01-17 541) spin_lock_nested(&(xa)->xa_lock, subclass)
82a958497dc912 Matthew Wilcox (Oracle 2020-01-17 542) #define xa_lock_bh_nested(xa, subclass) \
82a958497dc912 Matthew Wilcox (Oracle 2020-01-17 543) spin_lock_bh_nested(&(xa)->xa_lock, subclass)
82a958497dc912 Matthew Wilcox (Oracle 2020-01-17 544) #define xa_lock_irq_nested(xa, subclass) \
82a958497dc912 Matthew Wilcox (Oracle 2020-01-17 545) spin_lock_irq_nested(&(xa)->xa_lock, subclass)
82a958497dc912 Matthew Wilcox (Oracle 2020-01-17 546) #define xa_lock_irqsave_nested(xa, flags, subclass) \
82a958497dc912 Matthew Wilcox (Oracle 2020-01-17 547) spin_lock_irqsave_nested(&(xa)->xa_lock, flags, subclass)
f6bb2a2c0b81c4 Matthew Wilcox 2018-04-10 548
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 36433 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] staging: greybus: Convert uart.c from IDR to XArray
@ 2021-08-14 17:35 ` kernel test robot
0 siblings, 0 replies; 6+ messages in thread
From: kernel test robot @ 2021-08-14 17:35 UTC (permalink / raw)
To: kbuild-all
[-- Attachment #1: Type: text/plain, Size: 15941 bytes --]
Hi "Fabio,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on staging/staging-testing]
url: https://github.com/0day-ci/linux/commits/Fabio-M-De-Francesco/staging-greybus-Convert-uart-c-from-IDR-to-XArray/20210814-225807
base: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging.git 0bd35146642bdc56f1b87d75f047b1c92bd2bd39
config: i386-randconfig-s002-20210814 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce:
# apt-get install sparse
# sparse version: v0.6.3-348-gf0e6938b-dirty
# https://github.com/0day-ci/linux/commit/901c5fde0540c767590bce646219889730c4a41b
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Fabio-M-De-Francesco/staging-greybus-Convert-uart-c-from-IDR-to-XArray/20210814-225807
git checkout 901c5fde0540c767590bce646219889730c4a41b
# save the attached .config to linux build tree
make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=i386 SHELL=/bin/bash drivers/staging/greybus/
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
All errors (new ones prefixed by >>):
In file included from include/linux/radix-tree.h:19,
from include/linux/idr.h:15,
from include/linux/kernfs.h:13,
from include/linux/sysfs.h:16,
from include/linux/kobject.h:20,
from include/linux/module.h:21,
from drivers/staging/greybus/uart.c:15:
drivers/staging/greybus/uart.c: In function 'get_gb_by_minor':
>> include/linux/xarray.h:530:39: error: 'struct mutex' has no member named 'xa_lock'; did you mean 'wait_lock'?
530 | #define xa_lock(xa) spin_lock(&(xa)->xa_lock)
| ^~~~~~~
drivers/staging/greybus/uart.c:346:2: note: in expansion of macro 'xa_lock'
346 | xa_lock(&table_lock);
| ^~~~~~~
include/linux/xarray.h:531:43: error: 'struct mutex' has no member named 'xa_lock'; did you mean 'wait_lock'?
531 | #define xa_unlock(xa) spin_unlock(&(xa)->xa_lock)
| ^~~~~~~
drivers/staging/greybus/uart.c:358:2: note: in expansion of macro 'xa_unlock'
358 | xa_unlock(&table_lock);
| ^~~~~~~~~
vim +530 include/linux/xarray.h
9b89a035514468 Matthew Wilcox 2017-11-10 420
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 421) /**
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 422) * xa_for_each_range() - Iterate over a portion of an XArray.
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 423) * @xa: XArray.
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 424) * @index: Index of @entry.
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 425) * @entry: Entry retrieved from array.
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 426) * @start: First index to retrieve from array.
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 427) * @last: Last index to retrieve from array.
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 428) *
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 429) * During the iteration, @entry will have the value of the entry stored
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 430) * in @xa at @index. You may modify @index during the iteration if you
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 431) * want to skip or reprocess indices. It is safe to modify the array
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 432) * during the iteration. At the end of the iteration, @entry will be set
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 433) * to NULL and @index will have a value less than or equal to max.
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 434) *
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 435) * xa_for_each_range() is O(n.log(n)) while xas_for_each() is O(n). You have
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 436) * to handle your own locking with xas_for_each(), and if you have to unlock
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 437) * after each iteration, it will also end up being O(n.log(n)).
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 438) * xa_for_each_range() will spin if it hits a retry entry; if you intend to
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 439) * see retry entries, you should use the xas_for_each() iterator instead.
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 440) * The xas_for_each() iterator will expand into more inline code than
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 441) * xa_for_each_range().
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 442) *
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 443) * Context: Any context. Takes and releases the RCU lock.
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 444) */
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 445) #define xa_for_each_range(xa, index, entry, start, last) \
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 446) for (index = start, \
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 447) entry = xa_find(xa, &index, last, XA_PRESENT); \
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 448) entry; \
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 449) entry = xa_find_after(xa, &index, last, XA_PRESENT))
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 450)
b803b42823d0d9 Matthew Wilcox 2017-11-14 451 /**
4a31896c5b5a27 Matthew Wilcox 2018-12-17 452 * xa_for_each_start() - Iterate over a portion of an XArray.
b803b42823d0d9 Matthew Wilcox 2017-11-14 453 * @xa: XArray.
4a31896c5b5a27 Matthew Wilcox 2018-12-17 454 * @index: Index of @entry.
b803b42823d0d9 Matthew Wilcox 2017-11-14 455 * @entry: Entry retrieved from array.
4a31896c5b5a27 Matthew Wilcox 2018-12-17 456 * @start: First index to retrieve from array.
4a31896c5b5a27 Matthew Wilcox 2018-12-17 457 *
4a31896c5b5a27 Matthew Wilcox 2018-12-17 458 * During the iteration, @entry will have the value of the entry stored
4a31896c5b5a27 Matthew Wilcox 2018-12-17 459 * in @xa at @index. You may modify @index during the iteration if you
4a31896c5b5a27 Matthew Wilcox 2018-12-17 460 * want to skip or reprocess indices. It is safe to modify the array
4a31896c5b5a27 Matthew Wilcox 2018-12-17 461 * during the iteration. At the end of the iteration, @entry will be set
4a31896c5b5a27 Matthew Wilcox 2018-12-17 462 * to NULL and @index will have a value less than or equal to max.
4a31896c5b5a27 Matthew Wilcox 2018-12-17 463 *
4a31896c5b5a27 Matthew Wilcox 2018-12-17 464 * xa_for_each_start() is O(n.log(n)) while xas_for_each() is O(n). You have
4a31896c5b5a27 Matthew Wilcox 2018-12-17 465 * to handle your own locking with xas_for_each(), and if you have to unlock
4a31896c5b5a27 Matthew Wilcox 2018-12-17 466 * after each iteration, it will also end up being O(n.log(n)).
4a31896c5b5a27 Matthew Wilcox 2018-12-17 467 * xa_for_each_start() will spin if it hits a retry entry; if you intend to
4a31896c5b5a27 Matthew Wilcox 2018-12-17 468 * see retry entries, you should use the xas_for_each() iterator instead.
4a31896c5b5a27 Matthew Wilcox 2018-12-17 469 * The xas_for_each() iterator will expand into more inline code than
4a31896c5b5a27 Matthew Wilcox 2018-12-17 470 * xa_for_each_start().
4a31896c5b5a27 Matthew Wilcox 2018-12-17 471 *
4a31896c5b5a27 Matthew Wilcox 2018-12-17 472 * Context: Any context. Takes and releases the RCU lock.
4a31896c5b5a27 Matthew Wilcox 2018-12-17 473 */
4a31896c5b5a27 Matthew Wilcox 2018-12-17 474 #define xa_for_each_start(xa, index, entry, start) \
00ed452c210a0b Matthew Wilcox (Oracle 2020-01-12 475) xa_for_each_range(xa, index, entry, start, ULONG_MAX)
4a31896c5b5a27 Matthew Wilcox 2018-12-17 476
4a31896c5b5a27 Matthew Wilcox 2018-12-17 477 /**
4a31896c5b5a27 Matthew Wilcox 2018-12-17 478 * xa_for_each() - Iterate over present entries in an XArray.
4a31896c5b5a27 Matthew Wilcox 2018-12-17 479 * @xa: XArray.
b803b42823d0d9 Matthew Wilcox 2017-11-14 480 * @index: Index of @entry.
4a31896c5b5a27 Matthew Wilcox 2018-12-17 481 * @entry: Entry retrieved from array.
b803b42823d0d9 Matthew Wilcox 2017-11-14 482 *
4a31896c5b5a27 Matthew Wilcox 2018-12-17 483 * During the iteration, @entry will have the value of the entry stored
4a31896c5b5a27 Matthew Wilcox 2018-12-17 484 * in @xa at @index. You may modify @index during the iteration if you want
4a31896c5b5a27 Matthew Wilcox 2018-12-17 485 * to skip or reprocess indices. It is safe to modify the array during the
4a31896c5b5a27 Matthew Wilcox 2018-12-17 486 * iteration. At the end of the iteration, @entry will be set to NULL and
4a31896c5b5a27 Matthew Wilcox 2018-12-17 487 * @index will have a value less than or equal to max.
b803b42823d0d9 Matthew Wilcox 2017-11-14 488 *
b803b42823d0d9 Matthew Wilcox 2017-11-14 489 * xa_for_each() is O(n.log(n)) while xas_for_each() is O(n). You have
b803b42823d0d9 Matthew Wilcox 2017-11-14 490 * to handle your own locking with xas_for_each(), and if you have to unlock
b803b42823d0d9 Matthew Wilcox 2017-11-14 491 * after each iteration, it will also end up being O(n.log(n)). xa_for_each()
b803b42823d0d9 Matthew Wilcox 2017-11-14 492 * will spin if it hits a retry entry; if you intend to see retry entries,
b803b42823d0d9 Matthew Wilcox 2017-11-14 493 * you should use the xas_for_each() iterator instead. The xas_for_each()
b803b42823d0d9 Matthew Wilcox 2017-11-14 494 * iterator will expand into more inline code than xa_for_each().
b803b42823d0d9 Matthew Wilcox 2017-11-14 495 *
b803b42823d0d9 Matthew Wilcox 2017-11-14 496 * Context: Any context. Takes and releases the RCU lock.
b803b42823d0d9 Matthew Wilcox 2017-11-14 497 */
4a31896c5b5a27 Matthew Wilcox 2018-12-17 498 #define xa_for_each(xa, index, entry) \
4a31896c5b5a27 Matthew Wilcox 2018-12-17 499 xa_for_each_start(xa, index, entry, 0)
4a31896c5b5a27 Matthew Wilcox 2018-12-17 500
4a31896c5b5a27 Matthew Wilcox 2018-12-17 501 /**
4a31896c5b5a27 Matthew Wilcox 2018-12-17 502 * xa_for_each_marked() - Iterate over marked entries in an XArray.
4a31896c5b5a27 Matthew Wilcox 2018-12-17 503 * @xa: XArray.
4a31896c5b5a27 Matthew Wilcox 2018-12-17 504 * @index: Index of @entry.
4a31896c5b5a27 Matthew Wilcox 2018-12-17 505 * @entry: Entry retrieved from array.
4a31896c5b5a27 Matthew Wilcox 2018-12-17 506 * @filter: Selection criterion.
4a31896c5b5a27 Matthew Wilcox 2018-12-17 507 *
4a31896c5b5a27 Matthew Wilcox 2018-12-17 508 * During the iteration, @entry will have the value of the entry stored
4a31896c5b5a27 Matthew Wilcox 2018-12-17 509 * in @xa at @index. The iteration will skip all entries in the array
4a31896c5b5a27 Matthew Wilcox 2018-12-17 510 * which do not match @filter. You may modify @index during the iteration
4a31896c5b5a27 Matthew Wilcox 2018-12-17 511 * if you want to skip or reprocess indices. It is safe to modify the array
4a31896c5b5a27 Matthew Wilcox 2018-12-17 512 * during the iteration. At the end of the iteration, @entry will be set to
4a31896c5b5a27 Matthew Wilcox 2018-12-17 513 * NULL and @index will have a value less than or equal to max.
4a31896c5b5a27 Matthew Wilcox 2018-12-17 514 *
4a31896c5b5a27 Matthew Wilcox 2018-12-17 515 * xa_for_each_marked() is O(n.log(n)) while xas_for_each_marked() is O(n).
4a31896c5b5a27 Matthew Wilcox 2018-12-17 516 * You have to handle your own locking with xas_for_each(), and if you have
4a31896c5b5a27 Matthew Wilcox 2018-12-17 517 * to unlock after each iteration, it will also end up being O(n.log(n)).
4a31896c5b5a27 Matthew Wilcox 2018-12-17 518 * xa_for_each_marked() will spin if it hits a retry entry; if you intend to
4a31896c5b5a27 Matthew Wilcox 2018-12-17 519 * see retry entries, you should use the xas_for_each_marked() iterator
4a31896c5b5a27 Matthew Wilcox 2018-12-17 520 * instead. The xas_for_each_marked() iterator will expand into more inline
4a31896c5b5a27 Matthew Wilcox 2018-12-17 521 * code than xa_for_each_marked().
4a31896c5b5a27 Matthew Wilcox 2018-12-17 522 *
4a31896c5b5a27 Matthew Wilcox 2018-12-17 523 * Context: Any context. Takes and releases the RCU lock.
4a31896c5b5a27 Matthew Wilcox 2018-12-17 524 */
4a31896c5b5a27 Matthew Wilcox 2018-12-17 525 #define xa_for_each_marked(xa, index, entry, filter) \
4a31896c5b5a27 Matthew Wilcox 2018-12-17 526 for (index = 0, entry = xa_find(xa, &index, ULONG_MAX, filter); \
4a31896c5b5a27 Matthew Wilcox 2018-12-17 527 entry; entry = xa_find_after(xa, &index, ULONG_MAX, filter))
b803b42823d0d9 Matthew Wilcox 2017-11-14 528
f6bb2a2c0b81c4 Matthew Wilcox 2018-04-10 529 #define xa_trylock(xa) spin_trylock(&(xa)->xa_lock)
f6bb2a2c0b81c4 Matthew Wilcox 2018-04-10 @530 #define xa_lock(xa) spin_lock(&(xa)->xa_lock)
f6bb2a2c0b81c4 Matthew Wilcox 2018-04-10 531 #define xa_unlock(xa) spin_unlock(&(xa)->xa_lock)
f6bb2a2c0b81c4 Matthew Wilcox 2018-04-10 532 #define xa_lock_bh(xa) spin_lock_bh(&(xa)->xa_lock)
f6bb2a2c0b81c4 Matthew Wilcox 2018-04-10 533 #define xa_unlock_bh(xa) spin_unlock_bh(&(xa)->xa_lock)
f6bb2a2c0b81c4 Matthew Wilcox 2018-04-10 534 #define xa_lock_irq(xa) spin_lock_irq(&(xa)->xa_lock)
f6bb2a2c0b81c4 Matthew Wilcox 2018-04-10 535 #define xa_unlock_irq(xa) spin_unlock_irq(&(xa)->xa_lock)
f6bb2a2c0b81c4 Matthew Wilcox 2018-04-10 536 #define xa_lock_irqsave(xa, flags) \
f6bb2a2c0b81c4 Matthew Wilcox 2018-04-10 537 spin_lock_irqsave(&(xa)->xa_lock, flags)
f6bb2a2c0b81c4 Matthew Wilcox 2018-04-10 538 #define xa_unlock_irqrestore(xa, flags) \
f6bb2a2c0b81c4 Matthew Wilcox 2018-04-10 539 spin_unlock_irqrestore(&(xa)->xa_lock, flags)
82a958497dc912 Matthew Wilcox (Oracle 2020-01-17 540) #define xa_lock_nested(xa, subclass) \
82a958497dc912 Matthew Wilcox (Oracle 2020-01-17 541) spin_lock_nested(&(xa)->xa_lock, subclass)
82a958497dc912 Matthew Wilcox (Oracle 2020-01-17 542) #define xa_lock_bh_nested(xa, subclass) \
82a958497dc912 Matthew Wilcox (Oracle 2020-01-17 543) spin_lock_bh_nested(&(xa)->xa_lock, subclass)
82a958497dc912 Matthew Wilcox (Oracle 2020-01-17 544) #define xa_lock_irq_nested(xa, subclass) \
82a958497dc912 Matthew Wilcox (Oracle 2020-01-17 545) spin_lock_irq_nested(&(xa)->xa_lock, subclass)
82a958497dc912 Matthew Wilcox (Oracle 2020-01-17 546) #define xa_lock_irqsave_nested(xa, flags, subclass) \
82a958497dc912 Matthew Wilcox (Oracle 2020-01-17 547) spin_lock_irqsave_nested(&(xa)->xa_lock, flags, subclass)
f6bb2a2c0b81c4 Matthew Wilcox 2018-04-10 548
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 36433 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] staging: greybus: Convert uart.c from IDR to XArray
2021-08-14 14:56 Fabio M. De Francesco
@ 2021-08-14 17:20 ` kernel test robot
2021-08-14 17:35 ` kernel test robot
1 sibling, 0 replies; 6+ messages in thread
From: kernel test robot @ 2021-08-14 17:20 UTC (permalink / raw)
To: Fabio M. De Francesco, Johan Hovold, Alex Elder,
Greg Kroah-Hartman, greybus-dev, linux-staging, linux-kernel
Cc: clang-built-linux, kbuild-all, Fabio M. De Francesco
[-- Attachment #1: Type: text/plain, Size: 2846 bytes --]
Hi "Fabio,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on staging/staging-testing]
url: https://github.com/0day-ci/linux/commits/Fabio-M-De-Francesco/staging-greybus-Convert-uart-c-from-IDR-to-XArray/20210814-225807
base: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging.git 0bd35146642bdc56f1b87d75f047b1c92bd2bd39
config: riscv-randconfig-r042-20210814 (attached as .config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 1f7b25ea76a925aca690da28de9d78db7ca99d0c)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/901c5fde0540c767590bce646219889730c4a41b
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Fabio-M-De-Francesco/staging-greybus-Convert-uart-c-from-IDR-to-XArray/20210814-225807
git checkout 901c5fde0540c767590bce646219889730c4a41b
# save the attached .config to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross O=build_dir ARCH=riscv SHELL=/bin/bash drivers/staging/greybus/
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
All errors (new ones prefixed by >>):
>> drivers/staging/greybus/uart.c:346:2: error: no member named 'xa_lock' in 'struct mutex'
xa_lock(&table_lock);
^~~~~~~~~~~~~~~~~~~~
include/linux/xarray.h:530:39: note: expanded from macro 'xa_lock'
#define xa_lock(xa) spin_lock(&(xa)->xa_lock)
~~~~ ^
drivers/staging/greybus/uart.c:358:2: error: no member named 'xa_lock' in 'struct mutex'
xa_unlock(&table_lock);
^~~~~~~~~~~~~~~~~~~~~~
include/linux/xarray.h:531:43: note: expanded from macro 'xa_unlock'
#define xa_unlock(xa) spin_unlock(&(xa)->xa_lock)
~~~~ ^
2 errors generated.
vim +346 drivers/staging/greybus/uart.c
341
342 static struct gb_tty *get_gb_by_minor(unsigned int minor)
343 {
344 struct gb_tty *gb_tty;
345
> 346 xa_lock(&table_lock);
347 gb_tty = xa_load(&tty_minors, minor);
348 if (gb_tty) {
349 mutex_lock(&gb_tty->mutex);
350 if (gb_tty->disconnected) {
351 mutex_unlock(&gb_tty->mutex);
352 gb_tty = NULL;
353 } else {
354 tty_port_get(&gb_tty->port);
355 mutex_unlock(&gb_tty->mutex);
356 }
357 }
358 xa_unlock(&table_lock);
359 return gb_tty;
360 }
361
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 31201 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] staging: greybus: Convert uart.c from IDR to XArray
@ 2021-08-14 17:20 ` kernel test robot
0 siblings, 0 replies; 6+ messages in thread
From: kernel test robot @ 2021-08-14 17:20 UTC (permalink / raw)
To: kbuild-all
[-- Attachment #1: Type: text/plain, Size: 2916 bytes --]
Hi "Fabio,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on staging/staging-testing]
url: https://github.com/0day-ci/linux/commits/Fabio-M-De-Francesco/staging-greybus-Convert-uart-c-from-IDR-to-XArray/20210814-225807
base: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging.git 0bd35146642bdc56f1b87d75f047b1c92bd2bd39
config: riscv-randconfig-r042-20210814 (attached as .config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 1f7b25ea76a925aca690da28de9d78db7ca99d0c)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/901c5fde0540c767590bce646219889730c4a41b
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Fabio-M-De-Francesco/staging-greybus-Convert-uart-c-from-IDR-to-XArray/20210814-225807
git checkout 901c5fde0540c767590bce646219889730c4a41b
# save the attached .config to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross O=build_dir ARCH=riscv SHELL=/bin/bash drivers/staging/greybus/
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
All errors (new ones prefixed by >>):
>> drivers/staging/greybus/uart.c:346:2: error: no member named 'xa_lock' in 'struct mutex'
xa_lock(&table_lock);
^~~~~~~~~~~~~~~~~~~~
include/linux/xarray.h:530:39: note: expanded from macro 'xa_lock'
#define xa_lock(xa) spin_lock(&(xa)->xa_lock)
~~~~ ^
drivers/staging/greybus/uart.c:358:2: error: no member named 'xa_lock' in 'struct mutex'
xa_unlock(&table_lock);
^~~~~~~~~~~~~~~~~~~~~~
include/linux/xarray.h:531:43: note: expanded from macro 'xa_unlock'
#define xa_unlock(xa) spin_unlock(&(xa)->xa_lock)
~~~~ ^
2 errors generated.
vim +346 drivers/staging/greybus/uart.c
341
342 static struct gb_tty *get_gb_by_minor(unsigned int minor)
343 {
344 struct gb_tty *gb_tty;
345
> 346 xa_lock(&table_lock);
347 gb_tty = xa_load(&tty_minors, minor);
348 if (gb_tty) {
349 mutex_lock(&gb_tty->mutex);
350 if (gb_tty->disconnected) {
351 mutex_unlock(&gb_tty->mutex);
352 gb_tty = NULL;
353 } else {
354 tty_port_get(&gb_tty->port);
355 mutex_unlock(&gb_tty->mutex);
356 }
357 }
358 xa_unlock(&table_lock);
359 return gb_tty;
360 }
361
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 31201 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] staging: greybus: Convert uart.c from IDR to XArray
@ 2021-08-14 14:56 Fabio M. De Francesco
2021-08-14 17:20 ` kernel test robot
2021-08-14 17:35 ` kernel test robot
0 siblings, 2 replies; 6+ messages in thread
From: Fabio M. De Francesco @ 2021-08-14 14:56 UTC (permalink / raw)
To: Johan Hovold, Alex Elder, Greg Kroah-Hartman, greybus-dev,
linux-staging, linux-kernel
Cc: Fabio M. De Francesco
Convert greybus/uart.c from IDR to XArray. The abstract data type XArray
is more memory-efficient, parallelisable, and cache friendly. It takes
advantage of RCU to perform lookups without locking. Furthermore, IDR is
deprecated because XArray has a better (cleaner and more consistent) API.
Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
---
drivers/staging/greybus/uart.c | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/drivers/staging/greybus/uart.c b/drivers/staging/greybus/uart.c
index 73f01ed1e5b7..7c19156534ca 100644
--- a/drivers/staging/greybus/uart.c
+++ b/drivers/staging/greybus/uart.c
@@ -22,7 +22,7 @@
#include <linux/serial.h>
#include <linux/tty_driver.h>
#include <linux/tty_flip.h>
-#include <linux/idr.h>
+#include <linux/xarray.h>
#include <linux/fs.h>
#include <linux/kdev_t.h>
#include <linux/kfifo.h>
@@ -33,6 +33,7 @@
#include "gbphy.h"
#define GB_NUM_MINORS 16 /* 16 is more than enough */
+#define GB_RANGE_MINORS XA_LIMIT(0, GB_NUM_MINORS)
#define GB_NAME "ttyGB"
#define GB_UART_WRITE_FIFO_SIZE PAGE_SIZE
@@ -67,7 +68,7 @@ struct gb_tty {
};
static struct tty_driver *gb_tty_driver;
-static DEFINE_IDR(tty_minors);
+static DEFINE_XARRAY(tty_minors);
static DEFINE_MUTEX(table_lock);
static int gb_uart_receive_data_handler(struct gb_operation *op)
@@ -77,6 +78,7 @@ static int gb_uart_receive_data_handler(struct gb_operation *op)
struct tty_port *port = &gb_tty->port;
struct gb_message *request = op->request;
struct gb_uart_recv_data_request *receive_data;
+
u16 recv_data_size;
int count;
unsigned long tty_flags = TTY_NORMAL;
@@ -341,8 +343,8 @@ 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);
+ xa_lock(&table_lock);
+ gb_tty = xa_load(&tty_minors, minor);
if (gb_tty) {
mutex_lock(&gb_tty->mutex);
if (gb_tty->disconnected) {
@@ -353,19 +355,19 @@ static struct gb_tty *get_gb_by_minor(unsigned int minor)
mutex_unlock(&gb_tty->mutex);
}
}
- mutex_unlock(&table_lock);
+ xa_unlock(&table_lock);
return gb_tty;
}
static int alloc_minor(struct gb_tty *gb_tty)
{
int minor;
+ int ret;
- mutex_lock(&table_lock);
- minor = idr_alloc(&tty_minors, gb_tty, 0, GB_NUM_MINORS, GFP_KERNEL);
- mutex_unlock(&table_lock);
- if (minor >= 0)
- gb_tty->minor = minor;
+ ret = xa_alloc(&tty_minors, &minor, gb_tty, GB_RANGE_MINORS, GFP_KERNEL);
+ if (ret)
+ return ret;
+ gb_tty->minor = minor;
return minor;
}
@@ -374,9 +376,7 @@ static void release_minor(struct gb_tty *gb_tty)
int minor = gb_tty->minor;
gb_tty->minor = 0; /* Maybe should use an invalid value instead */
- mutex_lock(&table_lock);
- idr_remove(&tty_minors, minor);
- mutex_unlock(&table_lock);
+ xa_erase(&tty_minors, minor);
}
static int gb_tty_install(struct tty_driver *driver, struct tty_struct *tty)
@@ -982,7 +982,7 @@ static void gb_tty_exit(void)
{
tty_unregister_driver(gb_tty_driver);
put_tty_driver(gb_tty_driver);
- idr_destroy(&tty_minors);
+ xa_destroy(&tty_minors);
}
static const struct gbphy_device_id gb_uart_id_table[] = {
--
2.32.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-08-14 17:57 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-14 17:56 [PATCH] staging: greybus: Convert uart.c from IDR to XArray Fabio M. De Francesco
-- strict thread matches above, loose matches on Subject: below --
2021-08-14 14:56 Fabio M. De Francesco
2021-08-14 17:20 ` kernel test robot
2021-08-14 17:20 ` kernel test robot
2021-08-14 17:35 ` kernel test robot
2021-08-14 17:35 ` kernel test robot
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.