From patchwork Thu Nov 7 21:14:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiasheng Jiang X-Patchwork-Id: 13867175 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 B58C3D5D689 for ; Thu, 7 Nov 2024 21:18:04 +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:Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=7uKO2TXaFtTXkQxrGMFy3dzEippfijU9bG+tCuCJOR0=; b=LGl+mJzq3echGyXKZVNG3FTYE3 ooA8e5TzSFxcBLzBlff9Gn4orjWkuzgfLRvaS220i+IBRSElwLCdrPhbI6LKRVzUyd5eQThKvLt0F 64CCYez55i/ffzmEkkvSwrjl9ct+/p1oUAW4M7da4U0utgyGAq7ALgAw1qG7b8vqzVPeKThRcaK6F K2b4E+a4k/DcscLejueRXxpjZKd4H2/K1QyhXGz2WdluCdz85u7JpBCd2B1XWpVLwgqVnUHq269Fo v2lybeshRnC81rOiaLu/g7/J4tDNmsOWrVURcTrRFY4g//RNAmixxLIzdWW+FfaDd4AdU+ieBFb3k fm0npcMw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t99t1-00000008Nu7-3Csp; Thu, 07 Nov 2024 21:17:51 +0000 Received: from mail-qv1-xf2d.google.com ([2607:f8b0:4864:20::f2d]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t99pr-00000008NNa-3l3A; Thu, 07 Nov 2024 21:14:37 +0000 Received: by mail-qv1-xf2d.google.com with SMTP id 6a1803df08f44-6cbe9914487so9091806d6.1; Thu, 07 Nov 2024 13:14:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731014072; x=1731618872; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=7uKO2TXaFtTXkQxrGMFy3dzEippfijU9bG+tCuCJOR0=; b=Vki3NIlql9oBs2+Bq8SXywpZlj4FnOBm/pZut8Zq4XzN9Vx5Yvy/FJmw/0Y6BKIqZd 71hIqrcK+Yi/rvupLLNm6YvsxPK5vqTfvkl3WdUjHeXDYH0WocoEkFTzAn565td/1jCf vY4Lc27zc2ANQSNXJFCQJNh8FTNljOr2qkGZU4YbPKjVVc+08HMIrnN1aIEMqnrVW2ii E0pfHWzzEIO3sH6EMOJVaUg10Rv/EP5JRinL4wmV83le+wt1JhdqpD4Wch14FncUPeGl 0ias9QW4ewmLI5jdXJFo3pPGbCnA8HiLqHdEvSzDPasN3ewvmrPTMQuNlDHhOXoG1h04 2CUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731014072; x=1731618872; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=7uKO2TXaFtTXkQxrGMFy3dzEippfijU9bG+tCuCJOR0=; b=Bn4CY3Sm0a0nFUvvcX4vgwawzLDU8et+b2HRxNwAzrcJQJEUvLR7YVUe7A7NMAZHlc Cal4MooKhB95H5g+dkXnbjZhOgcoH9rZFzU6X1qlin4Kdxul8vItpCgBWIysCn5qYzBE fnXNdqRFS7oYwFmdaoifsEPWTpYPkM2qlInHDnP9pDB3vlcFFnxYV2NRHXOyBP+w+s3W leb+d4qEAJq5F2HJ4cPAQADiRHHYQKJ2PLHuO7dNZvj9WXAi5bwgDvUzFlFjqngPuluP AIe067x00nwfRpxWMA5vn6CNsH154XjiU1Gl1cw7Qz0Swr66rX7X0bblstTY+MH4RulO ZTog== X-Forwarded-Encrypted: i=1; AJvYcCXh/OFVMOgOogkJgiHwBP7c9ky61daDLYPqylXtIvUWEVgJvBUalsG+o6aGaIDxyDkRRji15R5CPLdnCQUJlCc=@lists.infradead.org, AJvYcCXs5PMcdfmdp/fMltH3BqZbet9ZLcrGr0TcMSGmu4KXfLQRAZ7ONtXRUOvIZS6RRcFMfM/30TzC+2aVUys1TNaN@lists.infradead.org X-Gm-Message-State: AOJu0YxDuImRCIR5g/KvJPdk+Hlbimm2Y5kTymWRyJcd/Wvt2OcJ9vzd DVKnRf4VhI8u9hZ/PeNQgFSA7+c+d6HbfAMoz5gX5lX1PCOsrUVl X-Google-Smtp-Source: AGHT+IEQO315sJ58AjAImU5jNkUQnktZ/9GnYkEh96OypdQQhSv+PNXvH4Sz82UfLiseFX3Nn+MBsA== X-Received: by 2002:a05:6214:5348:b0:6d3:5af5:2a58 with SMTP id 6a1803df08f44-6d39e1ee70bmr5395506d6.33.1731014071767; Thu, 07 Nov 2024 13:14:31 -0800 (PST) Received: from newman.cs.purdue.edu ([128.10.127.250]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d3962089fesm11486116d6.61.2024.11.07.13.14.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2024 13:14:31 -0800 (PST) From: Jiasheng Jiang To: andi.shyti@kernel.org Cc: dianders@chromium.org, rmk@dyn-67.arm.linux.org.uk, max.schwarz@online.de, david.wu@rock-chips.com, heiko@sntech.de, vz@mleia.com, wsa@kernel.org, manabian@gmail.com, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, Jiasheng Jiang Subject: [PATCH v3 1/3] i2c: lpc2k: Add check for clk_enable() Date: Thu, 7 Nov 2024 21:14:26 +0000 Message-Id: <20241107211428.32273-1-jiashengjiangcool@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241107_131435_962079_343B9C57 X-CRM114-Status: GOOD ( 11.92 ) 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 Add check for the return value of clk_enable() in order to catch the potential exception. Signed-off-by: Jiasheng Jiang --- Changelog: v2 -> v3: 1. Roll back unsuitable dev_err_probe() to dev_err() v1 -> v2: 1. Remove the Fixes tag. 2. Use dev_err_probe to simplify error handling. --- drivers/i2c/busses/i2c-lpc2k.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/busses/i2c-lpc2k.c b/drivers/i2c/busses/i2c-lpc2k.c index 9fb33cbf7419..ea9831f34cd6 100644 --- a/drivers/i2c/busses/i2c-lpc2k.c +++ b/drivers/i2c/busses/i2c-lpc2k.c @@ -442,8 +442,14 @@ static int i2c_lpc2k_suspend(struct device *dev) static int i2c_lpc2k_resume(struct device *dev) { struct lpc2k_i2c *i2c = dev_get_drvdata(dev); + int ret; + + ret = clk_enable(i2c->clk); + if (ret) { + dev_err(dev, "failed to enable clock: %d\n", ret); + return ret; + } - clk_enable(i2c->clk); i2c_lpc2k_reset(i2c); return 0; From patchwork Thu Nov 7 21:14:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiasheng Jiang X-Patchwork-Id: 13867179 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 D0B7DD5D689 for ; Thu, 7 Nov 2024 21:19:47 +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:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=jOo8kzEPRGUvbYhKweLQJeBsbVaNvGh932XZf4KLPhQ=; b=bxGSsry9spNfG6wIRD0BUhMEyB Bzsn3vbab2WSof0Lay5xZfdwbRZkn62FxLNXqo3Qtb0kxWDTMZRzDoU59tGIdM9ZMwaEfEOvh1yGn CyIA1f5ekxUGLwOOEMsckQWqlOox7B3LO94Qbs2HzgC66SywDzqada4b2wVOVXxtCZ/Qd+bi09p3r D04bm8VH+gjIy1otPf47l1I6jmpkT7kWnmhAUI2HNqUw51FVUFlDLuX4Gig9wbeTjRPbCAKaeSKwv xfR5THJc+s4nDpdu5Iml1wB/h4GXuLhAOJo1rz1oRtmvAs+pnfsBQSREdDDU/R/Vums25XZP2ZlAi ByUoLFkA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t99uj-00000008O5B-30Ws; Thu, 07 Nov 2024 21:19:37 +0000 Received: from mail-oo1-xc29.google.com ([2607:f8b0:4864:20::c29]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t99ps-00000008NNk-0aW5; Thu, 07 Nov 2024 21:14:37 +0000 Received: by mail-oo1-xc29.google.com with SMTP id 006d021491bc7-5ec1ee25504so754116eaf.3; Thu, 07 Nov 2024 13:14:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731014075; x=1731618875; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jOo8kzEPRGUvbYhKweLQJeBsbVaNvGh932XZf4KLPhQ=; b=bq4rlyACnFa0Xe7tUIx9ou8SGXOSOt8nhtczOstpPYT0e6ygFbQf8AeNs6uMAw8d1p z+7LkqW6unWF3NQDWmawizpQM+DIHbeL4v/sWrUKfrP70w9WVoFZSZkrcNWv5pCLcaS7 9bP/i/wOTWVvNWRLUJd5K4XZaZ9a5fPa9PgIoP8+nqCEsCM7krx+Uc89SITh/7Que10m RBjG7AuvZekvq+FDNtnXvIXif+APLL+PcYAAc1yPuQfK1Hvd1Tq8uKfx2OQ07107/Xmp IAxrHcA4XhLDmgSJiRPHUmsKgjcznjhD9GBeeNrPkdpVA5N+v75ZTD9hKZdqKjlGRMOF uVWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731014075; x=1731618875; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jOo8kzEPRGUvbYhKweLQJeBsbVaNvGh932XZf4KLPhQ=; b=EG5dc+bjaPPGYy2ZSVFKdyfAMZuGKUPDPUQS/xnlhGzNm3JWuKTiZHIQS+R4JI6UgI pxat7xZTUsl2htRYtuErX3hThw4bJRl0BRc4qNJ/Z6UC/5jykNmJkE5mtk5GzcZPi4tv yvUucjuWvPiSitQZL0cerMWRQBLL13akBSASNqw9Dje4i7N1HgP8VD21ux2HRqCXUISy YQWeH4EyUWu+E9OomasRLakEREtkxHKznPhLPnOmQaysLf3eAW9qCab9VZsrMCcGpZdl gtFpcaXF5dulGL7dKMlcoo23DHW2puZ0cKOPW16jMoyE6ewdq9o7pUPx5NejwrFrEOi6 eXXg== X-Forwarded-Encrypted: i=1; AJvYcCWBrRWL3Z7KA3kP4V5pvMaM3VqEuI7JeMggGGgRZxjVkFyQocRCFVWwLLZ9/Mz/vJaqkEQ/wMu9m698aYf0oj2n@lists.infradead.org, AJvYcCWy1S6vQBQmJKiLkmDvDOQFdQ9p+MU0kVNDVESjnYPQbfcPPX27nvrUEYOmo59FdYq/TIfIFETkeNXWUPHuV28=@lists.infradead.org X-Gm-Message-State: AOJu0YxlzTCXzxXgki4pbC3Qs4GOhYG55qJhm5vudsZNwbNevpZ0oCas U8EPhJIIYb5cq631ARD8wxmJXropCAQC2NMR5+xLBPUS5MN42egf X-Google-Smtp-Source: AGHT+IGhY1N2hk3DoCWVBqOOz8Mayrp7EeXL93lHogS0TvaItsDXtOLZPyJv421K0nsnaCchGhGTMg== X-Received: by 2002:a05:6359:428d:b0:1b8:203b:db84 with SMTP id e5c5f4694b2df-1c641e749e9mr92914155d.4.1731014074581; Thu, 07 Nov 2024 13:14:34 -0800 (PST) Received: from newman.cs.purdue.edu ([128.10.127.250]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d3962089fesm11486116d6.61.2024.11.07.13.14.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2024 13:14:34 -0800 (PST) From: Jiasheng Jiang To: andi.shyti@kernel.org Cc: dianders@chromium.org, rmk@dyn-67.arm.linux.org.uk, max.schwarz@online.de, david.wu@rock-chips.com, heiko@sntech.de, vz@mleia.com, wsa@kernel.org, manabian@gmail.com, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, Jiasheng Jiang Subject: [PATCH v3 2/3] i2c: pxa: Add check for clk_enable() and clk_prepare_enable() Date: Thu, 7 Nov 2024 21:14:27 +0000 Message-Id: <20241107211428.32273-2-jiashengjiangcool@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241107211428.32273-1-jiashengjiangcool@gmail.com> References: <20241107211428.32273-1-jiashengjiangcool@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241107_131436_220737_3E6A046F X-CRM114-Status: GOOD ( 12.91 ) 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 Add check for the return values of clk_enable() and clk_prepare_enable() in order to catch the potential exceptions. Signed-off-by: Jiasheng Jiang --- Changelog: v2 -> v3: 1. Roll back unsuitable dev_err_probe() to dev_err() 2. Correct the usage of dev_err_probe() v1 -> v2: 1. Remove the Fixes tag. 2. Use dev_err_probe to simplify error handling. --- drivers/i2c/busses/i2c-pxa.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c index 4d76e71cdd4b..4a92c5386df6 100644 --- a/drivers/i2c/busses/i2c-pxa.c +++ b/drivers/i2c/busses/i2c-pxa.c @@ -1503,7 +1503,9 @@ static int i2c_pxa_probe(struct platform_device *dev) i2c->adap.name); } - clk_prepare_enable(i2c->clk); + ret = clk_prepare_enable(i2c->clk); + if (ret) + return dev_err_probe(&dev->dev, ret, "failed to enable clock\n"); if (i2c->use_pio) { i2c->adap.algo = &i2c_pxa_pio_algorithm; @@ -1560,8 +1562,14 @@ static int i2c_pxa_suspend_noirq(struct device *dev) static int i2c_pxa_resume_noirq(struct device *dev) { struct pxa_i2c *i2c = dev_get_drvdata(dev); + int ret; + + ret = clk_enable(i2c->clk); + if (ret) { + dev_err(dev, "failed to enable clock: %d\n", ret); + return ret; + } - clk_enable(i2c->clk); i2c_pxa_reset(i2c); return 0; From patchwork Thu Nov 7 21:14:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiasheng Jiang X-Patchwork-Id: 13867180 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 8676FD5D68A for ; Thu, 7 Nov 2024 21:21:36 +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:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=vtYJat2vwne5+4WJO2r1NKcoNFx7A4N4AD7ayp8QtCI=; b=I3GWGofi81TduZqSvTFwGJ3yFG cVPXEsiGKufLERhJEMlqE5MFkWiXkNZfpBhkhO/ciAL22sWXyoEdyLMVG8rcBJ6NXGZEKOlXYkq0x pCxpfdKl1AeEhYZnzQRfKxuY++O6KDCBGUmtT31+fuRMXpg09pKjwU/b5HoOeYOUUFAlFU/RM2Jnc CSaTEZuw+23Hzkw6H38iqoS96N9TIg0j4w/OQ2NugFJW5GbO4faDWct6AvEAvSjoIMQEFNKVNp6L+ h1qUT1qRB+wCzXKFLNjhiXMD77K86cn3/k7jLHJx8jjR9Jj/MzVmUHIEvdh7XveLS8sJFQdMqURQC D+Cd7p2w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t99wS-00000008OLR-3oPa; Thu, 07 Nov 2024 21:21:25 +0000 Received: from mail-oi1-x230.google.com ([2607:f8b0:4864:20::230]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t99pt-00000008NOM-2nOK; Thu, 07 Nov 2024 21:14:39 +0000 Received: by mail-oi1-x230.google.com with SMTP id 5614622812f47-3e5fa17a79dso1017299b6e.1; Thu, 07 Nov 2024 13:14:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731014076; x=1731618876; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vtYJat2vwne5+4WJO2r1NKcoNFx7A4N4AD7ayp8QtCI=; b=JB6sxk9Eju0xlJS8F+q1Hfn2/UdU10Ghi2NQbtVKYU0/0cR+Ic1P6RkAY7PjZa3vDL ueoKnLneL5WLaTC92bsaKRpR8SUbkXXQgz0bn7mdcHTgSXelDesKOPlvPVuciXPc4x5D AFLA58Y+bbtZ5Z6Jy1QlQpiyW5Ujj/t9ajjkgt7YjYzJiJlL45dHSwh/HXEJk04phnhv Zoovc+tDwlnV2/iec/2bg5xunLK2NhkUBcKuvDZtpcga9oeuDu1syUsV8abYFUI+zvrI YYx4zOEDioKveOvtNv+Rdq+KBhkcPPLbObVIkgchX0W7TWvmljWIahqiWCBH86mijLF7 fxsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731014076; x=1731618876; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vtYJat2vwne5+4WJO2r1NKcoNFx7A4N4AD7ayp8QtCI=; b=uBpDOyGAPzwp5MF0NjvPveh6ggZvmd/3HLUCWpL1csW5Kqxadxu/KyazVJl++R66vi DcLmETzQVHf06fUB8cJ+dG148J6xqX9bBowkc/VQwPZeyAjMtKGhFMqOGsQGciNXhr4T kt+ZOzUecM0TVS7YsDGZniJbs11ufR7E6yQioZazact2hRqDd1loHzHQTm6kTGMTxrc+ VxIB3kl8JXsei4TKfeBMzIk6EhYM/uY5seLnHUsVbxLjwi4G14aIVdboUgu16kmmB+Z1 G8XrNW14BTtH4HF2IQBH+NcMEnW1Ex/F5BdDaP3tCKoi7zd26+0FMdHFchR/fqkIrKJK 0KNw== X-Forwarded-Encrypted: i=1; AJvYcCVVlVukAECnLYzJ1D1b7QAblhbEjUxwvSsDbDWcsS3GWerwkDokEtF0Zp9PIKM4Bee4XuycbyiLEC/ba5UhnEk=@lists.infradead.org, AJvYcCVw6fSZX4+K7TPii7w+DGcBHlkyEi4jJ+EF6D5dGZaokywW2qVtPtqvzbLQtjOjpkNe6EuHkGZfKdGIyq1UsapZ@lists.infradead.org X-Gm-Message-State: AOJu0YwYNlFM8ouG9xKI03mX8/T5Q5tS+/N9yTENT++fEK585x96JIJQ hsp7y22E/8RcofgJbUnIXnALbZnAyADcz5YP7mLLHVvIR/tSGgZR X-Google-Smtp-Source: AGHT+IGHP0pu9JWTZVGvNEWya7gP+rkzPi0pM59LG1R+OZu7lEwHGebIcNHfjBTkDrWb+2m5YeySdQ== X-Received: by 2002:a05:6358:790:b0:1c6:12aa:a50d with SMTP id e5c5f4694b2df-1c641f81b71mr65221955d.25.1731014076286; Thu, 07 Nov 2024 13:14:36 -0800 (PST) Received: from newman.cs.purdue.edu ([128.10.127.250]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d3962089fesm11486116d6.61.2024.11.07.13.14.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2024 13:14:36 -0800 (PST) From: Jiasheng Jiang To: andi.shyti@kernel.org Cc: dianders@chromium.org, rmk@dyn-67.arm.linux.org.uk, max.schwarz@online.de, david.wu@rock-chips.com, heiko@sntech.de, vz@mleia.com, wsa@kernel.org, manabian@gmail.com, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, Jiasheng Jiang Subject: [PATCH v3 3/3] i2c: rk3x: Add check for clk_enable() Date: Thu, 7 Nov 2024 21:14:28 +0000 Message-Id: <20241107211428.32273-3-jiashengjiangcool@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241107211428.32273-1-jiashengjiangcool@gmail.com> References: <20241107211428.32273-1-jiashengjiangcool@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241107_131437_782448_C8A51058 X-CRM114-Status: GOOD ( 16.87 ) 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 Add check for the return value of clk_enable() in order to catch the potential exception. Moreover, convert the return type of rk3x_i2c_adapt_div() into int and add the check. Signed-off-by: Jiasheng Jiang --- Changelog: v2 -> v3: 1. Roll back unsuitable dev_err_probe() to dev_err() v1 -> v2: 1. Remove the Fixes tag. 2. Use dev_err_probe to simplify error handling. --- drivers/i2c/busses/i2c-rk3x.c | 55 ++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 14 deletions(-) diff --git a/drivers/i2c/busses/i2c-rk3x.c b/drivers/i2c/busses/i2c-rk3x.c index 4ef9bad77b85..0263ee0e0470 100644 --- a/drivers/i2c/busses/i2c-rk3x.c +++ b/drivers/i2c/busses/i2c-rk3x.c @@ -871,7 +871,7 @@ static int rk3x_i2c_v1_calc_timings(unsigned long clk_rate, return ret; } -static void rk3x_i2c_adapt_div(struct rk3x_i2c *i2c, unsigned long clk_rate) +static int rk3x_i2c_adapt_div(struct rk3x_i2c *i2c, unsigned long clk_rate) { struct i2c_timings *t = &i2c->t; struct rk3x_i2c_calced_timings calc; @@ -883,7 +883,11 @@ static void rk3x_i2c_adapt_div(struct rk3x_i2c *i2c, unsigned long clk_rate) ret = i2c->soc_data->calc_timings(clk_rate, t, &calc); WARN_ONCE(ret != 0, "Could not reach SCL freq %u", t->bus_freq_hz); - clk_enable(i2c->pclk); + ret = clk_enable(i2c->pclk); + if (ret) { + dev_err(i2c->dev, "Can't enable bus clk for rk3399: %d\n", ret); + return ret; + } spin_lock_irqsave(&i2c->lock, flags); val = i2c_readl(i2c, REG_CON); @@ -904,6 +908,8 @@ static void rk3x_i2c_adapt_div(struct rk3x_i2c *i2c, unsigned long clk_rate) clk_rate / 1000, 1000000000 / t->bus_freq_hz, t_low_ns, t_high_ns); + + return 0; } /** @@ -942,19 +948,27 @@ static int rk3x_i2c_clk_notifier_cb(struct notifier_block *nb, unsigned long return NOTIFY_STOP; /* scale up */ - if (ndata->new_rate > ndata->old_rate) - rk3x_i2c_adapt_div(i2c, ndata->new_rate); + if (ndata->new_rate > ndata->old_rate) { + if (rk3x_i2c_adapt_div(i2c, ndata->new_rate)) + return NOTIFY_STOP; + } return NOTIFY_OK; case POST_RATE_CHANGE: /* scale down */ - if (ndata->new_rate < ndata->old_rate) - rk3x_i2c_adapt_div(i2c, ndata->new_rate); + if (ndata->new_rate < ndata->old_rate) { + if (rk3x_i2c_adapt_div(i2c, ndata->new_rate)) + return NOTIFY_STOP; + } + return NOTIFY_OK; case ABORT_RATE_CHANGE: /* scale up */ - if (ndata->new_rate > ndata->old_rate) - rk3x_i2c_adapt_div(i2c, ndata->old_rate); + if (ndata->new_rate > ndata->old_rate) { + if (rk3x_i2c_adapt_div(i2c, ndata->old_rate)) + return NOTIFY_STOP; + } + return NOTIFY_OK; default: return NOTIFY_DONE; @@ -1068,8 +1082,20 @@ static int rk3x_i2c_xfer_common(struct i2c_adapter *adap, spin_lock_irqsave(&i2c->lock, flags); - clk_enable(i2c->clk); - clk_enable(i2c->pclk); + ret = clk_enable(i2c->clk); + if (ret) { + spin_unlock_irqrestore(&i2c->lock, flags); + dev_err(i2c->dev, "Can't enable bus clk: %d\n", ret); + return ret; + } + + ret = clk_enable(i2c->pclk); + if (ret) { + clk_disable(i2c->clk); + spin_unlock_irqrestore(&i2c->lock, flags); + dev_err(i2c->dev, "Can't enable bus clk for rk3399: %d\n", ret); + return ret; + } i2c->is_last_msg = false; @@ -1149,9 +1175,7 @@ static __maybe_unused int rk3x_i2c_resume(struct device *dev) { struct rk3x_i2c *i2c = dev_get_drvdata(dev); - rk3x_i2c_adapt_div(i2c, clk_get_rate(i2c->clk)); - - return 0; + return rk3x_i2c_adapt_div(i2c, clk_get_rate(i2c->clk)); } static u32 rk3x_i2c_func(struct i2c_adapter *adap) @@ -1365,9 +1389,12 @@ static int rk3x_i2c_probe(struct platform_device *pdev) } clk_rate = clk_get_rate(i2c->clk); - rk3x_i2c_adapt_div(i2c, clk_rate); + ret = rk3x_i2c_adapt_div(i2c, clk_rate); clk_disable(i2c->clk); + if (ret) + goto err_clk_notifier; + ret = i2c_add_adapter(&i2c->adap); if (ret < 0) goto err_clk_notifier;