Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp2973197pxb; Tue, 12 Jan 2021 03:16:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJwLrqlYUOEoIyxrU0VkeIRJaX/T9wj75/LBpYfsbYwbtsAJhfA7LrKtioZtkQLSyrYb7e2A X-Received: by 2002:aa7:c253:: with SMTP id y19mr2914296edo.179.1610450200758; Tue, 12 Jan 2021 03:16:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610450200; cv=none; d=google.com; s=arc-20160816; b=uwfjsPjVkRHHt3zMGRT8OFGco6NdcqRGhZiEfczIMTNaKYWALaHG+r1CxnrbFR4LGi MfDx0+R5A310XjWpz1KXIkJ2lvCWXbaVU4lLEOWwjoFHgJgNmnndUYdQXcaCks1ADMkb rcpI+tlpzti0k937pJ1zn9bjqU9++tuDeEa6MOEK6u8lATOKC5up+LZLbTOkz9EOGSzL xLOecGoBGV4zwc08o0VYDIkxKcogy010Foc+Ff50Fp6ZzVKxeqBTjvcmg4bw9+5/SSLC 5u/jREVw/TS/zRwVjTyzyCe8CeNAMBWb73U2lzY58gD3RihPsEix6WmkutyR+7qe8WhH 1YpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=d5mQicZMUKTCO6n0ryJFS3xUw7H8AnuHgsc2eVO1VdQ=; b=a/S9Iye5BYu2l4kz8pDTz9E4ZrFNhqaV1o3dB18lXN2EEvZRMM3ROIMUbngKdQX8nE htq+WsTJWaDlcnwCNoOxdLhseq+pi387/upYlnDLwAYG32vUlwquJ0J+C/VU2h8LKvOD kngTxgy+1pSfVVQU7FbI/cP5eGj3a7WksUZ9JgUEEa3J6XKLJ58B2G0Rc/l1EJzGatZk 57Jw+zW6Mu0wyrVMWVkJvzS7E6tkSjeicfo2gyQ5mNAR5qLrTt+Y0pN/IA/c6lEyDkhP 1a4iM2AIQ9O62b94VoffATL8IUV9ioq0l+36bTrtIRSswPFF6S44miatTHK/QV0aGsa8 Wifg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=rEkgccxG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i2si1123802edv.606.2021.01.12.03.16.17; Tue, 12 Jan 2021 03:16:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=rEkgccxG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731021AbhALEim (ORCPT + 99 others); Mon, 11 Jan 2021 23:38:42 -0500 Received: from perceval.ideasonboard.com ([213.167.242.64]:40570 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728687AbhALEil (ORCPT ); Mon, 11 Jan 2021 23:38:41 -0500 Received: from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id EBFB63E; Tue, 12 Jan 2021 05:37:58 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1610426279; bh=JXMwIpyboCcKzCJXsNtKWX/esNzMw9e7pfIvcu3n2vE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=rEkgccxGm3jhwLQrWHkwt00pU9LMdLL4/NwfyadZHiYkyKbsC0/gpEw40yCrLzOWX aUV1UsghW7ijFQThJLPscXA7hCcdTgB5x6wtcUvMhEv8EXcb7jyyGuMa3uQWSlGL5+ agrb6waRf06ib+OX9eLqkj8sn0wYAYmVtybJY1Ys= Date: Tue, 12 Jan 2021 06:37:45 +0200 From: Laurent Pinchart To: Geert Uytterhoeven Cc: Andrzej Hajda , Neil Armstrong , Jonas Karlman , Jernej Skrabec , David Airlie , Daniel Vetter , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] drm/bridge: nwl-dsi: Avoid potential multiplication overflow on 32-bit Message-ID: References: <20210111125702.360745-1-geert+renesas@glider.be> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20210111125702.360745-1-geert+renesas@glider.be> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Geert, Thank you for the patch. On Mon, Jan 11, 2021 at 01:57:02PM +0100, Geert Uytterhoeven wrote: > As nwl_dsi.lanes is u32, and NSEC_PER_SEC is 1000000000L, the second > multiplication in > > dsi->lanes * 8 * NSEC_PER_SEC > > will overflow on a 32-bit platform. Fix this by making the constant > unsigned long long, forcing 64-bit arithmetic. > > While iMX8 is arm64, this driver is currently used on 64-bit platforms > only, where long is 64-bit, so this cannot happen. But the issue may > start to happen when the driver is reused for a 32-bit SoC, or when code > is copied for a new driver. > > Signed-off-by: Geert Uytterhoeven > --- > Compile-tested only. > --- > drivers/gpu/drm/bridge/nwl-dsi.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/gpu/drm/bridge/nwl-dsi.c b/drivers/gpu/drm/bridge/nwl-dsi.c > index 66b67402f1acd57d..a8da3081efdcc84e 100644 > --- a/drivers/gpu/drm/bridge/nwl-dsi.c > +++ b/drivers/gpu/drm/bridge/nwl-dsi.c > @@ -195,7 +195,7 @@ static u32 ps2bc(struct nwl_dsi *dsi, unsigned long long ps) > u32 bpp = mipi_dsi_pixel_format_to_bpp(dsi->format); > > return DIV64_U64_ROUND_UP(ps * dsi->mode.clock * bpp, > - dsi->lanes * 8 * NSEC_PER_SEC); > + dsi->lanes * 8ULL * NSEC_PER_SEC); I wonder if we could get rid of a whole class of bugs by turning NSEC_PER_SEC into a ULL, but I suppose there are valid cases where a 32-bit integer is enough. Reviewed-by: Laurent Pinchart How did you come across this by the way ? > } > > /* -- Regards, Laurent Pinchart