[mnyman-xhci:dbc 5/5] drivers/usb/host/xhci-dbgtty.c:423 xhci_dbc_tty_register_device() warn: unsigned 'port->minor' is never less than zero.

From: kernel test robot
Date: Wed Jan 19 2022 - 22:28:58 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/mnyman/xhci.git dbc
head: 595547d1cfa3f6c591ea084cc1f77cd45bd81213
commit: 595547d1cfa3f6c591ea084cc1f77cd45bd81213 [5/5] xhci: dbgtty: use IDR to support several dbc instances.
config: riscv-randconfig-m031-20220118 (https://download.01.org/0day-ci/archive/20220120/202201200955.C9pzrtCw-lkp@xxxxxxxxx/config)
compiler: riscv32-linux-gcc (GCC) 11.2.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@xxxxxxxxx>

smatch warnings:
drivers/usb/host/xhci-dbgtty.c:423 xhci_dbc_tty_register_device() warn: unsigned 'port->minor' is never less than zero.

vim +423 drivers/usb/host/xhci-dbgtty.c

407
408 static int xhci_dbc_tty_register_device(struct xhci_dbc *dbc)
409 {
410 int ret;
411 struct device *tty_dev;
412 struct dbc_port *port = dbc_to_port(dbc);
413
414 if (port->registered)
415 return -EBUSY;
416
417 xhci_dbc_tty_init_port(dbc, port);
418
419 mutex_lock(&dbc_tty_minors_lock);
420 port->minor = idr_alloc(&dbc_tty_minors, port, 0, 64, GFP_KERNEL);
421 mutex_unlock(&dbc_tty_minors_lock);
422
> 423 if (port->minor < 0) {
424 ret = port->minor;
425 goto err_idr;
426 }
427
428 ret = kfifo_alloc(&port->write_fifo, DBC_WRITE_BUF_SIZE, GFP_KERNEL);
429 if (ret)
430 goto err_exit_port;
431
432 ret = xhci_dbc_alloc_requests(dbc, BULK_IN, &port->read_pool,
433 dbc_read_complete);
434 if (ret)
435 goto err_free_fifo;
436
437 ret = xhci_dbc_alloc_requests(dbc, BULK_OUT, &port->write_pool,
438 dbc_write_complete);
439 if (ret)
440 goto err_free_requests;
441
442 tty_dev = tty_port_register_device(&port->port,
443 dbc_tty_driver, port->minor, NULL);
444 if (IS_ERR(tty_dev)) {
445 ret = PTR_ERR(tty_dev);
446 goto err_free_requests;
447 }
448
449 port->registered = true;
450
451 return 0;
452
453 err_free_requests:
454 xhci_dbc_free_requests(&port->read_pool);
455 xhci_dbc_free_requests(&port->write_pool);
456 err_free_fifo:
457 kfifo_free(&port->write_fifo);
458 err_exit_port:
459 idr_remove(&dbc_tty_minors, port->minor);
460 err_idr:
461 xhci_dbc_tty_exit_port(port);
462
463 dev_err(dbc->dev, "can't register tty port, err %d\n", ret);
464
465 return ret;
466 }
467

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@xxxxxxxxxxxx