Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp51522imu; Thu, 8 Nov 2018 14:36:37 -0800 (PST) X-Google-Smtp-Source: AJdET5d0JjG97dVHWLu/PuBwq326TEdBLYiFAAZgy7WA7R9gv2z9Zat6FFr1zEG5xPSWLuOrtkJp X-Received: by 2002:a17:902:9a04:: with SMTP id v4-v6mr6219168plp.247.1541716597132; Thu, 08 Nov 2018 14:36:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541716597; cv=none; d=google.com; s=arc-20160816; b=qZm8OrmCw2FfEAEwyiug0iw+oUVEH9q7pMHGDLoEoBmZSAHGpcSrPGJtVU13lVTjdj dwgRWmKBNo0JD+nVMDPRnFu+kQ3hCH9/QOHavtxadA5tV/wjppII5Qq6xPM0xBT8rixe 4H5A6U3CHD0fmyDUQ2Hf97kY+qx/7icylm/ufaNR6HIHCPnYoq/JU+MgoDY1P6nGApNr 9V7Xj+dYT3ztD7RM02RGwwW88zpEyCY56vQXcKA73Zchb9b/HypqzGhNizLX83AvLEod WhrE0SfsOj+JKx8WNN6+C5ZHW0tu4wzdNfOBN1YOcuk3013T9SRAiGtIPkQjsTiQIE+o EfRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=XK1wsIOQ1m8D7xk610nIXn6ZqsbsHo+EncNKfRtX9Y4=; b=bEKiNx1P5OoYOBQz7pt4JFGLpRLKkqIftXtRd7ytdVN8vfp54mvl5s/uxjcFtQNqhv QdX1M/velbt5aJnmRqVYSdA5VTaWE+VT11lIcuM23t/puTwHvbYv89Jfo1CVQCrsxnQ4 vjzi3NlUDhae85b9JbFrwgZjRMJAccaMGuNB4jqtbi73sMP1G6C60p1Ii2HxoEtFZ84H CjIVL7jCNHLVSVz3plPwjv8jfaBaqmOlpJuBqc0XQlo6/F77t0TKJtMTPBb8q5N0vTo7 NQ32d9LgC3u3EzOuDWEkGye4CAF6ILRUVZn3DWh1wdvi1X3nxN2eFCP9wNlyNelfguw8 afwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="qrS/RhDm"; 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 v14-v6si5170061pgt.78.2018.11.08.14.36.21; Thu, 08 Nov 2018 14:36:37 -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; dkim=pass header.i=@kernel.org header.s=default header.b="qrS/RhDm"; 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 S1728658AbeKIINl (ORCPT + 99 others); Fri, 9 Nov 2018 03:13:41 -0500 Received: from mail.kernel.org ([198.145.29.99]:54278 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728109AbeKIHgn (ORCPT ); Fri, 9 Nov 2018 02:36:43 -0500 Received: from localhost (unknown [208.72.13.198]) (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 D3AB4208E3; Thu, 8 Nov 2018 21:59:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541714354; bh=KA4p5T/AHZBnuvWp3H2OQZ887cwYTOHwCHoOOQIaZos=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qrS/RhDmamgl1LzSHkdhGZ2+uMfr+1OUy7y1EsA1Lg4QXH8kPE/bLbvHnzks+r1h7 dE8W5ELoamt/HuW8+eHnjMzfeYEMx3qHkV0w1FYAn3tfyM0jVBJiEBo20UNnFIlerE tx14qNrVjTtzmpnS6O0uTrml4tkqnHnFYPubjdNY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eugenia Emantayev , Tariq Toukan , "David S. Miller" , Sasha Levin Subject: [PATCH 4.4 029/114] net/mlx4_en: Resolve dividing by zero in 32-bit system Date: Thu, 8 Nov 2018 13:50:44 -0800 Message-Id: <20181108215101.728604370@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181108215059.051093652@linuxfoundation.org> References: <20181108215059.051093652@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 4850cf4581578216468b7b3c3d06cc5abb0a697d ] When doing roundup_pow_of_two for large enough number with bit 31, an overflow will occur and a value equal to 1 will be returned. In this case 1 will be subtracted from the return value and division by zero will be reached. Fixes: 31c128b66e5b ("net/mlx4_en: Choose time-stamping shift value according to HW frequency") Signed-off-by: Eugenia Emantayev Signed-off-by: Tariq Toukan Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/ethernet/mellanox/mlx4/en_clock.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/mellanox/mlx4/en_clock.c b/drivers/net/ethernet/mellanox/mlx4/en_clock.c index 4dccf7287f0f..52e4ed2f639d 100644 --- a/drivers/net/ethernet/mellanox/mlx4/en_clock.c +++ b/drivers/net/ethernet/mellanox/mlx4/en_clock.c @@ -251,8 +251,11 @@ static u32 freq_to_shift(u16 freq) { u32 freq_khz = freq * 1000; u64 max_val_cycles = freq_khz * 1000 * MLX4_EN_WRAP_AROUND_SEC; + u64 tmp_rounded = + roundup_pow_of_two(max_val_cycles) > max_val_cycles ? + roundup_pow_of_two(max_val_cycles) - 1 : UINT_MAX; u64 max_val_cycles_rounded = is_power_of_2(max_val_cycles + 1) ? - max_val_cycles : roundup_pow_of_two(max_val_cycles) - 1; + max_val_cycles : tmp_rounded; /* calculate max possible multiplier in order to fit in 64bit */ u64 max_mul = div_u64(0xffffffffffffffffULL, max_val_cycles_rounded); -- 2.17.1