Device 'xilinx-keypad' does not have a release() function, it is broken and must be fixed.

简介

用platform_device_register()注册的设备,卸载驱动模块的时候会报下面的错误.
Device 'xilinx-keypad' does not have a release() function, it is broken and must be fixed.

原因


//https://elixir.bootlin.com/linux/v4.1/source/drivers/base/core.c

/**
 * device_release - free device structure.
 * @kobj: device's kobject.
 *
 * This is called once the reference count for the object
 * reaches 0. We forward the call to the device's release
 * method, which should handle actually freeing the structure.
 */
static void device_release(struct kobject *kobj)
{
    struct device *dev = kobj_to_dev(kobj);
    struct device_private *p = dev->p;

    /*
     * Some platform devices are driven without driver attached
     * and managed resources may have been acquired.  Make sure
     * all resources are released.
     *
     * Drivers still can add resources into device after device
     * is deleted but alive, so release devres here to avoid
     * possible memory leak.
     */
    devres_release_all(dev);

    if (dev->release)
        dev->release(dev);
    else if (dev->type && dev->type->release)
        dev->type->release(dev);
    else if (dev->class && dev->class->dev_release)
        dev->class->dev_release(dev);
    else
        WARN(1, KERN_ERR "Device '%s' does not have a release() "
            "function, it is broken and must be fixed.\n",
            dev_name(dev));
    kfree(p);
}

原因是 platform_device->device -> release 没有初始化

解决方案

使用platform_device_alloc() , platform_device_add() 替代platform_device_register()去添加设备,如果使用platform_device_register()添加设备需要自己实现 platform_device->device -> release,3.+以上的内核使用设备树管理设备,除测试外尽量少用这种代码添加的方式.

引用

https://stackoverflow.com/questions/15532170/device-has-no-release-function-what-does-this-mean
http://blog.csdn.net/x356982611/article/details/79399371

猜你喜欢

转载自blog.csdn.net/x356982611/article/details/79399371