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

Re: [Xen-devel] Why cast to "signed short" before checking the return value of gnttab_claim_grant_reference() in xen-netfront.c?



>>> On 28.10.16 at 08:46, <dongli.zhang@xxxxxxxxxx> wrote:
> Would anyone please help with a question on xen-netfront.c code?
> 
> In xen-netfront.c, the return value of gnttab_claim_grant_reference() is
> checked with "BUG_ON((signed short)ref < 0);". Why we use signed short here
> while the return value is of uint32_t? 

The return value is of type int. The value the return value gets stored
into is of type uint32_t.

> Am I missing anything or can I send a patch to fix this issue? In
> xen-blkfront.c and xen-scsifront.c "BUG_ON(gnt_list_entry->gref == -ENOSPC);"
> is involved to check return value. 

This certainly looks wrong. Special casing -ENOSPC, otoh, isn't the
best approach either - I think you want to use IS_ERR_VALUE()
instead, perhaps together with using another intermediate
variable (or type long) to at once deal with the type mismatch
mentioned above as well as to please the compiler when using
IS_ERR_VALUE() (which casts the value to a pointer).

Jan

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
https://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.