Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

IB/uverbs: Explicitly pass ib_dev to uverbs commands

Done in preparation for deploying RCU for the device removal
flow. Allows isolating the RCU handling to the uverb_main layer and
keeping the uverbs_cmd code as is.

Signed-off-by: Yishai Hadas <yishaih@mellanox.com>
Signed-off-by: Shachar Raindel <raindel@mellanox.com>
Reviewed-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>

authored by

Yishai Hadas and committed by
Doug Ledford
057aec0d 35d4a0b6

+88 -39
+3
drivers/infiniband/core/uverbs.h
··· 178 178 void idr_remove_uobj(struct idr *idp, struct ib_uobject *uobj); 179 179 180 180 struct file *ib_uverbs_alloc_event_file(struct ib_uverbs_file *uverbs_file, 181 + struct ib_device *ib_dev, 181 182 int is_async); 182 183 void ib_uverbs_free_async_event_file(struct ib_uverbs_file *uverbs_file); 183 184 struct ib_uverbs_event_file *ib_uverbs_lookup_comp_file(int fd); ··· 215 214 216 215 #define IB_UVERBS_DECLARE_CMD(name) \ 217 216 ssize_t ib_uverbs_##name(struct ib_uverbs_file *file, \ 217 + struct ib_device *ib_dev, \ 218 218 const char __user *buf, int in_len, \ 219 219 int out_len) 220 220 ··· 257 255 258 256 #define IB_UVERBS_DECLARE_EX_CMD(name) \ 259 257 int ib_uverbs_ex_##name(struct ib_uverbs_file *file, \ 258 + struct ib_device *ib_dev, \ 260 259 struct ib_udata *ucore, \ 261 260 struct ib_udata *uhw) 262 261
+70 -33
drivers/infiniband/core/uverbs_cmd.c
··· 282 282 } 283 283 284 284 ssize_t ib_uverbs_get_context(struct ib_uverbs_file *file, 285 + struct ib_device *ib_dev, 285 286 const char __user *buf, 286 287 int in_len, int out_len) 287 288 { 288 289 struct ib_uverbs_get_context cmd; 289 290 struct ib_uverbs_get_context_resp resp; 290 291 struct ib_udata udata; 291 - struct ib_device *ibdev = file->device->ib_dev; 292 292 #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING 293 293 struct ib_device_attr dev_attr; 294 294 #endif ··· 313 313 (unsigned long) cmd.response + sizeof resp, 314 314 in_len - sizeof cmd, out_len - sizeof resp); 315 315 316 - ucontext = ibdev->alloc_ucontext(ibdev, &udata); 316 + ucontext = ib_dev->alloc_ucontext(ib_dev, &udata); 317 317 if (IS_ERR(ucontext)) { 318 318 ret = PTR_ERR(ucontext); 319 319 goto err; 320 320 } 321 321 322 - ucontext->device = ibdev; 322 + ucontext->device = ib_dev; 323 323 INIT_LIST_HEAD(&ucontext->pd_list); 324 324 INIT_LIST_HEAD(&ucontext->mr_list); 325 325 INIT_LIST_HEAD(&ucontext->mw_list); ··· 340 340 ucontext->odp_mrs_count = 0; 341 341 INIT_LIST_HEAD(&ucontext->no_private_counters); 342 342 343 - ret = ib_query_device(ibdev, &dev_attr); 343 + ret = ib_query_device(ib_dev, &dev_attr); 344 344 if (ret) 345 345 goto err_free; 346 346 if (!(dev_attr.device_cap_flags & IB_DEVICE_ON_DEMAND_PAGING)) ··· 355 355 goto err_free; 356 356 resp.async_fd = ret; 357 357 358 - filp = ib_uverbs_alloc_event_file(file, 1); 358 + filp = ib_uverbs_alloc_event_file(file, ib_dev, 1); 359 359 if (IS_ERR(filp)) { 360 360 ret = PTR_ERR(filp); 361 361 goto err_fd; ··· 384 384 385 385 err_free: 386 386 put_pid(ucontext->tgid); 387 - ibdev->dealloc_ucontext(ucontext); 387 + ib_dev->dealloc_ucontext(ucontext); 388 388 389 389 err: 390 390 mutex_unlock(&file->mutex); ··· 392 392 } 393 393 394 394 static void copy_query_dev_fields(struct ib_uverbs_file *file, 395 + struct ib_device *ib_dev, 395 396 struct ib_uverbs_query_device_resp *resp, 396 397 struct ib_device_attr *attr) 397 398 { 398 399 resp->fw_ver = attr->fw_ver; 399 - resp->node_guid = file->device->ib_dev->node_guid; 400 + resp->node_guid = ib_dev->node_guid; 400 401 resp->sys_image_guid = attr->sys_image_guid; 401 402 resp->max_mr_size = attr->max_mr_size; 402 403 resp->page_size_cap = attr->page_size_cap; ··· 435 434 resp->max_srq_sge = attr->max_srq_sge; 436 435 resp->max_pkeys = attr->max_pkeys; 437 436 resp->local_ca_ack_delay = attr->local_ca_ack_delay; 438 - resp->phys_port_cnt = file->device->ib_dev->phys_port_cnt; 437 + resp->phys_port_cnt = ib_dev->phys_port_cnt; 439 438 } 440 439 441 440 ssize_t ib_uverbs_query_device(struct ib_uverbs_file *file, 441 + struct ib_device *ib_dev, 442 442 const char __user *buf, 443 443 int in_len, int out_len) 444 444 { ··· 454 452 if (copy_from_user(&cmd, buf, sizeof cmd)) 455 453 return -EFAULT; 456 454 457 - ret = ib_query_device(file->device->ib_dev, &attr); 455 + ret = ib_query_device(ib_dev, &attr); 458 456 if (ret) 459 457 return ret; 460 458 461 459 memset(&resp, 0, sizeof resp); 462 - copy_query_dev_fields(file, &resp, &attr); 460 + copy_query_dev_fields(file, ib_dev, &resp, &attr); 463 461 464 462 if (copy_to_user((void __user *) (unsigned long) cmd.response, 465 463 &resp, sizeof resp)) ··· 469 467 } 470 468 471 469 ssize_t ib_uverbs_query_port(struct ib_uverbs_file *file, 470 + struct ib_device *ib_dev, 472 471 const char __user *buf, 473 472 int in_len, int out_len) 474 473 { ··· 484 481 if (copy_from_user(&cmd, buf, sizeof cmd)) 485 482 return -EFAULT; 486 483 487 - ret = ib_query_port(file->device->ib_dev, cmd.port_num, &attr); 484 + ret = ib_query_port(ib_dev, cmd.port_num, &attr); 488 485 if (ret) 489 486 return ret; 490 487 ··· 509 506 resp.active_width = attr.active_width; 510 507 resp.active_speed = attr.active_speed; 511 508 resp.phys_state = attr.phys_state; 512 - resp.link_layer = rdma_port_get_link_layer(file->device->ib_dev, 509 + resp.link_layer = rdma_port_get_link_layer(ib_dev, 513 510 cmd.port_num); 514 511 515 512 if (copy_to_user((void __user *) (unsigned long) cmd.response, ··· 520 517 } 521 518 522 519 ssize_t ib_uverbs_alloc_pd(struct ib_uverbs_file *file, 520 + struct ib_device *ib_dev, 523 521 const char __user *buf, 524 522 int in_len, int out_len) 525 523 { ··· 548 544 init_uobj(uobj, 0, file->ucontext, &pd_lock_class); 549 545 down_write(&uobj->mutex); 550 546 551 - pd = file->device->ib_dev->alloc_pd(file->device->ib_dev, 552 - file->ucontext, &udata); 547 + pd = ib_dev->alloc_pd(ib_dev, file->ucontext, &udata); 553 548 if (IS_ERR(pd)) { 554 549 ret = PTR_ERR(pd); 555 550 goto err; 556 551 } 557 552 558 - pd->device = file->device->ib_dev; 553 + pd->device = ib_dev; 559 554 pd->uobject = uobj; 560 555 pd->local_mr = NULL; 561 556 atomic_set(&pd->usecnt, 0); ··· 595 592 } 596 593 597 594 ssize_t ib_uverbs_dealloc_pd(struct ib_uverbs_file *file, 595 + struct ib_device *ib_dev, 598 596 const char __user *buf, 599 597 int in_len, int out_len) 600 598 { ··· 726 722 } 727 723 728 724 ssize_t ib_uverbs_open_xrcd(struct ib_uverbs_file *file, 725 + struct ib_device *ib_dev, 729 726 const char __user *buf, int in_len, 730 727 int out_len) 731 728 { ··· 785 780 down_write(&obj->uobject.mutex); 786 781 787 782 if (!xrcd) { 788 - xrcd = file->device->ib_dev->alloc_xrcd(file->device->ib_dev, 789 - file->ucontext, &udata); 783 + xrcd = ib_dev->alloc_xrcd(ib_dev, file->ucontext, &udata); 790 784 if (IS_ERR(xrcd)) { 791 785 ret = PTR_ERR(xrcd); 792 786 goto err; 793 787 } 794 788 795 789 xrcd->inode = inode; 796 - xrcd->device = file->device->ib_dev; 790 + xrcd->device = ib_dev; 797 791 atomic_set(&xrcd->usecnt, 0); 798 792 mutex_init(&xrcd->tgt_qp_mutex); 799 793 INIT_LIST_HEAD(&xrcd->tgt_qp_list); ··· 863 859 } 864 860 865 861 ssize_t ib_uverbs_close_xrcd(struct ib_uverbs_file *file, 862 + struct ib_device *ib_dev, 866 863 const char __user *buf, int in_len, 867 864 int out_len) 868 865 { ··· 941 936 } 942 937 943 938 ssize_t ib_uverbs_reg_mr(struct ib_uverbs_file *file, 939 + struct ib_device *ib_dev, 944 940 const char __user *buf, int in_len, 945 941 int out_len) 946 942 { ··· 1051 1045 } 1052 1046 1053 1047 ssize_t ib_uverbs_rereg_mr(struct ib_uverbs_file *file, 1048 + struct ib_device *ib_dev, 1054 1049 const char __user *buf, int in_len, 1055 1050 int out_len) 1056 1051 { ··· 1145 1138 } 1146 1139 1147 1140 ssize_t ib_uverbs_dereg_mr(struct ib_uverbs_file *file, 1141 + struct ib_device *ib_dev, 1148 1142 const char __user *buf, int in_len, 1149 1143 int out_len) 1150 1144 { ··· 1184 1176 } 1185 1177 1186 1178 ssize_t ib_uverbs_alloc_mw(struct ib_uverbs_file *file, 1187 - const char __user *buf, int in_len, 1188 - int out_len) 1179 + struct ib_device *ib_dev, 1180 + const char __user *buf, int in_len, 1181 + int out_len) 1189 1182 { 1190 1183 struct ib_uverbs_alloc_mw cmd; 1191 1184 struct ib_uverbs_alloc_mw_resp resp; ··· 1267 1258 } 1268 1259 1269 1260 ssize_t ib_uverbs_dealloc_mw(struct ib_uverbs_file *file, 1270 - const char __user *buf, int in_len, 1271 - int out_len) 1261 + struct ib_device *ib_dev, 1262 + const char __user *buf, int in_len, 1263 + int out_len) 1272 1264 { 1273 1265 struct ib_uverbs_dealloc_mw cmd; 1274 1266 struct ib_mw *mw; ··· 1306 1296 } 1307 1297 1308 1298 ssize_t ib_uverbs_create_comp_channel(struct ib_uverbs_file *file, 1299 + struct ib_device *ib_dev, 1309 1300 const char __user *buf, int in_len, 1310 1301 int out_len) 1311 1302 { ··· 1326 1315 return ret; 1327 1316 resp.fd = ret; 1328 1317 1329 - filp = ib_uverbs_alloc_event_file(file, 0); 1318 + filp = ib_uverbs_alloc_event_file(file, ib_dev, 0); 1330 1319 if (IS_ERR(filp)) { 1331 1320 put_unused_fd(resp.fd); 1332 1321 return PTR_ERR(filp); ··· 1344 1333 } 1345 1334 1346 1335 static struct ib_ucq_object *create_cq(struct ib_uverbs_file *file, 1336 + struct ib_device *ib_dev, 1347 1337 struct ib_udata *ucore, 1348 1338 struct ib_udata *uhw, 1349 1339 struct ib_uverbs_ex_create_cq *cmd, ··· 1393 1381 if (cmd_sz > offsetof(typeof(*cmd), flags) + sizeof(cmd->flags)) 1394 1382 attr.flags = cmd->flags; 1395 1383 1396 - cq = file->device->ib_dev->create_cq(file->device->ib_dev, &attr, 1384 + cq = ib_dev->create_cq(ib_dev, &attr, 1397 1385 file->ucontext, uhw); 1398 1386 if (IS_ERR(cq)) { 1399 1387 ret = PTR_ERR(cq); 1400 1388 goto err_file; 1401 1389 } 1402 1390 1403 - cq->device = file->device->ib_dev; 1391 + cq->device = ib_dev; 1404 1392 cq->uobject = &obj->uobject; 1405 1393 cq->comp_handler = ib_uverbs_comp_handler; 1406 1394 cq->event_handler = ib_uverbs_cq_event_handler; ··· 1461 1449 } 1462 1450 1463 1451 ssize_t ib_uverbs_create_cq(struct ib_uverbs_file *file, 1452 + struct ib_device *ib_dev, 1464 1453 const char __user *buf, int in_len, 1465 1454 int out_len) 1466 1455 { ··· 1490 1477 cmd_ex.comp_vector = cmd.comp_vector; 1491 1478 cmd_ex.comp_channel = cmd.comp_channel; 1492 1479 1493 - obj = create_cq(file, &ucore, &uhw, &cmd_ex, 1480 + obj = create_cq(file, ib_dev, &ucore, &uhw, &cmd_ex, 1494 1481 offsetof(typeof(cmd_ex), comp_channel) + 1495 1482 sizeof(cmd.comp_channel), ib_uverbs_create_cq_cb, 1496 1483 NULL); ··· 1513 1500 } 1514 1501 1515 1502 int ib_uverbs_ex_create_cq(struct ib_uverbs_file *file, 1503 + struct ib_device *ib_dev, 1516 1504 struct ib_udata *ucore, 1517 1505 struct ib_udata *uhw) 1518 1506 { ··· 1539 1525 sizeof(resp.response_length))) 1540 1526 return -ENOSPC; 1541 1527 1542 - obj = create_cq(file, ucore, uhw, &cmd, 1528 + obj = create_cq(file, ib_dev, ucore, uhw, &cmd, 1543 1529 min(ucore->inlen, sizeof(cmd)), 1544 1530 ib_uverbs_ex_create_cq_cb, NULL); 1545 1531 ··· 1550 1536 } 1551 1537 1552 1538 ssize_t ib_uverbs_resize_cq(struct ib_uverbs_file *file, 1539 + struct ib_device *ib_dev, 1553 1540 const char __user *buf, int in_len, 1554 1541 int out_len) 1555 1542 { ··· 1614 1599 } 1615 1600 1616 1601 ssize_t ib_uverbs_poll_cq(struct ib_uverbs_file *file, 1602 + struct ib_device *ib_dev, 1617 1603 const char __user *buf, int in_len, 1618 1604 int out_len) 1619 1605 { ··· 1666 1650 } 1667 1651 1668 1652 ssize_t ib_uverbs_req_notify_cq(struct ib_uverbs_file *file, 1653 + struct ib_device *ib_dev, 1669 1654 const char __user *buf, int in_len, 1670 1655 int out_len) 1671 1656 { ··· 1689 1672 } 1690 1673 1691 1674 ssize_t ib_uverbs_destroy_cq(struct ib_uverbs_file *file, 1675 + struct ib_device *ib_dev, 1692 1676 const char __user *buf, int in_len, 1693 1677 int out_len) 1694 1678 { ··· 1742 1724 } 1743 1725 1744 1726 ssize_t ib_uverbs_create_qp(struct ib_uverbs_file *file, 1727 + struct ib_device *ib_dev, 1745 1728 const char __user *buf, int in_len, 1746 1729 int out_len) 1747 1730 { ··· 1938 1919 } 1939 1920 1940 1921 ssize_t ib_uverbs_open_qp(struct ib_uverbs_file *file, 1922 + struct ib_device *ib_dev, 1941 1923 const char __user *buf, int in_len, int out_len) 1942 1924 { 1943 1925 struct ib_uverbs_open_qp cmd; ··· 2033 2013 } 2034 2014 2035 2015 ssize_t ib_uverbs_query_qp(struct ib_uverbs_file *file, 2016 + struct ib_device *ib_dev, 2036 2017 const char __user *buf, int in_len, 2037 2018 int out_len) 2038 2019 { ··· 2148 2127 } 2149 2128 2150 2129 ssize_t ib_uverbs_modify_qp(struct ib_uverbs_file *file, 2130 + struct ib_device *ib_dev, 2151 2131 const char __user *buf, int in_len, 2152 2132 int out_len) 2153 2133 { ··· 2245 2223 } 2246 2224 2247 2225 ssize_t ib_uverbs_destroy_qp(struct ib_uverbs_file *file, 2226 + struct ib_device *ib_dev, 2248 2227 const char __user *buf, int in_len, 2249 2228 int out_len) 2250 2229 { ··· 2304 2281 } 2305 2282 2306 2283 ssize_t ib_uverbs_post_send(struct ib_uverbs_file *file, 2284 + struct ib_device *ib_dev, 2307 2285 const char __user *buf, int in_len, 2308 2286 int out_len) 2309 2287 { ··· 2549 2525 } 2550 2526 2551 2527 ssize_t ib_uverbs_post_recv(struct ib_uverbs_file *file, 2528 + struct ib_device *ib_dev, 2552 2529 const char __user *buf, int in_len, 2553 2530 int out_len) 2554 2531 { ··· 2599 2574 } 2600 2575 2601 2576 ssize_t ib_uverbs_post_srq_recv(struct ib_uverbs_file *file, 2577 + struct ib_device *ib_dev, 2602 2578 const char __user *buf, int in_len, 2603 2579 int out_len) 2604 2580 { ··· 2649 2623 } 2650 2624 2651 2625 ssize_t ib_uverbs_create_ah(struct ib_uverbs_file *file, 2626 + struct ib_device *ib_dev, 2652 2627 const char __user *buf, int in_len, 2653 2628 int out_len) 2654 2629 { ··· 2742 2715 } 2743 2716 2744 2717 ssize_t ib_uverbs_destroy_ah(struct ib_uverbs_file *file, 2718 + struct ib_device *ib_dev, 2745 2719 const char __user *buf, int in_len, int out_len) 2746 2720 { 2747 2721 struct ib_uverbs_destroy_ah cmd; ··· 2779 2751 } 2780 2752 2781 2753 ssize_t ib_uverbs_attach_mcast(struct ib_uverbs_file *file, 2754 + struct ib_device *ib_dev, 2782 2755 const char __user *buf, int in_len, 2783 2756 int out_len) 2784 2757 { ··· 2827 2798 } 2828 2799 2829 2800 ssize_t ib_uverbs_detach_mcast(struct ib_uverbs_file *file, 2801 + struct ib_device *ib_dev, 2830 2802 const char __user *buf, int in_len, 2831 2803 int out_len) 2832 2804 { ··· 2908 2878 } 2909 2879 2910 2880 int ib_uverbs_ex_create_flow(struct ib_uverbs_file *file, 2881 + struct ib_device *ib_dev, 2911 2882 struct ib_udata *ucore, 2912 2883 struct ib_udata *uhw) 2913 2884 { ··· 3069 3038 } 3070 3039 3071 3040 int ib_uverbs_ex_destroy_flow(struct ib_uverbs_file *file, 3041 + struct ib_device *ib_dev, 3072 3042 struct ib_udata *ucore, 3073 3043 struct ib_udata *uhw) 3074 3044 { ··· 3112 3080 } 3113 3081 3114 3082 static int __uverbs_create_xsrq(struct ib_uverbs_file *file, 3083 + struct ib_device *ib_dev, 3115 3084 struct ib_uverbs_create_xsrq *cmd, 3116 3085 struct ib_udata *udata) 3117 3086 { ··· 3246 3213 } 3247 3214 3248 3215 ssize_t ib_uverbs_create_srq(struct ib_uverbs_file *file, 3216 + struct ib_device *ib_dev, 3249 3217 const char __user *buf, int in_len, 3250 3218 int out_len) 3251 3219 { ··· 3274 3240 (unsigned long) cmd.response + sizeof resp, 3275 3241 in_len - sizeof cmd, out_len - sizeof resp); 3276 3242 3277 - ret = __uverbs_create_xsrq(file, &xcmd, &udata); 3243 + ret = __uverbs_create_xsrq(file, ib_dev, &xcmd, &udata); 3278 3244 if (ret) 3279 3245 return ret; 3280 3246 ··· 3282 3248 } 3283 3249 3284 3250 ssize_t ib_uverbs_create_xsrq(struct ib_uverbs_file *file, 3251 + struct ib_device *ib_dev, 3285 3252 const char __user *buf, int in_len, int out_len) 3286 3253 { 3287 3254 struct ib_uverbs_create_xsrq cmd; ··· 3300 3265 (unsigned long) cmd.response + sizeof resp, 3301 3266 in_len - sizeof cmd, out_len - sizeof resp); 3302 3267 3303 - ret = __uverbs_create_xsrq(file, &cmd, &udata); 3268 + ret = __uverbs_create_xsrq(file, ib_dev, &cmd, &udata); 3304 3269 if (ret) 3305 3270 return ret; 3306 3271 ··· 3308 3273 } 3309 3274 3310 3275 ssize_t ib_uverbs_modify_srq(struct ib_uverbs_file *file, 3276 + struct ib_device *ib_dev, 3311 3277 const char __user *buf, int in_len, 3312 3278 int out_len) 3313 3279 { ··· 3339 3303 } 3340 3304 3341 3305 ssize_t ib_uverbs_query_srq(struct ib_uverbs_file *file, 3306 + struct ib_device *ib_dev, 3342 3307 const char __user *buf, 3343 3308 int in_len, int out_len) 3344 3309 { ··· 3380 3343 } 3381 3344 3382 3345 ssize_t ib_uverbs_destroy_srq(struct ib_uverbs_file *file, 3346 + struct ib_device *ib_dev, 3383 3347 const char __user *buf, int in_len, 3384 3348 int out_len) 3385 3349 { ··· 3438 3400 } 3439 3401 3440 3402 int ib_uverbs_ex_query_device(struct ib_uverbs_file *file, 3403 + struct ib_device *ib_dev, 3441 3404 struct ib_udata *ucore, 3442 3405 struct ib_udata *uhw) 3443 3406 { 3444 3407 struct ib_uverbs_ex_query_device_resp resp; 3445 3408 struct ib_uverbs_ex_query_device cmd; 3446 3409 struct ib_device_attr attr; 3447 - struct ib_device *device; 3448 3410 int err; 3449 3411 3450 - device = file->device->ib_dev; 3451 3412 if (ucore->inlen < sizeof(cmd)) 3452 3413 return -EINVAL; 3453 3414 ··· 3467 3430 3468 3431 memset(&attr, 0, sizeof(attr)); 3469 3432 3470 - err = device->query_device(device, &attr, uhw); 3433 + err = ib_dev->query_device(ib_dev, &attr, uhw); 3471 3434 if (err) 3472 3435 return err; 3473 3436 3474 - copy_query_dev_fields(file, &resp.base, &attr); 3437 + copy_query_dev_fields(file, ib_dev, &resp.base, &attr); 3475 3438 resp.comp_mask = 0; 3476 3439 3477 3440 if (ucore->outlen < resp.response_length + sizeof(resp.odp_caps))
+15 -6
drivers/infiniband/core/uverbs_main.c
··· 79 79 static DECLARE_BITMAP(dev_map, IB_UVERBS_MAX_DEVICES); 80 80 81 81 static ssize_t (*uverbs_cmd_table[])(struct ib_uverbs_file *file, 82 + struct ib_device *ib_dev, 82 83 const char __user *buf, int in_len, 83 84 int out_len) = { 84 85 [IB_USER_VERBS_CMD_GET_CONTEXT] = ib_uverbs_get_context, ··· 120 119 }; 121 120 122 121 static int (*uverbs_ex_cmd_table[])(struct ib_uverbs_file *file, 122 + struct ib_device *ib_dev, 123 123 struct ib_udata *ucore, 124 124 struct ib_udata *uhw) = { 125 125 [IB_USER_VERBS_EX_CMD_CREATE_FLOW] = ib_uverbs_ex_create_flow, ··· 559 557 } 560 558 561 559 struct file *ib_uverbs_alloc_event_file(struct ib_uverbs_file *uverbs_file, 560 + struct ib_device *ib_dev, 562 561 int is_async) 563 562 { 564 563 struct ib_uverbs_event_file *ev_file; ··· 589 586 uverbs_file->async_file = ev_file; 590 587 kref_get(&uverbs_file->async_file->ref); 591 588 INIT_IB_EVENT_HANDLER(&uverbs_file->event_handler, 592 - uverbs_file->device->ib_dev, 589 + ib_dev, 593 590 ib_uverbs_event_handler); 594 591 ret = ib_register_event_handler(&uverbs_file->event_handler); 595 592 if (ret) ··· 646 643 size_t count, loff_t *pos) 647 644 { 648 645 struct ib_uverbs_file *file = filp->private_data; 646 + struct ib_device *ib_dev = file->device->ib_dev; 649 647 struct ib_uverbs_cmd_hdr hdr; 650 648 __u32 flags; 649 + 650 + if (!ib_dev) 651 + return -ENODEV; 651 652 652 653 if (count < sizeof hdr) 653 654 return -EINVAL; ··· 679 672 command != IB_USER_VERBS_CMD_GET_CONTEXT) 680 673 return -EINVAL; 681 674 682 - if (!(file->device->ib_dev->uverbs_cmd_mask & (1ull << command))) 675 + if (!(ib_dev->uverbs_cmd_mask & (1ull << command))) 683 676 return -ENOSYS; 684 677 685 678 if (hdr.in_words * 4 != count) 686 679 return -EINVAL; 687 680 688 - return uverbs_cmd_table[command](file, 681 + return uverbs_cmd_table[command](file, ib_dev, 689 682 buf + sizeof(hdr), 690 683 hdr.in_words * 4, 691 684 hdr.out_words * 4); ··· 712 705 if (!file->ucontext) 713 706 return -EINVAL; 714 707 715 - if (!(file->device->ib_dev->uverbs_ex_cmd_mask & (1ull << command))) 708 + if (!(ib_dev->uverbs_ex_cmd_mask & (1ull << command))) 716 709 return -ENOSYS; 717 710 718 711 if (count < (sizeof(hdr) + sizeof(ex_hdr))) ··· 753 746 ex_hdr.provider_out_words * 8); 754 747 755 748 err = uverbs_ex_cmd_table[command](file, 749 + ib_dev, 756 750 &ucore, 757 751 &uhw); 758 752 ··· 769 761 static int ib_uverbs_mmap(struct file *filp, struct vm_area_struct *vma) 770 762 { 771 763 struct ib_uverbs_file *file = filp->private_data; 764 + struct ib_device *ib_dev = file->device->ib_dev; 772 765 773 - if (!file->ucontext) 766 + if (!ib_dev || !file->ucontext) 774 767 return -ENODEV; 775 768 else 776 - return file->device->ib_dev->mmap(file->ucontext, vma); 769 + return ib_dev->mmap(file->ucontext, vma); 777 770 } 778 771 779 772 /*