Skip to contentSkip to conversation

Question about gio_bus release function in sgi-ip22-gio

DISCUSSION Dingisoul 1 participant 1 message Feb 26 MIPS

lore
Share & tools
lore

Dingisoul

author
#0 lore raw

Dear maintainers,

I have a question regarding the sgi-ip22-gio implementation in the MIPS kernel.

gio_bus is declared as a static struct device variable. However, its release function calls kfree() on the device pointer, which would free a statically allocated variable — an undefined behavior:

    static void gio_bus_release(struct device *dev) {
        kfree(dev);
    }

    static struct device gio_bus = {
        .init_name = "gio",
        .release   = &gio_bus_release,
    };

My concern is that this could become an actual problem in ip22_gio_init. If device_register() fails, put_device() is called, which decrements the refcount to zero and triggers the release function:

    static int __init ip22_gio_init(void)
    {
        unsigned int pbdma __maybe_unused;
        int ret;

        ret = device_register(&gio_bus);
        if (ret) {
            put_device(&gio_bus);
            return ret;
        }
        ...
    }

Could this result in undefined behavior if the registration ever fails? Would it make sense to provide a no-op release function instead, given that gio_bus is statically allocated?

Thank you for your time and consideration.

Best regards,

Rubio