Re: [PATCH v3 5/5] virtio: add comments for virtio_register_device

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2017-12-19 19:11 GMT+08:00 Cornelia Huck <cohuck@xxxxxxxxxx>:
> On Sun, 17 Dec 2017 21:48:05 +0800
> weiping zhang <zwp10758@xxxxxxxxx> wrote:
>
>> As mentioned at drivers/base/core.c:
>> /*
>> * NOTE: _Never_ directly free @dev after calling this function, even
>> * if it returned an error! Always use put_device() to give up the
>> * reference initialized in this function instead.
>> */
>> virtio_register_device may fail before/after call device_register, the
>> caller should do a proper cleanup. Caller cann't use kfree directly,
>> if virtio_register_device has already called device_register. Caller
>> cann't use put_device directly, if virtio_register_device has not yet
>> call device_register, because kobject_put may give a warning cause
>> dev->kobj has not been initialized.
>
> This comment makes me inclined to think that we should also rethink
> register_virtio_device(). On failure, we cannot do kfree() due to
> driver core interaction; but we cannot do a put_device() either, since
> the refcount may not yet have been initialized -- unless we check the
> device status, which triggers I/O (at least on s390).
>
> We really want to do the same cleanup on error in every case. What
> about splitting device_register() into device_initialize() and
> device_add()? If we move device_initialize() before getting an index,
> we should be fine with doing put_device() on error in every case.
>
Good idea (^_^), I''ll apply it at V4.
_______________________________________________
Virtualization mailing list
Virtualization@xxxxxxxxxxxxxxxxxxxxxxxxxx
https://lists.linuxfoundation.org/mailman/listinfo/virtualization



[Index of Archives]     [KVM Development]     [Libvirt Development]     [Libvirt Users]     [CentOS Virtualization]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux