Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp4923903rwd; Tue, 30 May 2023 11:54:28 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6CMXpyqDiIkr1ZfibSSHfuKe/K3ihgtlQb5R6+l5DV5sSoYQ1Bbr2b4hLLyY7h4BukfwdB X-Received: by 2002:a05:6a00:1a0f:b0:64c:c5c0:6e01 with SMTP id g15-20020a056a001a0f00b0064cc5c06e01mr3919700pfv.31.1685472868328; Tue, 30 May 2023 11:54:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685472868; cv=none; d=google.com; s=arc-20160816; b=zpjZhdLJN8opPW76QEH3Xv6XCUHRaLVGGMfUdR8xSp4uz0f4PKwOERC+IBCM+dzzAb +3pQkJkWAvtS2amdTnkLwlagpo3BuIKDeSMSNNb023CrUDk2Lv5n57QWYlHzPaYAfp64 QqUPIqW3syMRMvP6vja5oTkY7SdGUls0TuAVcPAJYl16ZWf/YE+ceSl05sIjUJK/40p3 4y6N2l729OZqGdw9XgOr2U+awv9dhKOJXE+g2YAVLDFHjFJE80TMWS2fKgFg7BOP8FIH 2yCPOlt2aBhuFdFaOI4sF0t4Ek8d4ue73e/h5xWD3xfVihYZ1P4goujTwuZbPogZU9p6 gT7Q== 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=U30+E9zLvgOBox9gKfu7E8rOFU3QuLb3/xBmfvFHOoQ=; b=i8DgHk8cU3lmZdk1d/lXtLjKmEgcQNqZyDWuCysK+qmmFsWL7ElMKVTL1d4SkKEqSn eLT0IJfce3rsqWhHMuASNhkVkYzB8vPKUx6TwH8UxQvfiZrSPKGZPcHhGzys6jdBQdA3 VcA7JAK6NZpZs+GIS+sWGP6nSX0bweZMyvlhaWbfSnk7y0b30oMN408M5eNlZdFRVwro LyWDga7fIlx3bmUxoVr0mJ+Z3pNy2IVTz05Tae4fO7eceYOT9aV4eFILrwPf/b1DpsYp Tj3N8i8r8NYVB4Yuo5fXBFYn0u0WxLreIy/27AwYob/g71SQ7hid+Jmmj+gVxosBTt9P uYwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SobdW6ev; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x184-20020a6263c1000000b00640d9bf6807si2131585pfb.20.2023.05.30.11.54.14; Tue, 30 May 2023 11:54:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SobdW6ev; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230399AbjE3Sum (ORCPT + 99 others); Tue, 30 May 2023 14:50:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229630AbjE3Sul (ORCPT ); Tue, 30 May 2023 14:50:41 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 615B0C9; Tue, 30 May 2023 11:50:40 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id F0729628AE; Tue, 30 May 2023 18:50:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A6ABBC4339B; Tue, 30 May 2023 18:50:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685472639; bh=IZndPRsXdrvOnJb0ewXcTHzPGDycIf5ne3eEnx8Ld9E=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=SobdW6evDpNp5XKzU2RTYcxgG6l3SzTGzHCt5xrkeFknfGnlWzrVbG7cP1lPwqiaP 0FfyQurrDzUSnsieubT4XEnyDT97hyJQtHJCkBqJnG0CujgiOkILFbSLR7zDNG2zfY T0hRclOsh62yzX4bY8+RHhL+htMASIgNqijM8KK+6H5Ht8sJdg5Dv6cDj1Ps1Pey0s oVJeNXw6Y551qe82DQGWsaSS1fwR6MjgToppxj6pwlWvbH7FwDh/O6iZVWx7bZhddo NXJlP8NoZygP29UsklAodVhproIJN3PrDjO2Fv1p9/2bdMZGxOAU7sWK64Gi/PyPsy 8Ln+mS7SaCOWw== Date: Tue, 30 May 2023 20:50:36 +0200 From: Andi Shyti To: carlos.song@nxp.com Cc: aisheng.dong@nxp.com, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, xiaoning.wang@nxp.com, haibo.chen@nxp.com, linux-imx@nxp.com, linux-i2c@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] i2c: imx-lpi2c: fix type char overflow issue when calculating the clock cycle Message-ID: <20230530185036.ggep3pv7booqtb6b@intel.intel> References: <20230529080251.3614380-1-carlos.song@nxp.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230529080251.3614380-1-carlos.song@nxp.com> X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 29, 2023 at 04:02:51PM +0800, carlos.song@nxp.com wrote: > From: Clark Wang > > Claim clkhi and clklo as integer type to avoid possible calculation > errors caused by data overflow. > > Fixes: a55fa9d0e42e ("i2c: imx-lpi2c: add low power i2c bus driver") > Signed-off-by: Clark Wang > Signed-off-by: Carlos Song > --- > drivers/i2c/busses/i2c-imx-lpi2c.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/i2c/busses/i2c-imx-lpi2c.c b/drivers/i2c/busses/i2c-imx-lpi2c.c > index 40a4420d4c12..7dd33564cbe1 100644 > --- a/drivers/i2c/busses/i2c-imx-lpi2c.c > +++ b/drivers/i2c/busses/i2c-imx-lpi2c.c > @@ -211,8 +211,8 @@ static void lpi2c_imx_stop(struct lpi2c_imx_struct *lpi2c_imx) > /* CLKLO = I2C_CLK_RATIO * CLKHI, SETHOLD = CLKHI, DATAVD = CLKHI/2 */ > static int lpi2c_imx_config(struct lpi2c_imx_struct *lpi2c_imx) > { > - u8 prescale, filt, sethold, clkhi, clklo, datavd; > - unsigned int clk_rate, clk_cycle; > + u8 prescale, filt, sethold, datavd; > + unsigned int clk_rate, clk_cycle, clkhi, clklo; looks OK. Reviewed-by: Andi Shyti there is, though, another part I would take care of, this bit: clklo = clk_cycle - clkhi; if (clklo < 64) break; It might be unlikely, but if "clk_cycle > clkhi" then all the calculation. Do you mind adding a check: if (unlikely(clk_cycle > clkhi)) break; Andi > enum lpi2c_imx_pincfg pincfg; > unsigned int temp; > > -- > 2.34.1 >