From patchwork Fri Jun 30 12:30:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Schiffer X-Patchwork-Id: 1801923 X-Patchwork-Delegate: agust@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=tq-group.com header.i=@tq-group.com header.a=rsa-sha256 header.s=key1 header.b=iMADUoxI; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Qsvxm6PpQz20XS for ; Fri, 30 Jun 2023 22:38:36 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8E460867FE; Fri, 30 Jun 2023 14:38:27 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=ew.tq-group.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=tq-group.com header.i=@tq-group.com header.b="iMADUoxI"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 11C97867BD; Fri, 30 Jun 2023 14:37:41 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mx1.tq-group.com (mx1.tq-group.com [93.104.207.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 2444E867CE for ; Fri, 30 Jun 2023 14:36:29 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=ew.tq-group.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=matthias.schiffer@ew.tq-group.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tq-group.com; i=@tq-group.com; q=dns/txt; s=key1; t=1688128590; x=1719664590; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=D5Ks9z7+oaKXutsfXpnvfMbXGU/t0xPq2htVMJ2Z3cI=; b=iMADUoxI5aLB49BJMj7gqOfnv54BaH1XsTea2aC+zfySZ1t+tIXJS+29 BNiZZ7a/t9Lzw8WSZOC0A8iRCV1FkFw93yYxW015J0Rt/8mwfjwQ4us6z DEZsl5ckLe2/pwTk6KKXl+QwmLPW+AHrfbIheHN/rQeAupa9Cl8jUtsdI zPu77d/0Wsn+u8Chw/CFL8olL+NAlMmAom1V1GsJN1yRvgAoH7kQ2nBG5 EkZW9n3KI/vK7337npYQZ84o50FKukfadY1NbqnG8mjN5Mw5+l55k+DJ/ J38MPjKIYsBNw4ke+mgFvHP9rsDULu1zk5V/KR8KwGOd4AnDyTI0IV8ny g==; X-IronPort-AV: E=Sophos;i="6.01,170,1684792800"; d="scan'208";a="31699295" Received: from vtuxmail01.tq-net.de ([10.115.0.20]) by mx1.tq-group.com with ESMTP; 30 Jun 2023 14:30:29 +0200 Received: from localhost.localdomain (SCHIFFERM-M2.tq-net.de [10.121.49.20]) by vtuxmail01.tq-net.de (Postfix) with ESMTPA id E07F2280078; Fri, 30 Jun 2023 14:30:28 +0200 (CEST) From: Matthias Schiffer To: u-boot@lists.denx.de, Anatolij Gustschin Cc: u-boot@ew.tq-group.com, Matthias Schiffer Subject: [PATCH] video: backlight: pwm: avoid integer overflow in duty cycle calculation Date: Fri, 30 Jun 2023 14:30:07 +0200 Message-Id: <20230630123007.1725726-1-matthias.schiffer@ew.tq-group.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean The intermediate value could overflow for large periods and levels. Signed-off-by: Matthias Schiffer Reviewed-by: Simon Glass --- drivers/video/pwm_backlight.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/video/pwm_backlight.c b/drivers/video/pwm_backlight.c index d7c096923b3..46c16a8f447 100644 --- a/drivers/video/pwm_backlight.c +++ b/drivers/video/pwm_backlight.c @@ -63,7 +63,7 @@ static int set_pwm(struct pwm_backlight_priv *priv) int ret; if (priv->period_ns) { - duty_cycle = priv->period_ns * (priv->cur_level - priv->min_level) / + duty_cycle = (u64)priv->period_ns * (priv->cur_level - priv->min_level) / (priv->max_level - priv->min_level); ret = pwm_set_config(priv->pwm, priv->channel, priv->period_ns, duty_cycle);