From patchwork Mon Nov 25 13:50:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Song X-Patchwork-Id: 13884916 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9CCCDD58D4C for ; Mon, 25 Nov 2024 13:43:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:Date:Subject:Cc:To:From:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=BaIdQrInkRuQ0JQhQUkfXrxuh827knd7KtBLV02hJhQ=; b=zIRte/L6ApDXV4gyD1X2IIBsUR J3fVVVNWHUGgaH3Stm07KhW5L4/n537JEgcIMpm3uppBjEX1UMxjiiHWRqxCq8qE05e5d7DDxErsI QPD47v5EwW54hS9Kjze1cpdrXxED25AflrMLQa2tWwLTrioS/i3EoSTXA21bSl1VPy8rKgmxCPKKI YXrvrnPyr4zc+IrP2oDYKcKGc1nmmTNGATdi6rFh6T07MBvJmuv1mxnn/ZLypAO6kdHzIVfteOYwF OkZRtLd3WYaCiCIxGd748KLyxK1w8JPXBJc3EMOxNotWnWiDAx6jgy37cdvV6alW8KvA2wqMmvNQ5 Jj8uGVFg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tFZMj-00000008ANQ-3Z1u; Mon, 25 Nov 2024 13:43:01 +0000 Received: from mail-dbaeur03on2061a.outbound.protection.outlook.com ([2a01:111:f403:260d::61a] helo=EUR03-DBA-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tFZLm-00000008AGD-18l0 for linux-arm-kernel@lists.infradead.org; Mon, 25 Nov 2024 13:42:03 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=LXKvIJWeabARajgz0/xcCE+XeL6XY9ihDsjE4VbcqnintRRd4yOj7dM07vCCfJzsQiYw6rHPLJS2DmR/N0JrmkV6xGDjmowl+APALJEkGH4lhFq4AlU/1/Tytaou/2oAs9KpWhpm82gzGKK3D5i1ibb7t1QU/v5h0MoINEZe+JsGfdDDcoEJt+fFbv2f0ZxpNjauOtbXpOSGSXlcTtMsN6QzM3LMHBqlbkR1nHBFNckqEcCXgiSfw57iAnvYdrOjkTrwly2DdmU3FkN2Hrm3cCSTH8oUdDeX0CjMRV1tIUPM3sg+rvA8xAfnTUSxMHfvo22l+VduS9d6CtP0hquzVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=BaIdQrInkRuQ0JQhQUkfXrxuh827knd7KtBLV02hJhQ=; b=Gomv+WggUzZgrgZSR7x7+fRZVVU7kVFBcu48MKngv1ulveDlUzkMPxdOF8hYq7eI4Ed+8yPyCNEL0FXPgJav4++EHR27wJkn1JcdId9EvXr8yyOFr87vZlSA2XgKP3szE9zkuRvr802rue8iMmspqgTaid2dKqUMHBroGt+E/ey6pRlT5hfhTWEJmO5Xiqt5/x8uVC27/IUW75WfPJ8iG2gDckuCOlVRXdV5E3MQI3pmL5Yzzp1FcyDRU99Mf+bKf91od26sEaSR39qCw2LBNfQzGsh9GKq+VK8ZGkkuMPvQuM27YxH/AwwYNdMNdjkU6ajXs3/jBx2fpftljDXZXg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=BaIdQrInkRuQ0JQhQUkfXrxuh827knd7KtBLV02hJhQ=; b=Purzo0tNJeLkIm3p0jeenw5rmksbtO/d5N1HU2MAA71ut0GXtAOjiGQgTFm2+BnIIF9PrGzC3nfQzyerLMv+BaENr6TTpRxlFh8kvOx2N7pQU6i1946dQsDvH2HRK9rj+0NzNWhgZ1j68vk/s6GtWD2P6ZViWC8+DBfvmOSJdrygjkLaDna+llermx76ocMcVLWQx7sGgeWZEpiaWvGJMUHhlVdhr+LfE9Wx9oZmgkJJNxegHYMcmj1AvMPOt+L1J0BSlztKOhW0ryKLqszOu9Ye38NPoEHDYEq7qik2IL+wmMAgJ8nvRDrHKetrVtxC24jYGDHwK8M+NtaTxBc9Zg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM0PR0402MB3937.eurprd04.prod.outlook.com (2603:10a6:208:5::22) by GV1PR04MB9117.eurprd04.prod.outlook.com (2603:10a6:150:24::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8182.20; Mon, 25 Nov 2024 13:41:57 +0000 Received: from AM0PR0402MB3937.eurprd04.prod.outlook.com ([fe80::4e37:f56b:8a3e:bff0]) by AM0PR0402MB3937.eurprd04.prod.outlook.com ([fe80::4e37:f56b:8a3e:bff0%4]) with mapi id 15.20.8048.020; Mon, 25 Nov 2024 13:41:57 +0000 From: carlos.song@nxp.com To: o.rempel@pengutronix.de, kernel@pengutronix.de, andi.shyti@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, festevam@gmail.com, frank.li@nxp.com Cc: linux-i2c@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] i2c: imx: fix divide by zero warning Date: Mon, 25 Nov 2024 21:50:19 +0800 Message-Id: <20241125135019.1612030-1-carlos.song@nxp.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: AS4P192CA0044.EURP192.PROD.OUTLOOK.COM (2603:10a6:20b:658::8) To AM6PR0402MB3944.eurprd04.prod.outlook.com (2603:10a6:209:1c::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR0402MB3937:EE_|GV1PR04MB9117:EE_ X-MS-Office365-Filtering-Correlation-Id: 5a8737ef-ad67-49f7-96d6-08dd0d56ee65 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|52116014|376014|7416014|1800799024|366016|38350700014; X-Microsoft-Antispam-Message-Info: kO9ULpYD40hPZLIR1107PdjDSjqShBXSep6da73d2ofyLtmheDP15PkOMINBLnDEUn0vvwpUEx5kKgQwPkp4JsWXQTBpGs/4a2wy+KhAkjlBQraBK3aD2yjVq3X/IrpBn6xgCpvnQFRXVcyBDOYvst5jyGAU5nosdOFTi70XI4ttOaqwfwlWtHliLRGtCvxSEqn63Du8UREnO23aohHndYJ2N18KsyfBC42WDtUv3WgDgMHddyRW/3kIIPDgLvS+YNeuWhV0ELEVyvBiX03e4BJPF3c3GMoV801UWAVYF4g83EGb/f7F1wsLm8SF90klTZ75ATnuXlewVrshOf3LnaeEuGZ2HAUHVb3ZKZO0FZiKa2j6BkGa05ZNRghGe9sjp+e8hojZmLj8miycygTCP/ilD0viSYnbPR9aSwLwkgxWRUGyYfY3K+crjL5nXUVTAOc0FbP1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;SFS:(13230040)(52116014)(376014)(7416014)(1800799024)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: TDnYYihu3cImN+moPJlQhuDj1BbFkYwcJchZRPFy8g1C/lQJcEiribanL2WEow6YeP8eBR1XaktqTbJwAlUW0X5fQw5gC7j9DlN6gFzR1vo7IGF1tOD4qqDU/F+70ySrDsj3KjUkagp7CIQak8r2pR0eW0gOV05y2y0ruVS3QYEqf9pQVZz8336RQ7PKO218/cor++lHoVX+n61UBnTiCc7tBMeBvoiAjXnFK4GAqGA5dAQEzT/55mdGxrd61FyC+toBxJbe8WmXH/ezKluPrX8tGjTdBWwdMLoHbjetOnmGaFSko7PWjz3fpyPnNzTtHLqrthUBsnj47EGCHWvBuEsTU1ciR6nMYFe4WZU6nNMkwjP5aIzf3XI1SVyugR2Dd2MAUj2BqH92bLtljpFOfgdLOWB4QIv6zIK0P3Pl/LxSry9IxX74z3290TA0aGLT2oNDUbu2iizB/7VzRN8ScCaRPIdt/vUtjzwiomGgow5Pa/90zSy4np8jUpVfOBXJBIh/1lflNHmuXiz62txZpIr/qeYuy10s1gF+mufnWZyfmSNurkFmnnQHIhdqqnxOG40Lw++3yT3kdbU/INuwxn387akrtCTE+OPZI30tn7GQgmG+9XY1jI3A1cQYpdZTQ9bNKRBkt+LCmtkain7DYz4g+8IKd7sogRY/DLnnLPFBBsfwGxfeh8QKSUvE7CDy6rTFZxz+24LFAdUe79I53L0BkswiJK/Fl6GqdZgkCi1cRlRSIjbNgLfNnCdnTncTzHxoeSh31Sro85/unisBsrzq9Y2XsLqMAjPgX/fR2v/3aIvDS2NIjjBGh7BKfDuj04vrEhmS85Q7ojfh7Zq9or78gu29YFGe3GmE40occGMHW0xyj6mnOx3VKsloVmKHjVHObFG0U4W58DfJ+sIyV+MESX7WZ8CVSz2flgPhxEFzBeBagUVssTyE3GL8+JwhotOxy7RKhhpMELuPW1FszuUFRnX12o2xr0YCb/jvlbTlnoAtcGnnEa2hzNoAMuEvgSHMkR8XWujukJlBIHEwNPxpgHFmIHOE+KVpM4nWE1FBU4Qco5/b06XgFx/nU4EefHR7l2M2uFTyK5U7YCKZbeDTxvLuzM5jEnYUEf9wyEgJhwTWtgGY15Exg8Au00GLDAJaq2gqhsEXzE44PL0ngXLN+dGGCzCj7BtTV80iODLCbGrA/BAM2Y68llnamNbrVhyuJLY20yXzpOOj6Q33SxF5+3yoe7g0gYLu3z+emtXQ4fgldtEeaQeiVhlzVV2E1Yo7Csex+S65cQUK6ofUhv2v31eqr9gheScOg6G8t3CoeYpOlQv0nb4sGZgHhfPIeuL4gcjd2WYK7xcRWdVeI+qPdonMgNFGPusCBZ2Ragl70UAvqSlEblgeR9wzY4caYksSvPS8zpSxOCwf3FBnQRPTROkqiox8Fjjpc79ctASK1hqgkJi6qh5VVpdYvQKMdvTFXpS7ANnkMbN3oRzoxaI5aqY5hk7Mlo5rmF1l4sxzwHvDlpXexNhjJn5NzpdScd0hUVi5TUMcdFZURaxoBwDfZs8ITw706jINh1hWGRpsWV13kSfvbG9J/HiA1sUF X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5a8737ef-ad67-49f7-96d6-08dd0d56ee65 X-MS-Exchange-CrossTenant-AuthSource: AM6PR0402MB3944.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Nov 2024 13:41:57.8740 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: mjZlEGE9HwkLK4WY4DBBTjwiYdzkMziFpKysfs7bswofeKdb6Zn90boRTF9pXltfV3JVIEYyBkz36L5G2eovZA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV1PR04MB9117 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241125_054202_310894_9F53A2A6 X-CRM114-Status: GOOD ( 16.13 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Carlos Song Add "i2c_clk_rate / 2" check to avoid "divide by zero warning". i2c_clk_rate may be zero if i2c clock is disabled. Signed-off-by: Carlos Song Signed-off-by: Clark Wang Signed-off-by: Haibo Chen --- drivers/i2c/busses/i2c-imx.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c index 2c782cdc26bd..5ed4cb61e262 100644 --- a/drivers/i2c/busses/i2c-imx.c +++ b/drivers/i2c/busses/i2c-imx.c @@ -623,8 +623,8 @@ static int i2c_imx_acked(struct imx_i2c_struct *i2c_imx) return 0; } -static void i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx, - unsigned int i2c_clk_rate) +static int i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx, + unsigned int i2c_clk_rate) { struct imx_i2c_clk_pair *i2c_clk_div = i2c_imx->hwdata->clk_div; unsigned int div; @@ -639,7 +639,11 @@ static void i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx, /* Divider value calculation */ if (i2c_imx->cur_clk == i2c_clk_rate) - return; + return 0; + + /* Keep the denominator of the following program always NOT equal to 0. */ + if (!(i2c_clk_rate / 2)) + return -EINVAL; i2c_imx->cur_clk = i2c_clk_rate; @@ -670,6 +674,8 @@ static void i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx, dev_dbg(&i2c_imx->adapter.dev, "IFDR[IC]=0x%x, REAL DIV=%d\n", i2c_clk_div[i].val, i2c_clk_div[i].div); #endif + + return 0; } static int i2c_imx_clk_notifier_call(struct notifier_block *nb, @@ -679,11 +685,12 @@ static int i2c_imx_clk_notifier_call(struct notifier_block *nb, struct imx_i2c_struct *i2c_imx = container_of(nb, struct imx_i2c_struct, clk_change_nb); + int ret = 0; if (action & POST_RATE_CHANGE) - i2c_imx_set_clk(i2c_imx, ndata->new_rate); + ret = i2c_imx_set_clk(i2c_imx, ndata->new_rate); - return NOTIFY_OK; + return notifier_from_errno(ret); } static int i2c_imx_start(struct imx_i2c_struct *i2c_imx, bool atomic) @@ -1782,7 +1789,11 @@ static int i2c_imx_probe(struct platform_device *pdev) i2c_imx->bitrate = pdata->bitrate; i2c_imx->clk_change_nb.notifier_call = i2c_imx_clk_notifier_call; clk_notifier_register(i2c_imx->clk, &i2c_imx->clk_change_nb); - i2c_imx_set_clk(i2c_imx, clk_get_rate(i2c_imx->clk)); + ret = i2c_imx_set_clk(i2c_imx, clk_get_rate(i2c_imx->clk)); + if (ret < 0) { + dev_err(&pdev->dev, "can't get I2C clock\n"); + goto clk_notifier_unregister; + } i2c_imx_reset_regs(i2c_imx);