Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp3051704imm; Sun, 1 Jul 2018 11:06:47 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeXMtCREyZKLG6FNvWKZ8AenIvmq3v0GTVRatP+IrICgMxc2og2KVScVYlOmR4sRO+8ppCX X-Received: by 2002:a62:d94a:: with SMTP id s71-v6mr10666336pfg.164.1530468407587; Sun, 01 Jul 2018 11:06:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530468407; cv=none; d=google.com; s=arc-20160816; b=JJAPyDKLmmxPBN9tIYrimc9mg5maJ9v1AAKbpmUgPkHL05ZLY5w/F5c4YiHHfUTJhO 4rRthWa7qRKjVob0OWlVBeDgranr4nhaRqPXpbfERwZctDMp/q0brW8NRid+fKy3s0MM wkI8m3k3KI+6YyyLKy/V+6I1eGB5z89p+QnvZFjV1/y9kma0N4nls7UMZDZfiMtVQveZ m0TN9afswOydIDYOru9mIpvlzWx18CDADmvlwR9ycjjhd42uMhvr9GA2KgtialLaVXVx RV7+5OvzRK4nLHi+HppDMgspMNuBTVUqiV1quu3zLliBj2kqYD3uWjJ94HjZYe5FkQTH oN2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=8CPchyURlYpc7lOWm4MboAeE8dNqZFa8l5CLiTXnKsg=; b=jhILY2JV4V3W+wx2LRHsa/0VazKOt/tj63z2n+LtYzT425cq6olqBWvjBLCwLHI5Se 9rb1BcMnF/H3SbqCz6YtfkrS1q0Be1DKfbvYqP16ylkf7GugPRscfg+qRYrkNgs+K+2S +D/lo7wgjM8oZrf1Cbk0Vk1nkD2XR+PdwRyLwKOp9N8bQ6dgS6LglD9/r5LWEWxzEpbb RwiLUHjRZ6MMf5j5zc8ylxXvxY9pML8gM9j0TKxF6FHC54BtZEEmNdk0A7nPfLhUO5k3 wPNI0048bSLd2pTKdewjogbNaxfzM4dQCOUy8GXw91yJ7H4sjmsnxnuUazzYE0a5IRmM 9NKg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h8-v6si13777582pls.69.2018.07.01.11.06.33; Sun, 01 Jul 2018 11:06:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030277AbeGASE4 (ORCPT + 99 others); Sun, 1 Jul 2018 14:04:56 -0400 Received: from mail3-relais-sop.national.inria.fr ([192.134.164.104]:3225 "EHLO mail3-relais-sop.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030229AbeGASEu (ORCPT ); Sun, 1 Jul 2018 14:04:50 -0400 X-IronPort-AV: E=Sophos;i="5.51,295,1526335200"; d="scan'208";a="271074628" Received: from palace.rsr.lip6.fr (HELO localhost.localdomain) ([132.227.105.202]) by mail3-relais-sop.national.inria.fr with ESMTP/TLS/AES128-SHA256; 01 Jul 2018 20:04:45 +0200 From: Julia Lawall To: Hans Verkuil , joe@perches.com, Chengguang Xu Cc: kernel-janitors@vger.kernel.org, Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] [media] gspca_kinect: cast sizeof to int for comparison Date: Sun, 1 Jul 2018 19:32:05 +0200 Message-Id: <1530466325-1678-4-git-send-email-Julia.Lawall@lip6.fr> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1530466325-1678-1-git-send-email-Julia.Lawall@lip6.fr> References: <1530466325-1678-1-git-send-email-Julia.Lawall@lip6.fr> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Comparing an int to a size, which is unsigned, causes the int to become unsigned, giving the wrong result. kinect_read returns the result of usb_control_msg, which can return a negtive error code. A simplified version of the semantic match that finds this problem is as follows: (http://coccinelle.lip6.fr/) // @@ int x; expression e,e1; identifier f; @@ *x = f(...); ... when != x = e1 when != if (x < 0 || ...) { ... return ...; } *x < sizeof(e) // Signed-off-by: Julia Lawall --- drivers/media/usb/gspca/kinect.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/media/usb/gspca/kinect.c b/drivers/media/usb/gspca/kinect.c index 0cfdf8a..f993f62 100644 --- a/drivers/media/usb/gspca/kinect.c +++ b/drivers/media/usb/gspca/kinect.c @@ -163,7 +163,7 @@ static int send_cmd(struct gspca_dev *gspca_dev, uint16_t cmd, void *cmdbuf, actual_len = kinect_read(udev, ibuf, 0x200); } while (actual_len == 0); gspca_dbg(gspca_dev, D_USBO, "Control reply: %d\n", actual_len); - if (actual_len < sizeof(*rhdr)) { + if (actual_len < (int)sizeof(*rhdr)) { pr_err("send_cmd: Input control transfer failed (%d)\n", actual_len); return actual_len < 0 ? actual_len : -EREMOTEIO;