diff mbox

xen/pvcalls: fix unsigned less than zero error check

Message ID 20171103084202.27790-1-colin.king@canonical.com (mailing list archive)
State New, archived
Headers show

Commit Message

Colin King Nov. 3, 2017, 8:42 a.m. UTC
From: Colin Ian King <colin.king@canonical.com>

The check on bedata->ref is never true because ref is an unsigned
integer. Fix this by assigning signed int ret to the return of the
call to gnttab_claim_grant_reference so the -ve return can be checked.

Detected by CoverityScan, CID#1460358 ("Unsigned compared against 0")

Fixes: 219681909913 ("xen/pvcalls: connect to the backend")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/xen/pvcalls-front.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

Comments

Jürgen Groß Nov. 3, 2017, 9:01 a.m. UTC | #1
On 03/11/17 09:42, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> The check on bedata->ref is never true because ref is an unsigned
> integer. Fix this by assigning signed int ret to the return of the
> call to gnttab_claim_grant_reference so the -ve return can be checked.
> 
> Detected by CoverityScan, CID#1460358 ("Unsigned compared against 0")
> 
> Fixes: 219681909913 ("xen/pvcalls: connect to the backend")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

Reviewed-by: Juergen Gross <jgross@suse.com>


Juergen
Boris Ostrovsky Nov. 8, 2017, 9:20 p.m. UTC | #2
On 11/03/2017 05:01 AM, Juergen Gross wrote:
> On 03/11/17 09:42, Colin King wrote:
>> From: Colin Ian King <colin.king@canonical.com>
>>
>> The check on bedata->ref is never true because ref is an unsigned
>> integer. Fix this by assigning signed int ret to the return of the
>> call to gnttab_claim_grant_reference so the -ve return can be checked.
>>
>> Detected by CoverityScan, CID#1460358 ("Unsigned compared against 0")
>>
>> Fixes: 219681909913 ("xen/pvcalls: connect to the backend")
>> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> Reviewed-by: Juergen Gross <jgross@suse.com>


Applied to for-linus-4.15.

-boris
diff mbox

Patch

diff --git a/drivers/xen/pvcalls-front.c b/drivers/xen/pvcalls-front.c
index 0c1ec6894cc4..de8a470351a5 100644
--- a/drivers/xen/pvcalls-front.c
+++ b/drivers/xen/pvcalls-front.c
@@ -1186,11 +1186,10 @@  static int pvcalls_front_probe(struct xenbus_device *dev,
 	ret = gnttab_alloc_grant_references(1, &gref_head);
 	if (ret < 0)
 		goto error;
-	bedata->ref = gnttab_claim_grant_reference(&gref_head);
-	if (bedata->ref < 0) {
-		ret = bedata->ref;
+	ret = gnttab_claim_grant_reference(&gref_head);
+	if (ret < 0)
 		goto error;
-	}
+	bedata->ref = ret;
 	gnttab_grant_foreign_access_ref(bedata->ref, dev->otherend_id,
 					virt_to_gfn((void *)sring), 0);