From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Cooper Subject: Re: [PATCH] tools/libxc: Fix error checking for xc_get_{cpu, node}map_size() callers Date: Thu, 12 Dec 2013 21:05:47 +0000 Message-ID: <52AA252B.2070109@citrix.com> References: <1386776862-19921-1-git-send-email-andrew.cooper3@citrix.com> <1386858242.18946.1.camel@kazak.uk.xensource.com> <1386860178.5488.113.camel@Solace> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1386860178.5488.113.camel@Solace> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Dario Faggioli , Ian Campbell Cc: George Dunlap , Ian Jackson , Xen-devel List-Id: xen-devel@lists.xenproject.org On 12/12/2013 14:56, Dario Faggioli wrote: > On gio, 2013-12-12 at 14:24 +0000, Ian Campbell wrote: >> On Wed, 2013-12-11 at 15:47 +0000, Andrew Cooper wrote: >>> c/s 2e82c18cd850592ae9a1f682eb93965a868b5f2f changed the error returns of >>> xc_get_{cpu,node}map_size() to now include returning -1. This invalidated the >>> error checks from callers, which expected 0 to be the only error case. >> I don't think 0 is a valid error value any more. Neither xc_get_max_cpus >> nor xc_get_max_nodes can return 0 and the map_size functions will round >> to 1 or more. >> > Yep, I confirm that, after that changeset, neither > xc_get_max_{cpus,nodes}() nor xc_get_{cpu,node}map_size() return 0 as an > error anymore. Zero might not be "the error condition" any more, but it is certainly an error from any of these functions (and possible as xc_get_max_{cpus,nodes}() is capable of returning 0 if Xen hands back -1 for physinfo.max_{cpu,node}_id) > >> So these could all be "< 0" tests think. >> > Indeed. > > Anyway, looks like, while I fixed the callers of the xx_get_max_xx > things in that very comment, I didn't do the same for the xx_get_*map_xx > ones. Weird, as ISTR doing so too... :-/ > > Anyway, thanks to Coverity for caching this and to Andrew for the patch. > > I'll reply to v2 (if you're posting it) but, with the conditions > converted to "< 0", this can have my: > > Reviewed-by: Dario Faggioli > > Regards, > Dario > xc_{cpu/node}map_alloc() must strictly still be "<= 0" checks to avoid the issue where calloc(1, 0) returns a non-NULL pointer. Currently, I am of the opinion that the patch is better as is, than changing some of the checks to being strictly "< 0" ~Andrew