From patchwork Mon Nov 4 21:43:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiasheng Jiang X-Patchwork-Id: 840649 Received: from mail-qv1-f41.google.com (mail-qv1-f41.google.com [209.85.219.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2213F1FA272; Mon, 4 Nov 2024 21:43:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730756596; cv=none; b=EzM5/ZTKUTlcXL9kMD4BGD1nkGG+H/hnb092VBMLy7oh8SVPyj4YuRhLTIGobEbSIi1DiHgXX38O/2RA+GYsJXS8i5mHtg2wqCICpIgUuAC0K5KNr5t5nAO/6r7XCIzg7WIsrLA4OT5hamCT5WuXwu4BuWNun2ZKCVHIql23mUY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730756596; c=relaxed/simple; bh=G5TtYDkJ/9/I8cZQy53k83kHp5eWxFTGnXpbMyoYplY=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=IhcDeBBP3dZkaQnQLtt1cBOhCOM3nfnUzPQaIJeMrzkTg4lwdoErCbtyq7aYT9OgI0P1CTyYM2MOK3pSF4pzl1FUsqJKxD9tApsAcSFszQofuNYxR/+MmrcsnMxlH8AlcO0y2ThATxiKUsZPMJoiJSEl4h9292myyOf1CGNM97E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=fKLVB1dV; arc=none smtp.client-ip=209.85.219.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fKLVB1dV" Received: by mail-qv1-f41.google.com with SMTP id 6a1803df08f44-6cbe3ea8e3fso33462756d6.0; Mon, 04 Nov 2024 13:43:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730756594; x=1731361394; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=/4tmB1crXrQeW2xb2p4HQOS59dYvDstelXee2aLIlks=; b=fKLVB1dVm0cEyKq1xikkuA2I1GlHmdXLvOWBQUOqGZkHORxFfGmACl/NLcXOPC2r2F mZtcy7RkqCETJDCoEiHvHloKm2GfJ+noJrUN4N78BSUvGLonAZllC5VKydDEtXT/8E3g nKHAi6X0YMowkqw8AGqtoGJG+JASNVXmgRFTTJ8gUZSfmpIGBJIiy/a3Gu1J3FLlqAYr O1Z1zL5WqyrO758/rxgOL1oLoDqIHFBBixBvyNXh5/uuwrKry/miYGSq5M80pn0ARvmj Ofk+Y5M9EXQxZ1xQLyRJbCfyO6/J/+VYm1L7v4rXvwU0vrByF8TFJk3Acl+vaOqmed5E Qriw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730756594; x=1731361394; 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=/4tmB1crXrQeW2xb2p4HQOS59dYvDstelXee2aLIlks=; b=V+2zz+K1FsEv2Rv2qL0PwoqPhapV6coao9GIOlPLct5jCxHT4B3607VcCSpYuknIIF zd75lD/Arsrnp6K9NxM/qRixEjqgw14O4q5INBnAIYPA9Qt9u8ftnPkO1xQe1cseLCT2 ykr47MUGXcZPied4Yl9gL5s8acIDPmBfERJCp7iqKn7AV2DN8WKSGR5AfwdoGxc5mBbR H1mWvz8CihNmVkfU6TA2mEvz8JW91ArWQ0xmfZvI3OIvpNPKiEfPgr5/9Pdrki+DTDKj u1rPc3dGJ1tgcGhFlH8cuVph+v8cfBGuw4fzBydiy7Ety12NqOaktxsnN0k6cmIFZg6k uzhg== X-Forwarded-Encrypted: i=1; AJvYcCUXlncPlrgaxjnii0JRXbVnhlYF9wlqMKcCOzF6NPTOduSx5rJ3QtYU7rChVmNgh7BYsGR3i4szWGRUmYAY@vger.kernel.org, AJvYcCWnWY6sYmhf5Nh9l/1Ufh9rvTnUkwk4MAMxEIJ8ETPgTCcZLpWBNdo58SOw2PorRJP4DN929EiAbAc=@vger.kernel.org X-Gm-Message-State: AOJu0YzMeWnAU8p2cd1QNJ1NUU0p66dYSOODFC+sHdpcVn8BS23h/NTe KPxKHU46yWDWXjdsfWq+aG2q3/tptmibn/nQM/jbGDZy1h2KQz/i X-Google-Smtp-Source: AGHT+IHiD08rBdxTtb8aWm9tjEu6W9aqyM2twM5OiMs1ouAVCkDkPquU7pdY0W4uFRX0AKoynB85Ww== X-Received: by 2002:a05:6214:3386:b0:6cb:fa1c:87da with SMTP id 6a1803df08f44-6d351b2083emr248567506d6.38.1730756593883; Mon, 04 Nov 2024 13:43:13 -0800 (PST) Received: from newman.cs.purdue.edu ([128.10.127.250]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d35415b1edsm52553916d6.75.2024.11.04.13.43.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 13:43:13 -0800 (PST) From: Jiasheng Jiang To: rmk@dyn-67.arm.linux.org.uk, max.schwarz@online.de, dianders@chromium.org, david.wu@rock-chips.com, heiko@sntech.de, vz@mleia.com, andi.shyti@kernel.org, wsa@kernel.org, manabian@gmail.com Cc: 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 1/3] i2c: lpc2k: Add check for clk_enable() Date: Mon, 4 Nov 2024 21:43:08 +0000 Message-Id: <20241104214310.6048-1-jiashengjiangcool@gmail.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add check for the return value of clk_enable() in order to catch the potential exception. Fixes: 3f9c37a0c9a5 ("i2c: lpc2k: add driver") Signed-off-by: Jiasheng Jiang --- 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 Mon Nov 4 21:43:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiasheng Jiang X-Patchwork-Id: 840926 Received: from mail-oo1-f50.google.com (mail-oo1-f50.google.com [209.85.161.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9D2911E5725; Mon, 4 Nov 2024 21:43:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730756598; cv=none; b=TPKQOp1NG0WP0/kMk/UbHvY2hJfx+pglfAmQ+y3apzw7OAZKAWpdk7REzCHvqWUiCOMcBbi8kPobinlvApxI3leTHzUI+/OlX4duly6CcuUS0N+wSM7E/7kRVq0fhpLvmDLAeaZktkBqNsFdNtUUUJkt3U0ggqSMV9uIZzMX55M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730756598; c=relaxed/simple; bh=XrxCgXP+ydeQT4DjN34U1VCFZbux1vFruYBUaV2QmVk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hU19vSvJQpb/yuQbQQIoESrLKRDQpM9aVSRpa4TCiJzuy39CL9+A4TJTBKsEvP2MbedeFEXn4gpq4wDO5bk3HJhEvED80sXrE8DLO+8mlO2QKuUrgd0DwRuvWO52fTtbTYqPSZkrSa4Uo8wXDCHSn+OM4DhpV6uYX7N+BQuu0QM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Vu7wTK+o; arc=none smtp.client-ip=209.85.161.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Vu7wTK+o" Received: by mail-oo1-f50.google.com with SMTP id 006d021491bc7-5ebc27fdc30so2518069eaf.2; Mon, 04 Nov 2024 13:43:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730756595; x=1731361395; darn=vger.kernel.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=qOLycEB3fTB76jveJ6Ec3et2DfKHvs/Gj7ofAidlU2U=; b=Vu7wTK+obTUTYm0jXAUoSn/W7DWL5G4LOFSz3A80IUhV4neB+5oMGiGo+B4TYJEtiP 5V1m9pRdoa+0IJbW2Q9d0IoOwJMxt3Z1Qef712sSpg/mP0NyaSbo0dVMgN2It7nE6w2V aXzS+fxMYfzPUvJkEUxSy1Kf1Z/Bj5i7DkdylP1d6QM13aYZp+yTUxgys1qGQ4MsOFnA bOo7zeNzrntG43AYUU3UBID5Y10Kqrf01d9HNeGk8C7jEaIdIZn8TaCsx4HHXRBSJzVk b3EcUtvozItb3QxofBIjB63kinntY13kU5+aOjurGTcN+cglgsZ2Y4Sh4033vJhW/Zka wntg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730756595; x=1731361395; 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=qOLycEB3fTB76jveJ6Ec3et2DfKHvs/Gj7ofAidlU2U=; b=EBgVaImgv8Rr12t74wgQVPBPRgmAQAiz2bilmbbz9AFZxyOxl/AEYgdGLsKn5etkoZ iG3g5EkJICR9/c7nTgYEMRvBufeEMzcbma7WKebCrW27e1z+IKRyyA2thBJJM48jiAR5 FbAC65sLVeKMqWd4AmxFoFoSumTlzOfPpt/GBR4B8FFOgZFol3SAppgAtvZG952xOEh0 PTuHE8IxYQ5HFa9PFzeflu5twNdQ37jxVZN50YZa2/hGv40raJyMwDFv3A0MAn3uXebQ WJesF/g6siszqMCXfZpTWPiT3OIYoTujk81QJYv4VIT0kOHzUgypyN33uXiDtiNrvqm7 /UBQ== X-Forwarded-Encrypted: i=1; AJvYcCUXx0DnlxgVUSiGcbOdLOTJdpBfGwPzv2O7E5xXl9KjG+SDkWetfAxTASjHyI13SVEoJAMhxmslgl8=@vger.kernel.org, AJvYcCUeP8k22X1ILqsXU5QL7k5ChPWuFFWOOHHxKvaXHSjzQagmEqBtqEUuAJoLKYBYYcSsMeJtJ8cQfJ+usdHj@vger.kernel.org X-Gm-Message-State: AOJu0YwTPRRYAedRh5iVURP+1Iw4iD++f16q181g6PpSf+I16p4PcHG+ 3QYi9iGfM2+4tSN/NmGeud567BxSXPTXQWld6QQIwGwIqz/vXnT/ X-Google-Smtp-Source: AGHT+IGnt1DbQccv8yv6iE45XBrqGyCFkNPY8U/R7NDQnyLk4H54QS9Fm7w3bkWhRyMLeNLeyX0P/A== X-Received: by 2002:a05:6358:7254:b0:1ad:10eb:cd39 with SMTP id e5c5f4694b2df-1c3f9f7979amr1635893255d.26.1730756595525; Mon, 04 Nov 2024 13:43:15 -0800 (PST) Received: from newman.cs.purdue.edu ([128.10.127.250]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d35415b1edsm52553916d6.75.2024.11.04.13.43.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 13:43:15 -0800 (PST) From: Jiasheng Jiang To: rmk@dyn-67.arm.linux.org.uk, max.schwarz@online.de, dianders@chromium.org, david.wu@rock-chips.com, heiko@sntech.de, vz@mleia.com, andi.shyti@kernel.org, wsa@kernel.org, manabian@gmail.com Cc: 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 2/3] i2c: pxa: Add check for clk_enable() and clk_prepare_enable() Date: Mon, 4 Nov 2024 21:43:09 +0000 Message-Id: <20241104214310.6048-2-jiashengjiangcool@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241104214310.6048-1-jiashengjiangcool@gmail.com> References: <20241104214310.6048-1-jiashengjiangcool@gmail.com> Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add check for the return values of clk_enable() and clk_prepare_enable() in order to catch the potential exceptions. Fixes: e7d48fa2b5fb ("[I2C] pxa: provide late suspend and early resume hooks") Fixes: c3cef3f3c07b ("[ARM] pxa: update pxa i2c driver to use clk support") Signed-off-by: Jiasheng Jiang --- drivers/i2c/busses/i2c-pxa.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c index 4d76e71cdd4b..1118a7f5c6bf 100644 --- a/drivers/i2c/busses/i2c-pxa.c +++ b/drivers/i2c/busses/i2c-pxa.c @@ -1503,7 +1503,11 @@ 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) { + dev_err(&dev->dev, "failed to enable clock: %d\n", ret); + return ret; + } if (i2c->use_pio) { i2c->adap.algo = &i2c_pxa_pio_algorithm; @@ -1560,8 +1564,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 Mon Nov 4 21:43:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiasheng Jiang X-Patchwork-Id: 840648 Received: from mail-qv1-f50.google.com (mail-qv1-f50.google.com [209.85.219.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4877E1FDF88; Mon, 4 Nov 2024 21:43:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730756599; cv=none; b=NkgqHxVB40JF09FJBgirz7lTnqyizXwUWxcfnHPF/LAZj1xWJu4ipTvp1lKZ/Loc1+FvZbZzKhawgPNEMiWb73M9Qb7kfZf94maEmU1XhjwPC2Do8uwA6KyV8wqa1YP9OL2rA5WeqB2Esrhtz3mPmXZlr0mNTgUFvanjGroH4YE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730756599; c=relaxed/simple; bh=bpKFPPtC1GStj4J3pND2QCsA8ppdzq3JzH/A/uLN4i8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=c2dQWu/I5Ow58v/SJtm1uNZbeQrpm1AiVZN168Wzu5Oim4CHEBluS9wPvc5aMfBg9DjK//K/MkCksIJq5mROXCCLPzdQQSM8Sg/xU6DTQJUjl55ElraOWHCYzvbrmSiRaDVJkBOdJS+FXYe3alIZek7MEt5u0wZ0k/YP8ajelBM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Rrsfwb9l; arc=none smtp.client-ip=209.85.219.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Rrsfwb9l" Received: by mail-qv1-f50.google.com with SMTP id 6a1803df08f44-6cbcc2bd7fcso31966156d6.1; Mon, 04 Nov 2024 13:43:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730756597; x=1731361397; darn=vger.kernel.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=gpEshnq6i6G+Np3ZVcF5ef21yjGyMRFFgjDXZD1qG8A=; b=Rrsfwb9lZzgj9op302JbXmVOnY/1IrettQ1r0gkhdHz59QYUFmwLwsWzBW37dI9crx JNln9N4TR1K/wO+6lizrw/HwjZfFuXg8XkpbfulvWqQeRW6GA84mG5pu/zDEk1NxNMJb udn+6vWhOTgQDFCOCB5y44VsSTHjA0WeDXY3/ilxQHmi4cksd1wB9A85ZoQMXNCkrsFS uaKbh7ButvmSNgaiSr8fjIhdHoss43tlPI5VSz+amJvhjn/VVk0Ns2ymkj24UlS8F1g8 h7IKepUPQL8vNpjSRFPTSvnAA/eL5Ekj3NZcPjynRURQ05FCPsMSHGAJMVw8vqdR4sgd sOrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730756597; x=1731361397; 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=gpEshnq6i6G+Np3ZVcF5ef21yjGyMRFFgjDXZD1qG8A=; b=e8tF7PYE+is+wvq6hHs7iAIJxRZyJST4+e7vD5ecAyC3tl/nadZAsEThgwYU2vaLN3 Yzky9BJ+UtWdONaIEDeAr/1Uv8mm1dUCYPKvB1iF4qyc0LnFx6MXEWThtfz1UrWy3S2p tZjJ55tHIcfYG3nTftZiZ5eDM3jMx3u7Z1HM00raxwSt+KnsIvS8PQnUv9poDiLuBvI7 OZDuXdV+xy51rD+HrSrxHXYF2vkbdiqGNdv9clvygmih0acoCel6OVYjlDH16GAKzhZC 9L7j8/bVslVz0VglIfWyf4X8y5UcNIihsU/N+KiBtocyVtipx1FQTr+TZBY96JB/FxpS UYLQ== X-Forwarded-Encrypted: i=1; AJvYcCUcKWeASx9zAAmMC09e6sFsDOqc48AEXeygf5thGiI3M9mGR4FyiaD6sFd7CIP7K3vPUssEc3QvGLw=@vger.kernel.org, AJvYcCXvbtyiKOT4xjTlCkO9AHjGiWJi2JJEu2durEgZh9oQl/2+6FhHdkIWCKGkeUNDYr6EDvd/sL05rgcPR730@vger.kernel.org X-Gm-Message-State: AOJu0YzzeeLmCzV0MFcebKXCFJaUq1MyTQjhQWRKQJ5krOTluYLhjhzE RRH2IDkhtoaijVVcBDmbnW1BzpbK0Xq+hf8SBP5PYdW8zFLXN9l+ X-Google-Smtp-Source: AGHT+IES5Vzl7DJKtNHPJ7UmtrOwkZwfCRkFo15pFheXgrIEAUHkNDpzR2YA54jau7pQhc5lYfGEsQ== X-Received: by 2002:a05:6214:5f01:b0:6d1:7854:ab49 with SMTP id 6a1803df08f44-6d351a8f23bmr277872066d6.11.1730756597159; Mon, 04 Nov 2024 13:43:17 -0800 (PST) Received: from newman.cs.purdue.edu ([128.10.127.250]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d35415b1edsm52553916d6.75.2024.11.04.13.43.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 13:43:16 -0800 (PST) From: Jiasheng Jiang To: rmk@dyn-67.arm.linux.org.uk, max.schwarz@online.de, dianders@chromium.org, david.wu@rock-chips.com, heiko@sntech.de, vz@mleia.com, andi.shyti@kernel.org, wsa@kernel.org, manabian@gmail.com Cc: 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 3/3] i2c: rk3x: Add check for clk_enable() Date: Mon, 4 Nov 2024 21:43:10 +0000 Message-Id: <20241104214310.6048-3-jiashengjiangcool@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241104214310.6048-1-jiashengjiangcool@gmail.com> References: <20241104214310.6048-1-jiashengjiangcool@gmail.com> Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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. Fixes: 7e086c3fc2df ("i2c: rk3x: add i2c support for rk3399 soc") Fixes: 249051f49907 ("i2c: rk3x: handle dynamic clock rate changes correctly") Fixes: c41aa3ce938b ("i2c: rk3x: add driver for Rockchip RK3xxx SoC I2C adapter") Signed-off-by: Jiasheng Jiang --- 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..a4662b0dbd8c 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) { + dev_err(i2c->dev, "Can't enable bus clk: %d\n", ret); + spin_unlock_irqrestore(&i2c->lock, flags); + return ret; + } + + ret = clk_enable(i2c->pclk); + if (ret) { + dev_err(i2c->dev, "Can't enable bus clk for rk3399: %d\n", ret); + clk_disable(i2c->clk); + spin_unlock_irqrestore(&i2c->lock, flags); + 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;