Date: Sun, 13 Mar 2011 21:51:47 +0000 (UTC) From: Jeff Roberson <jeff@FreeBSD.org> To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r219625 - in projects/ofed/head/sys/ofed: drivers/infiniband/core include/linux include/net Message-ID: <201103132151.p2DLplTY066942@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: jeff Date: Sun Mar 13 21:51:47 2011 New Revision: 219625 URL: http://svn.freebsd.org/changeset/base/219625 Log: - Fix several object reference leaks that prevent module unloading. - Acquire and release Giant in the right places for devclass. - Don't include opt_inet6.h in module builds. - Fix missing dev_t assignment in the cdev code. - Add kobject types for cdevs. Modified: projects/ofed/head/sys/ofed/drivers/infiniband/core/sysfs.c projects/ofed/head/sys/ofed/drivers/infiniband/core/uverbs_main.c projects/ofed/head/sys/ofed/include/linux/cdev.h projects/ofed/head/sys/ofed/include/linux/device.h projects/ofed/head/sys/ofed/include/linux/in6.h projects/ofed/head/sys/ofed/include/linux/list.h projects/ofed/head/sys/ofed/include/linux/pci.h projects/ofed/head/sys/ofed/include/net/ipv6.h Modified: projects/ofed/head/sys/ofed/drivers/infiniband/core/sysfs.c ============================================================================== --- projects/ofed/head/sys/ofed/drivers/infiniband/core/sysfs.c Sun Mar 13 21:23:25 2011 (r219624) +++ projects/ofed/head/sys/ofed/drivers/infiniband/core/sysfs.c Sun Mar 13 21:51:47 2011 (r219625) @@ -522,7 +522,7 @@ static int add_port(struct ib_device *de p->port_num = port_num; ret = kobject_init_and_add(&p->kobj, &port_type, - kobject_get(device->ports_parent), + device->ports_parent, "%d", port_num); if (ret) goto err_put; @@ -810,7 +810,7 @@ int ib_device_register_sysfs(struct ib_d } device->ports_parent = kobject_create_and_add("ports", - kobject_get(&class_dev->kobj)); + &class_dev->kobj); if (!device->ports_parent) { ret = -ENOMEM; goto err_put; Modified: projects/ofed/head/sys/ofed/drivers/infiniband/core/uverbs_main.c ============================================================================== --- projects/ofed/head/sys/ofed/drivers/infiniband/core/uverbs_main.c Sun Mar 13 21:23:25 2011 (r219624) +++ projects/ofed/head/sys/ofed/drivers/infiniband/core/uverbs_main.c Sun Mar 13 21:51:47 2011 (r219625) @@ -891,6 +891,7 @@ static void ib_uverbs_remove_one(struct if (!uverbs_dev) return; + sysfs_remove_group(&uverbs_dev->dev->kobj, &device_group); dev_set_drvdata(uverbs_dev->dev, NULL); device_destroy(uverbs_class, uverbs_dev->cdev->dev); cdev_del(uverbs_dev->cdev); Modified: projects/ofed/head/sys/ofed/include/linux/cdev.h ============================================================================== --- projects/ofed/head/sys/ofed/include/linux/cdev.h Sun Mar 13 21:23:25 2011 (r219624) +++ projects/ofed/head/sys/ofed/include/linux/cdev.h Sun Mar 13 21:51:47 2011 (r219625) @@ -48,10 +48,39 @@ struct linux_cdev { }; static inline void +cdev_release(struct kobject *kobj) +{ + struct linux_cdev *cdev; + + cdev = container_of(kobj, struct linux_cdev, kobj); + if (cdev->cdev) + destroy_dev(cdev->cdev); + kfree(cdev); +} + +static inline void +cdev_static_release(struct kobject *kobj) +{ + struct linux_cdev *cdev; + + cdev = container_of(kobj, struct linux_cdev, kobj); + if (cdev->cdev) + destroy_dev(cdev->cdev); +} + +static struct kobj_type cdev_ktype = { + .release = cdev_release, +}; + +static struct kobj_type cdev_static_ktype = { + .release = cdev_static_release, +}; + +static inline void cdev_init(struct linux_cdev *cdev, const struct file_operations *ops) { - kobject_init(&cdev->kobj, NULL); + kobject_init(&cdev->kobj, &cdev_static_ktype); cdev->ops = ops; } @@ -60,10 +89,9 @@ cdev_alloc(void) { struct linux_cdev *cdev; - /* XXX Need cdev_ktype */ cdev = kzalloc(sizeof(struct linux_cdev), M_WAITOK); if (cdev) - kobject_init(&cdev->kobj, NULL); + kobject_init(&cdev->kobj, &cdev_ktype); return (cdev); } @@ -80,6 +108,7 @@ cdev_add(struct linux_cdev *cdev, dev_t panic("cdev_add: Unsupported count: %d", count); cdev->cdev = make_dev(&linuxcdevsw, MINOR(dev), 0, 0, 0700, kobject_name(&cdev->kobj)); + cdev->dev = dev; cdev->cdev->si_drv1 = cdev; return (0); @@ -88,10 +117,11 @@ cdev_add(struct linux_cdev *cdev, dev_t static inline void cdev_del(struct linux_cdev *cdev) { - if (cdev->cdev) + if (cdev->cdev) { destroy_dev(cdev->cdev); + cdev->cdev = NULL; + } kobject_put(&cdev->kobj); - kfree(cdev); /* XXX ref cnt */ } #define cdev linux_cdev Modified: projects/ofed/head/sys/ofed/include/linux/device.h ============================================================================== --- projects/ofed/head/sys/ofed/include/linux/device.h Sun Mar 13 21:23:25 2011 (r219624) +++ projects/ofed/head/sys/ofed/include/linux/device.h Sun Mar 13 21:51:47 2011 (r219625) @@ -275,16 +275,15 @@ device_register(struct device *dev) unit = -1; if (bsddev == NULL) bsddev = device_add_child(dev->parent->bsddev, - dev->kobj.name, unit); + dev->class->kobj.name, unit); if (bsddev) { if (dev->devt == 0) - dev->devt = device_get_unit(bsddev); + dev->devt = makedev(0, device_get_unit(bsddev)); device_set_softc(bsddev, dev); } dev->bsddev = bsddev; kobject_init(&dev->kobj, &dev_ktype); kobject_add(&dev->kobj, &dev->class->kobj, dev_name(dev)); - get_device(dev); return (0); } @@ -308,17 +307,13 @@ struct device *device_create(struct clas static inline void device_destroy(struct class *class, dev_t devt) { - struct device *dev; device_t bsddev; int unit; unit = MINOR(devt); bsddev = devclass_get_device(class->bsdclass, unit); - if (bsddev) { - dev = device_get_softc(bsddev); - device_unregister(dev); - put_device(dev); - } + if (bsddev) + device_unregister(device_get_softc(bsddev)); } static inline void Modified: projects/ofed/head/sys/ofed/include/linux/in6.h ============================================================================== --- projects/ofed/head/sys/ofed/include/linux/in6.h Sun Mar 13 21:23:25 2011 (r219624) +++ projects/ofed/head/sys/ofed/include/linux/in6.h Sun Mar 13 21:51:47 2011 (r219625) @@ -29,6 +29,8 @@ #ifndef _LINUX_IN6_H_ #define _LINUX_IN6_H_ +#ifndef KLD_MODULE #include "opt_inet6.h" +#endif #endif /* _LINUX_IN6_H_ */ Modified: projects/ofed/head/sys/ofed/include/linux/list.h ============================================================================== --- projects/ofed/head/sys/ofed/include/linux/list.h Sun Mar 13 21:23:25 2011 (r219624) +++ projects/ofed/head/sys/ofed/include/linux/list.h Sun Mar 13 21:51:47 2011 (r219625) @@ -49,15 +49,13 @@ #include <net/bpf.h> #include <net/if.h> #include <net/if_types.h> +#include <net/if_media.h> #include <netinet/in.h> #include <netinet/in_pcb.h> -#include "opt_inet6.h" -#ifdef INET6 #include <netinet6/in6_var.h> #include <netinet6/nd6.h> -#endif #include <vm/vm.h> #include <vm/vm_object.h> Modified: projects/ofed/head/sys/ofed/include/linux/pci.h ============================================================================== --- projects/ofed/head/sys/ofed/include/linux/pci.h Sun Mar 13 21:23:25 2011 (r219624) +++ projects/ofed/head/sys/ofed/include/linux/pci.h Sun Mar 13 21:51:47 2011 (r219625) @@ -178,7 +178,7 @@ pci_resource_len(struct pci_dev *pdev, i } /* - * XXX All drivers just seem to want to inspect the type not flags. + * All drivers just seem to want to inspect the type not flags. */ static inline int pci_resource_flags(struct pci_dev *pdev, int bar) @@ -429,6 +429,7 @@ linux_pci_attach(device_t dev) spin_lock(&pci_lock); list_del(&pdev->links); spin_unlock(&pci_lock); + put_device(&pdev->dev); return (-error); } return (0); @@ -440,10 +441,14 @@ linux_pci_detach(device_t dev) struct pci_dev *pdev; pdev = device_get_softc(dev); + mtx_unlock(&Giant); pdev->pdrv->remove(pdev); + mtx_lock(&Giant); spin_lock(&pci_lock); list_del(&pdev->links); spin_unlock(&pci_lock); + put_device(&pdev->dev); + return (0); } @@ -483,7 +488,9 @@ pci_unregister_driver(struct pci_driver list_del(&pdrv->links); bus = devclass_find("pci"); + mtx_lock(&Giant); devclass_delete_driver(bus, &pdrv->driver); + mtx_unlock(&Giant); } struct msix_entry { Modified: projects/ofed/head/sys/ofed/include/net/ipv6.h ============================================================================== --- projects/ofed/head/sys/ofed/include/net/ipv6.h Sun Mar 13 21:23:25 2011 (r219624) +++ projects/ofed/head/sys/ofed/include/net/ipv6.h Sun Mar 13 21:51:47 2011 (r219625) @@ -29,7 +29,9 @@ #ifndef _LINUX_NET_IPV6_H_ #define _LINUX_NET_IPV6_H_ +#ifndef KLD_MODULE #include "opt_inet6.h" +#endif #define ipv6_addr_loopback IN6_IS_ADDR_LOOPBACK #define ipv6_addr_copy(dst, src) \
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201103132151.p2DLplTY066942>