lkml.org 
[lkml]   [2010]   [Jul]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: [PATCH 2/6] Driver core: Fix memory leak on bus_register error path
    >>> 
    >>> retval = kset_register(&priv->subsys);
    >>> - if (retval)
    >>> + if (retval) {
    >>> + kfree(priv->subsys.kobj.name);
    >>
    >> I don't think we want to bury the logic of how kobject names are handled
    >> up here in the bus code, right? Shouldn't the subsys kobject name be
    >> able to be cleaned up on its own somehow instead?
    >>
    >
    > So, my first instinct was to use kobject_cleanup, but a few lines above:
    >
    > priv->subsys.kobj.ktype = &bus_ktype;
    >
    > and bus_ktype's definition, with the notable absence of a release method:
    >
    > static struct kobj_type bus_ktype = {
    > .sysfs_ops = &bus_sysfs_ops,
    > };
    >
    > which in kobject_cleanup would yield:
    >
    > struct kobj_type *t = get_ktype(kobj);
    >
    > if (t && !t->release)
    > pr_debug("kobject: '%s' (%p): does not have a release() "
    > "function, it is broken and must be fixed.\n",
    > kobject_name(kobj), kobj);
    >
    > (if I understand everything correctly)
    >

    Thinking about this more, how does this ever work "correctly"? If we
    chase the 'normal' path from bus_unregister...

    given bus->p->subsys.kobj.ktype = &bus_ktype

    bus_unregister(struct bus_type *bus) {
    kset_unregister(&bus->p->subsys) {
    kobject_put(&k->kobj) {
    kref_put(&kobj->kref, kobject_release) {
    (assuming last ref)
    kobject_cleanup(container_of(kref, struct kobject, kref)) {
    struct kobj_type *t = get_ktype(kobj);

    if (t && !t->release)
    pr_debug("kobject: '%s' (%p): does not have a release() "
    "function, it is broken and must be fixed.\n",
    kobject_name(kobj), kobj);

    Wouldn't this get hit every time a bus unregisters? I feel like I'm
    missing something here?


    \
     
     \ /
      Last update: 2010-07-24 03:51    [W:0.022 / U:124.900 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site