[Patch v2 2/4] veth: implement io_alloc()

Cong Wang xiyou.wangcong at gmail.com
Mon Mar 31 15:11:57 EDT 2014


On Mon, Mar 31, 2014 at 4:04 AM, Thomas Graf <tgraf at suug.ch> wrote:
> On 03/28/14 at 06:08pm, Cong Wang wrote:
>> +static int veth_alloc(struct rtnl_link *link)
>> +{
>> +     struct rtnl_link *peer;
>> +     int err;
>> +
>> +     if (link->l_info)
>> +             return 0;
>
> Can you put a comment above to explain that the return is needed
> to break the recursion loop?
>

Sure.

>> +
>> +     if (!(peer = rtnl_link_alloc())) {
>> +             rtnl_link_put(link);
>
> This put looks wrong. It could free the link object beneath
> the caller.
>

Good catch, I will fix it.

>> +             return -NLE_NOMEM;
>> +     }
>> +
>> +     peer->l_info = link;
>
> You need to acquire a refcnt to link to make sure link is
> not freed while you hold that reference.
>
> nl_object_get(OBJ_CAST(link));
> peer->l_info = link;
>
> And then release it again in io_free
>

Yeah, will do.

Thanks!



More information about the libnl mailing list