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

Configure Feed

Select the types of activity you want to include in your feed.

dibs: Move struct device to dibs_dev

Move struct device from ism_dev and smc_lo_dev to dibs_dev, and define a
corresponding release function. Free ism_dev in ism_remove() and smc_lo_dev
in smc_lo_dev_remove().

Replace smcd->ops->get_dev(smcd) by using dibs->dev directly.

An alternative design would be to embed dibs_dev as a field in ism_dev and
do the same for other dibs device driver specific structs. However that
would have the disadvantage that each dibs device driver needs to allocate
dibs_dev and each dibs device driver needs a different device release
function. The advantage would be that ism_dev and other device driver
specific structs would be covered by device reference counts.

Signed-off-by: Julian Ruess <julianr@linux.ibm.com>
Co-developed-by: Alexandra Winter <wintera@linux.ibm.com>
Signed-off-by: Alexandra Winter <wintera@linux.ibm.com>
Reviewed-by: Mahanta Jambigi <mjambigi@linux.ibm.com>
Link: https://patch.msgid.link/20250918110500.1731261-9-wintera@linux.ibm.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

authored by

Julian Ruess and committed by
Paolo Abeni
845c334a 69baaac9

+63 -101
+7 -8
drivers/dibs/dibs_loopback.c
··· 15 15 16 16 #include "dibs_loopback.h" 17 17 18 + static const char dibs_lo_dev_name[] = "lo"; 18 19 /* global loopback device */ 19 20 static struct dibs_lo_dev *lo_dev; 20 21 ··· 27 26 static const struct dibs_dev_ops dibs_lo_ops = { 28 27 .get_fabric_id = dibs_lo_get_fabric_id, 29 28 }; 30 - 31 - static void dibs_lo_dev_exit(struct dibs_lo_dev *ldev) 32 - { 33 - dibs_dev_del(ldev->dibs); 34 - } 35 29 36 30 static int dibs_lo_dev_probe(void) 37 31 { ··· 48 52 dibs->drv_priv = ldev; 49 53 dibs->ops = &dibs_lo_ops; 50 54 55 + dibs->dev.parent = NULL; 56 + dev_set_name(&dibs->dev, "%s", dibs_lo_dev_name); 57 + 51 58 ret = dibs_dev_add(dibs); 52 59 if (ret) 53 60 goto err_reg; ··· 59 60 60 61 err_reg: 61 62 /* pairs with dibs_dev_alloc() */ 62 - kfree(dibs); 63 + put_device(&dibs->dev); 63 64 kfree(ldev); 64 65 65 66 return ret; ··· 70 71 if (!lo_dev) 71 72 return; 72 73 73 - dibs_lo_dev_exit(lo_dev); 74 + dibs_dev_del(lo_dev->dibs); 74 75 /* pairs with dibs_dev_alloc() */ 75 - kfree(lo_dev->dibs); 76 + put_device(&lo_dev->dibs->dev); 76 77 kfree(lo_dev); 77 78 lo_dev = NULL; 78 79 }
+20 -1
drivers/dibs/dibs_main.c
··· 88 88 } 89 89 EXPORT_SYMBOL_GPL(dibs_unregister_client); 90 90 91 + static void dibs_dev_release(struct device *dev) 92 + { 93 + struct dibs_dev *dibs; 94 + 95 + dibs = container_of(dev, struct dibs_dev, dev); 96 + 97 + kfree(dibs); 98 + } 99 + 91 100 struct dibs_dev *dibs_dev_alloc(void) 92 101 { 93 102 struct dibs_dev *dibs; 94 103 95 104 dibs = kzalloc(sizeof(*dibs), GFP_KERNEL); 105 + if (!dibs) 106 + return dibs; 107 + dibs->dev.release = dibs_dev_release; 108 + device_initialize(&dibs->dev); 96 109 97 110 return dibs; 98 111 } ··· 113 100 114 101 int dibs_dev_add(struct dibs_dev *dibs) 115 102 { 116 - int i; 103 + int i, ret; 104 + 105 + ret = device_add(&dibs->dev); 106 + if (ret) 107 + return ret; 117 108 118 109 mutex_lock(&dibs_dev_list.mutex); 119 110 mutex_lock(&clients_lock); ··· 146 129 mutex_unlock(&clients_lock); 147 130 list_del_init(&dibs->list); 148 131 mutex_unlock(&dibs_dev_list.mutex); 132 + 133 + device_del(&dibs->dev); 149 134 } 150 135 EXPORT_SYMBOL_GPL(dibs_dev_del); 151 136
+8 -32
drivers/s390/net/ism_drv.c
··· 602 602 return ret; 603 603 } 604 604 605 - static void ism_dev_release(struct device *dev) 606 - { 607 - struct ism_dev *ism; 608 - 609 - ism = container_of(dev, struct ism_dev, dev); 610 - 611 - kfree(ism); 612 - } 613 - 614 605 static void ism_dev_exit(struct ism_dev *ism) 615 606 { 616 607 struct pci_dev *pdev = ism->pdev; ··· 640 649 spin_lock_init(&ism->cmd_lock); 641 650 dev_set_drvdata(&pdev->dev, ism); 642 651 ism->pdev = pdev; 643 - ism->dev.parent = &pdev->dev; 644 - ism->dev.release = ism_dev_release; 645 - device_initialize(&ism->dev); 646 - dev_set_name(&ism->dev, "%s", dev_name(&pdev->dev)); 647 - ret = device_add(&ism->dev); 648 - if (ret) 649 - goto err_dev; 650 652 651 653 ret = pci_enable_device_mem(pdev); 652 654 if (ret) 653 - goto err; 655 + goto err_dev; 654 656 655 657 ret = pci_request_mem_regions(pdev, DRV_NAME); 656 658 if (ret) ··· 671 687 if (ret) 672 688 goto err_dibs; 673 689 690 + dibs->dev.parent = &pdev->dev; 691 + dev_set_name(&dibs->dev, "%s", dev_name(&pdev->dev)); 692 + 674 693 ret = dibs_dev_add(dibs); 675 694 if (ret) 676 695 goto err_ism; ··· 684 697 ism_dev_exit(ism); 685 698 err_dibs: 686 699 /* pairs with dibs_dev_alloc() */ 687 - kfree(dibs); 700 + put_device(&dibs->dev); 688 701 err_resource: 689 702 pci_release_mem_regions(pdev); 690 703 err_disable: 691 704 pci_disable_device(pdev); 692 - err: 693 - device_del(&ism->dev); 694 705 err_dev: 695 706 dev_set_drvdata(&pdev->dev, NULL); 696 - put_device(&ism->dev); 707 + kfree(ism); 697 708 698 709 return ret; 699 710 } ··· 704 719 dibs_dev_del(dibs); 705 720 ism_dev_exit(ism); 706 721 /* pairs with dibs_dev_alloc() */ 707 - kfree(dibs); 722 + put_device(&dibs->dev); 708 723 709 724 pci_release_mem_regions(pdev); 710 725 pci_disable_device(pdev); 711 - device_del(&ism->dev); 712 726 dev_set_drvdata(&pdev->dev, NULL); 713 - put_device(&ism->dev); 727 + kfree(ism); 714 728 } 715 729 716 730 static struct pci_driver ism_driver = { ··· 850 866 smcd_gid->gid_ext = 0; 851 867 } 852 868 853 - static inline struct device *smcd_get_dev(struct smcd_dev *dev) 854 - { 855 - struct ism_dev *ism = dev->priv; 856 - 857 - return &ism->dev; 858 - } 859 - 860 869 static const struct smcd_ops ism_smcd_ops = { 861 870 .query_remote_gid = smcd_query_rgid, 862 871 .register_dmb = smcd_register_dmb, ··· 862 885 .move_data = smcd_move, 863 886 .supports_v2 = smcd_supports_v2, 864 887 .get_local_gid = smcd_get_local_gid, 865 - .get_dev = smcd_get_dev, 866 888 }; 867 889 868 890 const struct smcd_ops *ism_get_smcd_ops(void)
+1
include/linux/dibs.h
··· 135 135 136 136 struct dibs_dev { 137 137 struct list_head list; 138 + struct device dev; 138 139 /* To be filled by device driver, before calling dibs_dev_add(): */ 139 140 const struct dibs_dev_ops *ops; 140 141 /* priv pointer for device driver */
-1
include/linux/ism.h
··· 42 42 struct ism_eq *ieq; 43 43 dma_addr_t ieq_dma_addr; 44 44 45 - struct device dev; 46 45 u64 local_gid; 47 46 int ieq_idx; 48 47
-1
include/net/smc.h
··· 63 63 unsigned int size); 64 64 int (*supports_v2)(void); 65 65 void (*get_local_gid)(struct smcd_dev *dev, struct smcd_gid *gid); 66 - struct device* (*get_dev)(struct smcd_dev *dev); 67 66 68 67 /* optional operations */ 69 68 int (*add_vlan_id)(struct smcd_dev *dev, u64 vlan_id);
+2 -2
net/smc/smc_core.c
··· 924 924 if (ini->is_smcd) { 925 925 /* SMC-D specific settings */ 926 926 smcd = ini->ism_dev[ini->ism_selected]; 927 - get_device(smcd->ops->get_dev(smcd)); 927 + get_device(&smcd->dibs->dev); 928 928 lgr->peer_gid.gid = 929 929 ini->ism_peer_gid[ini->ism_selected].gid; 930 930 lgr->peer_gid.gid_ext = ··· 1474 1474 destroy_workqueue(lgr->tx_wq); 1475 1475 if (lgr->is_smcd) { 1476 1476 smc_ism_put_vlan(lgr->smcd, lgr->vlan_id); 1477 - put_device(lgr->smcd->ops->get_dev(lgr->smcd)); 1477 + put_device(&lgr->smcd->dibs->dev); 1478 1478 } 1479 1479 smc_lgr_put(lgr); /* theoretically last lgr_put */ 1480 1480 }
+19 -27
net/smc/smc_ism.c
··· 303 303 char smc_pnet[SMC_MAX_PNETID_LEN + 1]; 304 304 struct smc_pci_dev smc_pci_dev; 305 305 struct nlattr *port_attrs; 306 + struct dibs_dev *dibs; 306 307 struct nlattr *attrs; 307 - struct ism_dev *ism; 308 308 int use_cnt = 0; 309 309 void *nlh; 310 310 311 - ism = smcd->priv; 311 + dibs = smcd->dibs; 312 312 nlh = genlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq, 313 313 &smc_gen_nl_family, NLM_F_MULTI, 314 314 SMC_NETLINK_GET_DEV_SMCD); ··· 323 323 if (nla_put_u8(skb, SMC_NLA_DEV_IS_CRIT, use_cnt > 0)) 324 324 goto errattr; 325 325 memset(&smc_pci_dev, 0, sizeof(smc_pci_dev)); 326 - smc_set_pci_values(ism->pdev, &smc_pci_dev); 326 + smc_set_pci_values(to_pci_dev(dibs->dev.parent), &smc_pci_dev); 327 327 if (nla_put_u32(skb, SMC_NLA_DEV_PCI_FID, smc_pci_dev.pci_fid)) 328 328 goto errattr; 329 329 if (nla_put_u16(skb, SMC_NLA_DEV_PCI_CHID, smc_pci_dev.pci_pchid)) ··· 509 509 510 510 if (smc_ism_is_loopback(dibs)) { 511 511 ops = smc_lo_get_smcd_ops(); 512 - smcd = smcd_alloc_dev(dev_name(&smc_lo->dev), ops, 512 + smcd = smcd_alloc_dev(dev_name(&dibs->dev), ops, 513 513 SMC_LO_MAX_DMBS); 514 514 } else { 515 515 ism = dibs->drv_priv; 516 516 #if IS_ENABLED(CONFIG_ISM) 517 517 ops = ism_get_smcd_ops(); 518 518 #endif 519 - smcd = smcd_alloc_dev(dev_name(&ism->pdev->dev), ops, 519 + smcd = smcd_alloc_dev(dev_name(&dibs->dev), ops, 520 520 ISM_NR_DMBS); 521 521 } 522 522 if (!smcd) ··· 534 534 ism_set_priv(ism, &smc_ism_client, smcd); 535 535 smcd->client = &smc_ism_client; 536 536 #endif 537 - if (smc_pnetid_by_dev_port(&ism->pdev->dev, 0, smcd->pnetid)) 538 - smc_pnetid_by_table_smcd(smcd); 539 537 } 538 + 539 + if (smc_pnetid_by_dev_port(dibs->dev.parent, 0, smcd->pnetid)) 540 + smc_pnetid_by_table_smcd(smcd); 540 541 541 542 if (smc_ism_is_loopback(dibs) || smcd->ops->supports_v2()) 542 543 smc_ism_set_v2_capable(); ··· 558 557 } 559 558 mutex_unlock(&smcd_dev_list.mutex); 560 559 561 - if (smc_ism_is_loopback(dibs)) { 562 - pr_warn_ratelimited("smc: adding smcd loopback device\n"); 563 - } else { 564 - if (smc_pnet_is_pnetid_set(smcd->pnetid)) 565 - pr_warn_ratelimited("smc: adding smcd device %s with pnetid %.16s%s\n", 566 - dev_name(&ism->dev), smcd->pnetid, 567 - smcd->pnetid_by_user ? 568 - " (user defined)" : 569 - ""); 570 - else 571 - pr_warn_ratelimited("smc: adding smcd device %s without pnetid\n", 572 - dev_name(&ism->dev)); 573 - } 560 + if (smc_pnet_is_pnetid_set(smcd->pnetid)) 561 + pr_warn_ratelimited("smc: adding smcd device %s with pnetid %.16s%s\n", 562 + dev_name(&dibs->dev), smcd->pnetid, 563 + smcd->pnetid_by_user ? 564 + " (user defined)" : 565 + ""); 566 + else 567 + pr_warn_ratelimited("smc: adding smcd device %s without pnetid\n", 568 + dev_name(&dibs->dev)); 574 569 return; 575 570 } 576 571 577 572 static void smcd_unregister_dev(struct dibs_dev *dibs) 578 573 { 579 574 struct smcd_dev *smcd = dibs_get_priv(dibs, &smc_dibs_client); 580 - struct ism_dev *ism = dibs->drv_priv; 581 575 582 - if (smc_ism_is_loopback(dibs)) { 583 - pr_warn_ratelimited("smc: removing smcd loopback device\n"); 584 - } else { 585 - pr_warn_ratelimited("smc: removing smcd device %s\n", 586 - dev_name(&ism->dev)); 587 - } 576 + pr_warn_ratelimited("smc: removing smcd device %s\n", 577 + dev_name(&dibs->dev)); 588 578 smcd->going_away = 1; 589 579 smc_smcd_terminate_all(smcd); 590 580 mutex_lock(&smcd_dev_list.mutex);
+1 -20
net/smc/smc_loopback.c
··· 23 23 #define SMC_LO_SUPPORT_NOCOPY 0x1 24 24 #define SMC_DMA_ADDR_INVALID (~(dma_addr_t)0) 25 25 26 - static const char smc_lo_dev_name[] = "loopback-ism"; 27 26 static struct smc_lo_dev *lo_dev; 28 27 29 28 static void smc_lo_generate_ids(struct smc_lo_dev *ldev) ··· 254 255 smcd_gid->gid_ext = ldev->local_gid.gid_ext; 255 256 } 256 257 257 - static struct device *smc_lo_get_dev(struct smcd_dev *smcd) 258 - { 259 - return &((struct smc_lo_dev *)smcd->priv)->dev; 260 - } 261 - 262 258 static const struct smcd_ops lo_ops = { 263 259 .query_remote_gid = smc_lo_query_rgid, 264 260 .register_dmb = smc_lo_register_dmb, ··· 268 274 .signal_event = NULL, 269 275 .move_data = smc_lo_move_data, 270 276 .get_local_gid = smc_lo_get_local_gid, 271 - .get_dev = smc_lo_get_dev, 272 277 }; 273 278 274 279 const struct smcd_ops *smc_lo_get_smcd_ops(void) ··· 292 299 wait_event(ldev->ldev_release, !atomic_read(&ldev->dmb_cnt)); 293 300 } 294 301 295 - static void smc_lo_dev_release(struct device *dev) 296 - { 297 - struct smc_lo_dev *ldev = 298 - container_of(dev, struct smc_lo_dev, dev); 299 - 300 - kfree(ldev); 301 - } 302 - 303 302 static int smc_lo_dev_probe(void) 304 303 { 305 304 struct smc_lo_dev *ldev; ··· 300 315 if (!ldev) 301 316 return -ENOMEM; 302 317 303 - ldev->dev.parent = NULL; 304 - ldev->dev.release = smc_lo_dev_release; 305 - device_initialize(&ldev->dev); 306 - dev_set_name(&ldev->dev, smc_lo_dev_name); 307 318 smc_lo_dev_init(ldev); 308 319 309 320 lo_dev = ldev; /* global loopback device */ ··· 313 332 return; 314 333 315 334 smc_lo_dev_exit(lo_dev); 316 - put_device(&lo_dev->dev); /* device_initialize in smc_lo_dev_probe */ 335 + kfree(lo_dev); 317 336 lo_dev = NULL; 318 337 } 319 338
-1
net/smc/smc_loopback.h
··· 32 32 33 33 struct smc_lo_dev { 34 34 struct smcd_dev *smcd; 35 - struct device dev; 36 35 struct smcd_gid local_gid; 37 36 atomic_t dmb_cnt; 38 37 rwlock_t dmb_ht_lock;
+5 -8
net/smc/smc_pnet.c
··· 169 169 pr_warn_ratelimited("smc: smcd device %s " 170 170 "erased user defined pnetid " 171 171 "%.16s\n", 172 - dev_name(smcd->ops->get_dev(smcd)), 172 + dev_name(&smcd->dibs->dev), 173 173 smcd->pnetid); 174 174 memset(smcd->pnetid, 0, SMC_MAX_PNETID_LEN); 175 175 smcd->pnetid_by_user = false; ··· 332 332 333 333 mutex_lock(&smcd_dev_list.mutex); 334 334 list_for_each_entry(smcd_dev, &smcd_dev_list.list, list) { 335 - if (!strncmp(dev_name(smcd_dev->ops->get_dev(smcd_dev)), 335 + if (!strncmp(dev_name(&smcd_dev->dibs->dev), 336 336 smcd_name, IB_DEVICE_NAME_MAX - 1)) 337 337 goto out; 338 338 } ··· 413 413 bool smcddev_applied = true; 414 414 bool ibdev_applied = true; 415 415 struct smcd_dev *smcd; 416 - struct device *dev; 417 416 bool new_ibdev; 418 417 419 418 /* try to apply the pnetid to active devices */ ··· 430 431 if (smcd) { 431 432 smcddev_applied = smc_pnet_apply_smcd(smcd, pnet_name); 432 433 if (smcddev_applied) { 433 - dev = smcd->ops->get_dev(smcd); 434 - pr_warn_ratelimited("smc: smcd device %s " 435 - "applied user defined pnetid " 436 - "%.16s\n", dev_name(dev), 434 + pr_warn_ratelimited("smc: smcd device %s applied user defined pnetid %.16s\n", 435 + dev_name(&smcd->dibs->dev), 437 436 smcd->pnetid); 438 437 } 439 438 } ··· 1190 1193 */ 1191 1194 int smc_pnetid_by_table_smcd(struct smcd_dev *smcddev) 1192 1195 { 1193 - const char *ib_name = dev_name(smcddev->ops->get_dev(smcddev)); 1196 + const char *ib_name = dev_name(&smcddev->dibs->dev); 1194 1197 struct smc_pnettable *pnettable; 1195 1198 struct smc_pnetentry *tmp_pe; 1196 1199 struct smc_net *sn;