• Logan Gunthorpe's avatar
    mtd: utilize new cdev_device_add helper function · 493cfaea
    Logan Gunthorpe authored
    This is not as straightforward a conversion as the others
    in this series. These drivers did not originally make use of
    kobj.parent so they likely suffered from a use after free bug if
    someone unregistered the devices while they are being used.
    
    In order to make the conversions, switch from device_register
    to device_initialize / cdev_device_add.
    
    In build.c, this patch unwinds a complicated mess of extra
    get_device/put_devices and reference tracking by moving device_initialize
    early in the attach process. Then it always uses put_device and instead of
    using device_unregister and extra get_devices everywhere we just use
    cdev_device_del and one put_device once everything is completely done.
    This simplifies things dramatically and makes it easier to reason about.
    
    In vmt.c, the patch pushes device initialization up to the beginning of the
    device creation and then that function only needs to use put_device
    in the error path which simplifies things a good deal.
    Signed-off-by: default avatarLogan Gunthorpe <logang@deltatee.com>
    Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    493cfaea
vmt.c 21.5 KB