Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp3051660imm; Sun, 1 Jul 2018 11:06:45 -0700 (PDT) X-Google-Smtp-Source: ADUXVKL//5uixCRFaJ7r4yfSwzRkTdhb/Bc55Ii6SzSLL9BBkAtckxOz2hVIRuEfFE+9W0mKk0Vs X-Received: by 2002:a65:47cc:: with SMTP id f12-v6mr19207656pgs.173.1530468405095; Sun, 01 Jul 2018 11:06:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530468405; cv=none; d=google.com; s=arc-20160816; b=mVOMnFR5YIHUCdCOHQqKwfy5OfZxGMNn6ySAxjRToBePsqv6Quz8zk/Iv4km4x20Tn d2WjqC7zm5GXr8MBRW9C2XQqvbLcIAy/DhGLEVEbu14hzHhmGv2BYCxtQJfMXzv7dibL Cerl4/OBSs8YozgnbnUc83wgngwAqIIgH/lKJfHyOex6wg8tx9NITRCCheTrbWy3gHE6 kqM2wpUjAgF8h+6Zvz3YAKibqkFBc7uMJoWVG16dyOZ4l/ZM+MBZqV/cZjLc9BtqGjk4 OpnrvJlcSKpdWeFV+troWjnOlHH5v1K5AXkKX1y7jyAua1CcnkO+R+z2hIa32QhJVIpO ZTqA== 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=Iw9uuL8ovhtRQKc7ceNDEVd0XLOCnuPP1NJEkxTc69Y=; b=02m1Gatwem/rJqa1hBIi/HPGaWMFTMN1uWBTQ1FbZkC3w4/WJOsF81LEovKWFC8Hz/ eKjbfKXciXi3WpwtFQeRHhNI7caVTKKcGUe0xleawd4i3rTWFtcgQcj3jI0Em2vOZzY1 qF4WUnPWcKmiM61Pic3CCOIcgI5It5dsnBSP9g5QxvlMnEzeobsFe8Ks2TcZxoufYVDT 4np5PszzgjF7LbS1v26eK67oDIH1sjzrG+DmrrhzBISv+dSymR+fiKMSSrsY8/LEMSC/ YS82/tIo1ZCQBM+eRKDjDREoYUvTckEUcUZOuy/6CKPEogy8y+cHzrQ037sUebgnumAV Sw5w== 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 n14-v6si1566503pgg.216.2018.07.01.11.06.30; Sun, 01 Jul 2018 11:06:45 -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 S1030310AbeGASF0 (ORCPT + 99 others); Sun, 1 Jul 2018 14:05:26 -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 S965713AbeGASEt (ORCPT ); Sun, 1 Jul 2018 14:04:49 -0400 X-IronPort-AV: E=Sophos;i="5.51,295,1526335200"; d="scan'208";a="271074627" 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: Greg Kroah-Hartman , joe@perches.com, Chengguang Xu Cc: kernel-janitors@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] usb: wusbcore: security: cast sizeof to int for comparison Date: Sun, 1 Jul 2018 19:32:04 +0200 Message-Id: <1530466325-1678-3-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. usb_get_descriptor can return a negative 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/usb/wusbcore/security.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/wusbcore/security.c b/drivers/usb/wusbcore/security.c index 33d2f5d..14ac8c9 100644 --- a/drivers/usb/wusbcore/security.c +++ b/drivers/usb/wusbcore/security.c @@ -217,7 +217,7 @@ int wusb_dev_sec_add(struct wusbhc *wusbhc, result = usb_get_descriptor(usb_dev, USB_DT_SECURITY, 0, secd, sizeof(*secd)); - if (result < sizeof(*secd)) { + if (result < (int)sizeof(*secd)) { dev_err(dev, "Can't read security descriptor or " "not enough data: %d\n", result); goto out;