diff mbox series

[-next] IB/mlx5: Add missing error code

Message ID 20210222082503.22388-1-yuehaibing@huawei.com (mailing list archive)
State Superseded
Headers show
Series [-next] IB/mlx5: Add missing error code | expand

Commit Message

Yue Haibing Feb. 22, 2021, 8:25 a.m. UTC
Set err to -ENOMEM if kzalloc fails instead of 0.

Fixes: 759738537142 ("IB/mlx5: Enable subscription for device events over DEVX")
Signed-off-by: YueHaibing <yuehaibing@huawei.com>
---
 drivers/infiniband/hw/mlx5/devx.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

kernel test robot Feb. 22, 2021, 12:12 p.m. UTC | #1
Hi YueHaibing,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on next-20210219]

url:    https://github.com/0day-ci/linux/commits/YueHaibing/IB-mlx5-Add-missing-error-code/20210222-162815
base:    abaf6f60176f1ae9d946d63e4db63164600b7b1a
config: arc-allyesconfig (attached as .config)
compiler: arceb-elf-gcc (GCC) 9.3.0
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/893d2d872d109265f4b7419499d5de46c47895a7
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review YueHaibing/IB-mlx5-Add-missing-error-code/20210222-162815
        git checkout 893d2d872d109265f4b7419499d5de46c47895a7
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arc 

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/infiniband/hw/mlx5/devx.c: In function 'mlx5_ib_handler_MLX5_IB_METHOD_DEVX_SUBSCRIBE_EVENT':
>> drivers/infiniband/hw/mlx5/devx.c:2078:4: error: expected ';' before 'goto'
    2078 |    goto err;
         |    ^~~~


vim +2078 drivers/infiniband/hw/mlx5/devx.c

7597385371425f Yishai Hadas    2019-06-30  1971  
7597385371425f Yishai Hadas    2019-06-30  1972  #define MAX_NUM_EVENTS 16
7597385371425f Yishai Hadas    2019-06-30  1973  static int UVERBS_HANDLER(MLX5_IB_METHOD_DEVX_SUBSCRIBE_EVENT)(
7597385371425f Yishai Hadas    2019-06-30  1974  	struct uverbs_attr_bundle *attrs)
7597385371425f Yishai Hadas    2019-06-30  1975  {
7597385371425f Yishai Hadas    2019-06-30  1976  	struct ib_uobject *devx_uobj = uverbs_attr_get_uobject(
7597385371425f Yishai Hadas    2019-06-30  1977  				attrs,
7597385371425f Yishai Hadas    2019-06-30  1978  				MLX5_IB_ATTR_DEVX_SUBSCRIBE_EVENT_OBJ_HANDLE);
7597385371425f Yishai Hadas    2019-06-30  1979  	struct mlx5_ib_ucontext *c = rdma_udata_to_drv_context(
7597385371425f Yishai Hadas    2019-06-30  1980  		&attrs->driver_udata, struct mlx5_ib_ucontext, ibucontext);
7597385371425f Yishai Hadas    2019-06-30  1981  	struct mlx5_ib_dev *dev = to_mdev(c->ibucontext.device);
7597385371425f Yishai Hadas    2019-06-30  1982  	struct ib_uobject *fd_uobj;
7597385371425f Yishai Hadas    2019-06-30  1983  	struct devx_obj *obj = NULL;
7597385371425f Yishai Hadas    2019-06-30  1984  	struct devx_async_event_file *ev_file;
7597385371425f Yishai Hadas    2019-06-30  1985  	struct mlx5_devx_event_table *devx_event_table = &dev->devx_event_table;
7597385371425f Yishai Hadas    2019-06-30  1986  	u16 *event_type_num_list;
7597385371425f Yishai Hadas    2019-06-30  1987  	struct devx_event_subscription *event_sub, *tmp_sub;
7597385371425f Yishai Hadas    2019-06-30  1988  	struct list_head sub_list;
7597385371425f Yishai Hadas    2019-06-30  1989  	int redirect_fd;
7597385371425f Yishai Hadas    2019-06-30  1990  	bool use_eventfd = false;
7597385371425f Yishai Hadas    2019-06-30  1991  	int num_events;
7597385371425f Yishai Hadas    2019-06-30  1992  	int num_alloc_xa_entries = 0;
7597385371425f Yishai Hadas    2019-06-30  1993  	u16 obj_type = 0;
7597385371425f Yishai Hadas    2019-06-30  1994  	u64 cookie = 0;
7597385371425f Yishai Hadas    2019-06-30  1995  	u32 obj_id = 0;
7597385371425f Yishai Hadas    2019-06-30  1996  	int err;
7597385371425f Yishai Hadas    2019-06-30  1997  	int i;
7597385371425f Yishai Hadas    2019-06-30  1998  
7597385371425f Yishai Hadas    2019-06-30  1999  	if (!c->devx_uid)
7597385371425f Yishai Hadas    2019-06-30  2000  		return -EINVAL;
7597385371425f Yishai Hadas    2019-06-30  2001  
7597385371425f Yishai Hadas    2019-06-30  2002  	if (!IS_ERR(devx_uobj)) {
7597385371425f Yishai Hadas    2019-06-30  2003  		obj = (struct devx_obj *)devx_uobj->object;
7597385371425f Yishai Hadas    2019-06-30  2004  		if (obj)
7597385371425f Yishai Hadas    2019-06-30  2005  			obj_id = get_dec_obj_id(obj->obj_id);
7597385371425f Yishai Hadas    2019-06-30  2006  	}
7597385371425f Yishai Hadas    2019-06-30  2007  
7597385371425f Yishai Hadas    2019-06-30  2008  	fd_uobj = uverbs_attr_get_uobject(attrs,
7597385371425f Yishai Hadas    2019-06-30  2009  				MLX5_IB_ATTR_DEVX_SUBSCRIBE_EVENT_FD_HANDLE);
7597385371425f Yishai Hadas    2019-06-30  2010  	if (IS_ERR(fd_uobj))
7597385371425f Yishai Hadas    2019-06-30  2011  		return PTR_ERR(fd_uobj);
7597385371425f Yishai Hadas    2019-06-30  2012  
7597385371425f Yishai Hadas    2019-06-30  2013  	ev_file = container_of(fd_uobj, struct devx_async_event_file,
7597385371425f Yishai Hadas    2019-06-30  2014  			       uobj);
7597385371425f Yishai Hadas    2019-06-30  2015  
7597385371425f Yishai Hadas    2019-06-30  2016  	if (uverbs_attr_is_valid(attrs,
7597385371425f Yishai Hadas    2019-06-30  2017  				 MLX5_IB_ATTR_DEVX_SUBSCRIBE_EVENT_FD_NUM)) {
7597385371425f Yishai Hadas    2019-06-30  2018  		err = uverbs_copy_from(&redirect_fd, attrs,
7597385371425f Yishai Hadas    2019-06-30  2019  			       MLX5_IB_ATTR_DEVX_SUBSCRIBE_EVENT_FD_NUM);
7597385371425f Yishai Hadas    2019-06-30  2020  		if (err)
7597385371425f Yishai Hadas    2019-06-30  2021  			return err;
7597385371425f Yishai Hadas    2019-06-30  2022  
7597385371425f Yishai Hadas    2019-06-30  2023  		use_eventfd = true;
7597385371425f Yishai Hadas    2019-06-30  2024  	}
7597385371425f Yishai Hadas    2019-06-30  2025  
7597385371425f Yishai Hadas    2019-06-30  2026  	if (uverbs_attr_is_valid(attrs,
7597385371425f Yishai Hadas    2019-06-30  2027  				 MLX5_IB_ATTR_DEVX_SUBSCRIBE_EVENT_COOKIE)) {
7597385371425f Yishai Hadas    2019-06-30  2028  		if (use_eventfd)
7597385371425f Yishai Hadas    2019-06-30  2029  			return -EINVAL;
7597385371425f Yishai Hadas    2019-06-30  2030  
7597385371425f Yishai Hadas    2019-06-30  2031  		err = uverbs_copy_from(&cookie, attrs,
7597385371425f Yishai Hadas    2019-06-30  2032  				MLX5_IB_ATTR_DEVX_SUBSCRIBE_EVENT_COOKIE);
7597385371425f Yishai Hadas    2019-06-30  2033  		if (err)
7597385371425f Yishai Hadas    2019-06-30  2034  			return err;
7597385371425f Yishai Hadas    2019-06-30  2035  	}
7597385371425f Yishai Hadas    2019-06-30  2036  
7597385371425f Yishai Hadas    2019-06-30  2037  	num_events = uverbs_attr_ptr_get_array_size(
7597385371425f Yishai Hadas    2019-06-30  2038  		attrs, MLX5_IB_ATTR_DEVX_SUBSCRIBE_EVENT_TYPE_NUM_LIST,
7597385371425f Yishai Hadas    2019-06-30  2039  		sizeof(u16));
7597385371425f Yishai Hadas    2019-06-30  2040  
7597385371425f Yishai Hadas    2019-06-30  2041  	if (num_events < 0)
7597385371425f Yishai Hadas    2019-06-30  2042  		return num_events;
7597385371425f Yishai Hadas    2019-06-30  2043  
7597385371425f Yishai Hadas    2019-06-30  2044  	if (num_events > MAX_NUM_EVENTS)
7597385371425f Yishai Hadas    2019-06-30  2045  		return -EINVAL;
7597385371425f Yishai Hadas    2019-06-30  2046  
7597385371425f Yishai Hadas    2019-06-30  2047  	event_type_num_list = uverbs_attr_get_alloced_ptr(attrs,
7597385371425f Yishai Hadas    2019-06-30  2048  			MLX5_IB_ATTR_DEVX_SUBSCRIBE_EVENT_TYPE_NUM_LIST);
7597385371425f Yishai Hadas    2019-06-30  2049  
7597385371425f Yishai Hadas    2019-06-30  2050  	if (!is_valid_events(dev->mdev, num_events, event_type_num_list, obj))
7597385371425f Yishai Hadas    2019-06-30  2051  		return -EINVAL;
7597385371425f Yishai Hadas    2019-06-30  2052  
7597385371425f Yishai Hadas    2019-06-30  2053  	INIT_LIST_HEAD(&sub_list);
7597385371425f Yishai Hadas    2019-06-30  2054  
7597385371425f Yishai Hadas    2019-06-30  2055  	/* Protect from concurrent subscriptions to same XA entries to allow
7597385371425f Yishai Hadas    2019-06-30  2056  	 * both to succeed
7597385371425f Yishai Hadas    2019-06-30  2057  	 */
7597385371425f Yishai Hadas    2019-06-30  2058  	mutex_lock(&devx_event_table->event_xa_lock);
7597385371425f Yishai Hadas    2019-06-30  2059  	for (i = 0; i < num_events; i++) {
7597385371425f Yishai Hadas    2019-06-30  2060  		u32 key_level1;
7597385371425f Yishai Hadas    2019-06-30  2061  
7597385371425f Yishai Hadas    2019-06-30  2062  		if (obj)
7597385371425f Yishai Hadas    2019-06-30  2063  			obj_type = get_dec_obj_type(obj,
7597385371425f Yishai Hadas    2019-06-30  2064  						    event_type_num_list[i]);
7597385371425f Yishai Hadas    2019-06-30  2065  		key_level1 = event_type_num_list[i] | obj_type << 16;
7597385371425f Yishai Hadas    2019-06-30  2066  
7597385371425f Yishai Hadas    2019-06-30  2067  		err = subscribe_event_xa_alloc(devx_event_table,
7597385371425f Yishai Hadas    2019-06-30  2068  					       key_level1,
7597385371425f Yishai Hadas    2019-06-30  2069  					       obj,
7597385371425f Yishai Hadas    2019-06-30  2070  					       obj_id);
7597385371425f Yishai Hadas    2019-06-30  2071  		if (err)
7597385371425f Yishai Hadas    2019-06-30  2072  			goto err;
7597385371425f Yishai Hadas    2019-06-30  2073  
7597385371425f Yishai Hadas    2019-06-30  2074  		num_alloc_xa_entries++;
7597385371425f Yishai Hadas    2019-06-30  2075  		event_sub = kzalloc(sizeof(*event_sub), GFP_KERNEL);
893d2d872d1092 YueHaibing      2021-02-22  2076  		if (!event_sub) {
893d2d872d1092 YueHaibing      2021-02-22  2077  			err = -ENOMEM
7597385371425f Yishai Hadas    2019-06-30 @2078  			goto err;
893d2d872d1092 YueHaibing      2021-02-22  2079  		}
7597385371425f Yishai Hadas    2019-06-30  2080  
7597385371425f Yishai Hadas    2019-06-30  2081  		list_add_tail(&event_sub->event_list, &sub_list);
6898d1c661d79f Jason Gunthorpe 2020-01-08  2082  		uverbs_uobject_get(&ev_file->uobj);
7597385371425f Yishai Hadas    2019-06-30  2083  		if (use_eventfd) {
7597385371425f Yishai Hadas    2019-06-30  2084  			event_sub->eventfd =
7597385371425f Yishai Hadas    2019-06-30  2085  				eventfd_ctx_fdget(redirect_fd);
7597385371425f Yishai Hadas    2019-06-30  2086  
e7e6c6320c8c9e Dan Carpenter   2019-08-07  2087  			if (IS_ERR(event_sub->eventfd)) {
7597385371425f Yishai Hadas    2019-06-30  2088  				err = PTR_ERR(event_sub->eventfd);
7597385371425f Yishai Hadas    2019-06-30  2089  				event_sub->eventfd = NULL;
7597385371425f Yishai Hadas    2019-06-30  2090  				goto err;
7597385371425f Yishai Hadas    2019-06-30  2091  			}
7597385371425f Yishai Hadas    2019-06-30  2092  		}
7597385371425f Yishai Hadas    2019-06-30  2093  
7597385371425f Yishai Hadas    2019-06-30  2094  		event_sub->cookie = cookie;
7597385371425f Yishai Hadas    2019-06-30  2095  		event_sub->ev_file = ev_file;
7597385371425f Yishai Hadas    2019-06-30  2096  		/* May be needed upon cleanup the devx object/subscription */
7597385371425f Yishai Hadas    2019-06-30  2097  		event_sub->xa_key_level1 = key_level1;
7597385371425f Yishai Hadas    2019-06-30  2098  		event_sub->xa_key_level2 = obj_id;
7597385371425f Yishai Hadas    2019-06-30  2099  		INIT_LIST_HEAD(&event_sub->obj_list);
7597385371425f Yishai Hadas    2019-06-30  2100  	}
7597385371425f Yishai Hadas    2019-06-30  2101  
7597385371425f Yishai Hadas    2019-06-30  2102  	/* Once all the allocations and the XA data insertions were done we
7597385371425f Yishai Hadas    2019-06-30  2103  	 * can go ahead and add all the subscriptions to the relevant lists
7597385371425f Yishai Hadas    2019-06-30  2104  	 * without concern of a failure.
7597385371425f Yishai Hadas    2019-06-30  2105  	 */
7597385371425f Yishai Hadas    2019-06-30  2106  	list_for_each_entry_safe(event_sub, tmp_sub, &sub_list, event_list) {
7597385371425f Yishai Hadas    2019-06-30  2107  		struct devx_event *event;
7597385371425f Yishai Hadas    2019-06-30  2108  		struct devx_obj_event *obj_event;
7597385371425f Yishai Hadas    2019-06-30  2109  
7597385371425f Yishai Hadas    2019-06-30  2110  		list_del_init(&event_sub->event_list);
7597385371425f Yishai Hadas    2019-06-30  2111  
7597385371425f Yishai Hadas    2019-06-30  2112  		spin_lock_irq(&ev_file->lock);
7597385371425f Yishai Hadas    2019-06-30  2113  		list_add_tail_rcu(&event_sub->file_list,
7597385371425f Yishai Hadas    2019-06-30  2114  				  &ev_file->subscribed_events_list);
7597385371425f Yishai Hadas    2019-06-30  2115  		spin_unlock_irq(&ev_file->lock);
7597385371425f Yishai Hadas    2019-06-30  2116  
7597385371425f Yishai Hadas    2019-06-30  2117  		event = xa_load(&devx_event_table->event_xa,
7597385371425f Yishai Hadas    2019-06-30  2118  				event_sub->xa_key_level1);
7597385371425f Yishai Hadas    2019-06-30  2119  		WARN_ON(!event);
7597385371425f Yishai Hadas    2019-06-30  2120  
7597385371425f Yishai Hadas    2019-06-30  2121  		if (!obj) {
7597385371425f Yishai Hadas    2019-06-30  2122  			list_add_tail_rcu(&event_sub->xa_list,
7597385371425f Yishai Hadas    2019-06-30  2123  					  &event->unaffiliated_list);
7597385371425f Yishai Hadas    2019-06-30  2124  			continue;
7597385371425f Yishai Hadas    2019-06-30  2125  		}
7597385371425f Yishai Hadas    2019-06-30  2126  
7597385371425f Yishai Hadas    2019-06-30  2127  		obj_event = xa_load(&event->object_ids, obj_id);
7597385371425f Yishai Hadas    2019-06-30  2128  		WARN_ON(!obj_event);
7597385371425f Yishai Hadas    2019-06-30  2129  		list_add_tail_rcu(&event_sub->xa_list,
7597385371425f Yishai Hadas    2019-06-30  2130  				  &obj_event->obj_sub_list);
7597385371425f Yishai Hadas    2019-06-30  2131  		list_add_tail_rcu(&event_sub->obj_list,
7597385371425f Yishai Hadas    2019-06-30  2132  				  &obj->event_sub);
7597385371425f Yishai Hadas    2019-06-30  2133  	}
7597385371425f Yishai Hadas    2019-06-30  2134  
7597385371425f Yishai Hadas    2019-06-30  2135  	mutex_unlock(&devx_event_table->event_xa_lock);
7597385371425f Yishai Hadas    2019-06-30  2136  	return 0;
7597385371425f Yishai Hadas    2019-06-30  2137  
7597385371425f Yishai Hadas    2019-06-30  2138  err:
7597385371425f Yishai Hadas    2019-06-30  2139  	list_for_each_entry_safe(event_sub, tmp_sub, &sub_list, event_list) {
7597385371425f Yishai Hadas    2019-06-30  2140  		list_del(&event_sub->event_list);
7597385371425f Yishai Hadas    2019-06-30  2141  
7597385371425f Yishai Hadas    2019-06-30  2142  		subscribe_event_xa_dealloc(devx_event_table,
7597385371425f Yishai Hadas    2019-06-30  2143  					   event_sub->xa_key_level1,
7597385371425f Yishai Hadas    2019-06-30  2144  					   obj,
7597385371425f Yishai Hadas    2019-06-30  2145  					   obj_id);
7597385371425f Yishai Hadas    2019-06-30  2146  
7597385371425f Yishai Hadas    2019-06-30  2147  		if (event_sub->eventfd)
7597385371425f Yishai Hadas    2019-06-30  2148  			eventfd_ctx_put(event_sub->eventfd);
6898d1c661d79f Jason Gunthorpe 2020-01-08  2149  		uverbs_uobject_put(&event_sub->ev_file->uobj);
7597385371425f Yishai Hadas    2019-06-30  2150  		kfree(event_sub);
7597385371425f Yishai Hadas    2019-06-30  2151  	}
7597385371425f Yishai Hadas    2019-06-30  2152  
7597385371425f Yishai Hadas    2019-06-30  2153  	mutex_unlock(&devx_event_table->event_xa_lock);
7597385371425f Yishai Hadas    2019-06-30  2154  	return err;
7597385371425f Yishai Hadas    2019-06-30  2155  }
7597385371425f Yishai Hadas    2019-06-30  2156  

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

Patch

diff --git a/drivers/infiniband/hw/mlx5/devx.c b/drivers/infiniband/hw/mlx5/devx.c
index ebc2a4355fa5..3c8e6a25465d 100644
--- a/drivers/infiniband/hw/mlx5/devx.c
+++ b/drivers/infiniband/hw/mlx5/devx.c
@@ -2073,8 +2073,10 @@  static int UVERBS_HANDLER(MLX5_IB_METHOD_DEVX_SUBSCRIBE_EVENT)(
 
 		num_alloc_xa_entries++;
 		event_sub = kzalloc(sizeof(*event_sub), GFP_KERNEL);
-		if (!event_sub)
+		if (!event_sub) {
+			err = -ENOMEM
 			goto err;
+		}
 
 		list_add_tail(&event_sub->event_list, &sub_list);
 		uverbs_uobject_get(&ev_file->uobj);