Received: by 10.223.185.116 with SMTP id b49csp6643458wrg; Wed, 28 Feb 2018 12:57:15 -0800 (PST) X-Google-Smtp-Source: AG47ELsKVuOu+oAroHp7yODFbUYJ4pGQhEJaLFaDs6k4B5ctSuHfoLbOYXRbWk8QQBdSqc2yxUDG X-Received: by 2002:a17:902:7d94:: with SMTP id a20-v6mr16591260plm.184.1519851435321; Wed, 28 Feb 2018 12:57:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519851435; cv=none; d=google.com; s=arc-20160816; b=XgytaxoycYk1EITlVhjo40P4mtMI5odRkFAFhfCFtocSgd2qRKVp9iGMJExCZuUS9K NA6SqlPxfw+vzPcfjGUYmOflVLAIVg80pcVagdDFJINdGC9tbKPH7FFpCqqcReKbWSNt XlfqIAIIgb32NHttg9k2PinlK4V8OypsH8g/KoNyGZroQ7AF549SPnZPvcj1eZtOVZ+G jUVkU81p+Mf8bUMDJr7k4Z4fxifet8ZMvSNogOQw8OTXJfi2CoP/dVt2kjIhf3JpE0m1 9jCdSUeJL8bQv5SuFbTIcE2TPUNP6xXSzYlQUuxuF4KHmJ9VTf+srPxMqUOWDxqzo2ne degQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dmarc-filter:arc-authentication-results; bh=EoMosU6zkx7zhB/dIpGwaJ/SXD11dgXAJDUPM7ZVjdQ=; b=o8gY/T1Xl1/2q5WP4yfwz4nfE8pa7R9BxSgoy3GdqxLymbCScsFe2BHf6pAWQiDDOS dV4RtlJUmSZO92KIPPcDcl0aqLb+iAvxy6j+dBy3ImiSis/kTXQeoUsUcUAvGTBElq6Y jB1ezZpu4S3MSjMVyRwpk0dtt8cANp18Q1AIJjUahLgE8QOC9hAIX7SF+9Au/MBnzwx1 3grOg1WTV1JKx5WHbiXl8VcbCw3xHgZ4dmbU+PmWwL/tvtMNdo4BJpQowcdHTVohvnnd XTCZ0HnwD8iZxWITQ9gNQbS8GrpvFBFNgTb2MxEvvOVFEBa2xROLUY7EAhgPNOMHJ8ha /EeA== 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 p1si1455439pgc.593.2018.02.28.12.57.00; Wed, 28 Feb 2018 12:57:15 -0800 (PST) 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 S934854AbeB1Uzt (ORCPT + 99 others); Wed, 28 Feb 2018 15:55:49 -0500 Received: from mail.kernel.org ([198.145.29.99]:39618 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934739AbeB1Uzr (ORCPT ); Wed, 28 Feb 2018 15:55:47 -0500 Received: from localhost (unknown [69.55.156.246]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 10D43214EE; Wed, 28 Feb 2018 20:55:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 10D43214EE Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=helgaas@kernel.org Date: Wed, 28 Feb 2018 14:55:46 -0600 From: Bjorn Helgaas To: "Gustavo A. R. Silva" Cc: Andy Shevchenko , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] PCI/ASPM: Change type of threshold_ns variable to u32 Message-ID: <20180228205546.GL127842@bhelgaas-glaptop.roam.corp.google.com> References: <20180227231952.GA9001@embeddedor.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180227231952.GA9001@embeddedor.com> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 27, 2018 at 05:19:52PM -0600, Gustavo A. R. Silva wrote: > It seems that the expression threshold_us * 1000 will never exceed the > 32-bit limits [1]. So changing the type of threshold_ns from u64 to u32 > seems sensible [2]. > > [1] https://marc.info/?l=linux-kernel&m=151855021100725&w=2 > [2] https://marc.info/?l=linux-kernel&m=151976318924615&w=2 > > Addresses-Coverity-ID: 1462501 > Signed-off-by: Gustavo A. R. Silva Applied with Andy's Reviewed-by to pci/aspm for v4.17, thanks! I included a more detailed analysis in the changelog: PCI/ASPM: Declare threshold_ns as u32, not u64 aspm_calc_l1ss_info() computes l1_2_threshold in microseconds as: l1_2_threshold = 2 + 4 + t_common_mode + t_power_on; where t_common_mode is at most 255us: PCI_L1SS_CAP_CM_RESTORE_TIME 0x0000ff00 <-- 8 bits; <256us and t_power_on is at most 31 * 100us = 3100us: PCI_L1SS_CAP_P_PWR_ON_VALUE 0x00f80000 <-- 5 bits; <32 PCI_L1SS_CAP_P_PWR_ON_SCALE 0x00030000 <-- *2us, *10us, or *100us So l1_2_threshold is at most 2 + 4 + 255 + 3100 = 3361, which means threshold_ns is at most 3361 * 1000 = 3361000, which easily fits in a u32. Declare threshold_ns as u32, not u64. This fixes a Coverity warning. Addresses-Coverity-ID: 1462501 Signed-off-by: Gustavo A. R. Silva [bhelgaas: changelog] Signed-off-by: Bjorn Helgaas Reviewed-by: Andy Shevchenko > --- > drivers/pci/pcie/aspm.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c > index 57feef2..8633fc4 100644 > --- a/drivers/pci/pcie/aspm.c > +++ b/drivers/pci/pcie/aspm.c > @@ -322,7 +322,7 @@ static u32 calc_l1ss_pwron(struct pci_dev *pdev, u32 scale, u32 val) > > static void encode_l12_threshold(u32 threshold_us, u32 *scale, u32 *value) > { > - u64 threshold_ns = threshold_us * 1000; > + u32 threshold_ns = threshold_us * 1000; > > /* See PCIe r3.1, sec 7.33.3 and sec 6.18 */ > if (threshold_ns < 32) { > -- > 2.7.4 >