Skip to contentSkip to conversation

Ref-count problem in kset_find_obj?

DISCUSSION Martin Schwidefsky 3 participants 3 messages Oct 29, 2003 – Oct 30, 2003

lore
Share & tools
lore
#0 lore raw

Hi Pat,
looking through the sysfs code I noticed a potential problem in kset_find_obj:

struct kobject * kset_find_obj(struct kset * kset, const char * name)

{
        struct list_head * entry;
        struct kobject * ret = NULL;

        down_read(&kset->subsys->rwsem);
        list_for_each(entry,&kset->list) {
                struct kobject * k = to_kobj(entry);
                if (!strcmp(kobject_name(k),name)) {
			ret = k;
			break;
                }
        }
        up_read(&kset->subsys->rwsem);
        return ret;
}

The reference count of the kobject to be returned is not increased before the semaphore is released. A kobject_del/unlink could remove the object before the called of kset_find_obj is able to increase the reference count. This makes kset_find_obj more or less unusable, doesn't it?

blue skies,
Martin.

#1 lore raw
Quoted 6 lines

The reference count of the kobject to be returned is not increased before the semaphore is released. A kobject_del/unlink could remove the object before the called of kset_find_obj is able to increase the reference count. This makes kset_find_obj more or less unusable, doesn't it?

Yes, you're right. The function is pretty much unused, and I don't have a problem removing it, provided we can fix up the one user (arch/i386/kernel/edd.c). Unless of course, you're planning on using it..

Pat

#2 lore raw
Quoted 10 lines · Patrick Mochel
Quoted 6 lines

The reference count of the kobject to be returned is not increased before the semaphore is released. A kobject_del/unlink could remove the object before the called of kset_find_obj is able to increase the reference count. This makes kset_find_obj more or less unusable, doesn't it?

Yes, you're right. The function is pretty much unused, and I don't have a problem removing it, provided we can fix up the one user (arch/i386/kernel/edd.c). Unless of course, you're planning on using it..

At the moment, edd.c doesn't actually use it. It wants to - find_bus() is a useful concept, but I haven't proven that the scsi_bus list only has scsi_devices on it, so that code isn't compiled in at present. If the scsi_bus list is clean now, then yes, I'll want to turn it back on (after 2.6.0 is out) and will need find_bus() to be possible.

Thanks,
Matt

Signature · 4 lines
Matt Domsch
Sr. Software Engineer, Lead Engineer
Dell Linux Solutions www.dell.com/linux
Linux on Dell mailing lists @ http://lists.us.dell.com