libxc: avoid clobbering errno in xc_domain_pod_target()
PATCH v2 1/1 libxc: avoid clobbering errno in xc_domain_pod_target()
do_memory_op() supplies return value and has "errno" set the usual way. Don't overwrite "errno" with 1 (aka EPERM on at least Linux). There's also no reason to overwrite "err".
---
While the hypervisor side of the hypercall gives the impression of being able to return positive values as of 637a283f17eb ("PoD: Allow pod_set_cache_target hypercall to be preempted"), due to the use of "rc >= 0" there, afaict that's not actually the case. IOW "err" can really only be 0 or -1 here, and hence its setting to zero may also be worthwhile to drop.
---
v2: Don't save/restore errno, as DPRINTF() already does so.
tools/libs/ctrl/xc_domain.c +0 -4
@@ -1230,13 +1230,9 @@ static int xc_domain_pod_target(xc_inter err =do_memory_op (xch, op, &pod_target,sizeof (pod_target));if ( err <0 ) - {DPRINTF ("Failed %s_pod_target dom %d\n" , (op==XENMEM_set_pod_target)?"set" :"get" , domid); - errno = -err; - err =-1 ; - }else err =0 ;
Quoted 5 lines · Jan Beulich
do_memory_op()supplies return value and has "errno" set the usual way. Don't overwrite "errno" with 1 (aka EPERM on at least Linux). There's also no reason to overwrite "err".Signed-off-by Jan Beulich <[email protected]>
Juergen
Hi Jan
Quoted 7 lines · Jan Beulich
do_memory_op()supplies return value and has "errno" set the usual way. Don't overwrite "errno" with 1 (aka EPERM on at least Linux). There's also no reason to overwrite "err".Signed-off-by Jan Beulich <[email protected]>
But if err can really only be 0 or -1, I do wonder if the else forcing err to 0 could be removed but I must say I have no idea if do_memory_op could return a value >0.
Anyway not related to the patch itself.
Cheers
Bertrand
Quoted 28 lines
---
While the hypervisor side of the hypercall gives the impression of being able to return positive values as of637a283f17eb("PoD: Allowpod_set_cache_targethypercall to be preempted"), due to the use of "rc >= 0" there, afaict that's not actually the case. IOW "err" can really only be 0 or -1 here, and hence its setting to zero may also be worthwhile to drop.
---
v2: Don't save/restore errno, asDPRINTF()already does so.tools/libs/ctrl/xc_domain.c +0
-4@@ -1230,13 +1230,9 @@ static int xc_domain_pod_target(xc_inter err =do_memory_op (xch, op, &pod_target,sizeof (pod_target));if ( err <0 ) - {DPRINTF ("Failed %s_pod_target dom %d\n" , (op==XENMEM_set_pod_target)?"set" :"get" , domid); - errno = -err; - err =-1 ; - }else err =0 ;
Quoted 8 lines · Bertrand Marquis
Quoted 7 lines · Jan Beulich
do_memory_op()supplies return value and has "errno" set the usual way. Don't overwrite "errno" with 1 (aka EPERM on at least Linux). There's also no reason to overwrite "err".Signed-off-by Jan Beulich <[email protected]>Reviewed-by Bertrand Marquis <[email protected]>
Thanks.
Quoted 2 lines
But if err can really only be 0 or -1, I do wonder if the else forcing err to 0 could be removed but I must say I have no idea if
do_memory_opcould return a value >0.
Indeed - see ...
Quoted 8 lines
Quoted 8 lines
---
While the hypervisor side of the hypercall gives the impression of being able to return positive values as of637a283f17eb("PoD: Allowpod_set_cache_targethypercall to be preempted"), due to the use of "rc >= 0" there, afaict that's not actually the case. IOW "err" can really only be 0 or -1 here, and hence its setting to zero may also be worthwhile to drop.
---
... this.
Jan
Hi Jan,
Quoted 28 lines · Jan Beulich
Quoted 8 lines · Bertrand Marquis
Quoted 7 lines · Jan Beulich
do_memory_op()supplies return value and has "errno" set the usual way. Don't overwrite "errno" with 1 (aka EPERM on at least Linux). There's also no reason to overwrite "err".Signed-off-by Jan Beulich <[email protected]>Reviewed-by Bertrand Marquis <[email protected]>Thanks.
Quoted 2 lines
But if err can really only be 0 or -1, I do wonder if the else forcing err to 0 could be removed but I must say I have no idea if
do_memory_opcould return a value >0.Indeed - see ...
Quoted 8 lines
Quoted 8 lines
---
While the hypervisor side of the hypercall gives the impression of being able to return positive values as of637a283f17eb("PoD: Allowpod_set_cache_targethypercall to be preempted"), due to the use of "rc >= 0" there, afaict that's not actually the case. IOW "err" can really only be 0 or -1 here, and hence its setting to zero may also be worthwhile to drop.
---
Quoted 1 line
... this.
So the else should be dropped then, why not doing it and just mentioning it there ?
Bertrand
Quoted 3 lines
Jan
Quoted 27 lines · Bertrand Marquis
Quoted 27 lines · Jan Beulich
Quoted 8 lines · Bertrand Marquis
Quoted 7 lines · Jan Beulich
do_memory_op()supplies return value and has "errno" set the usual way. Don't overwrite "errno" with 1 (aka EPERM on at least Linux). There's also no reason to overwrite "err".Signed-off-by Jan Beulich <[email protected]>Reviewed-by Bertrand Marquis <[email protected]>Thanks.
Quoted 2 lines
But if err can really only be 0 or -1, I do wonder if the else forcing err to 0 could be removed but I must say I have no idea if
do_memory_opcould return a value >0.Indeed - see ...
Quoted 8 lines
Quoted 8 lines
---
While the hypervisor side of the hypercall gives the impression of being able to return positive values as of637a283f17eb("PoD: Allowpod_set_cache_targethypercall to be preempted"), due to the use of "rc >= 0" there, afaict that's not actually the case. IOW "err" can really only be 0 or -1 here, and hence its setting to zero may also be worthwhile to drop.
---
Quoted 3 lines
Quoted 1 line
... this.
So the else should be dropped then, why not doing it and just mentioning it there ?
Well, I'd like confirmation by a maintainer. There are a few aspects to how things are done in the tool stack which I'm not always aware of. IOW there might be reasons to keep things as they are after this variant of the patch.
Jan