From patchwork Tue Nov 5 16:18:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiasheng Jiang X-Patchwork-Id: 840925 Received: from mail-qk1-f180.google.com (mail-qk1-f180.google.com [209.85.222.180]) (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 4FBA61877; Tue, 5 Nov 2024 16:18:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730823506; cv=none; b=EXb74kaue+wyT+u4bAa56esBWT966f3ka50BPngM9SOpG63xk2Mun3TmBLLo9wVbFdlTZ+mydEY135mY7wjynBs4ypQsbUTzbg8MT5NZNSpZ2wrWCXM348YPW3VcP1gj47UoQgwirsQNU6rxm56yZNXkO0RvG6S8J3Jh7heSWNo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730823506; c=relaxed/simple; bh=z9s+hsUVJLqCYkFiFYgtd29iDUGXpufvXpuuTVOhtfM=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=dWkFjMddHWljr24bc9n1IEwc3XMOCPRrHO7JwFMAROWnwDgdDqGMqFH9/1Ki/UEWzKPohUmaibOzgR2MsgdJWV60ZTSREG6qx0Owsxt1h2xagK62IRCG1R7qj1sadoAkjzZ7ZGTPhH5aoqybXs4BTe08NTDT6pLdCywd3NGWn1A= 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=eXZ7PTD6; arc=none smtp.client-ip=209.85.222.180 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="eXZ7PTD6" Received: by mail-qk1-f180.google.com with SMTP id af79cd13be357-7b15467f383so397314585a.3; Tue, 05 Nov 2024 08:18:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730823504; x=1731428304; 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=KmtWlz91TJSK4h5e5cNQt2Ayuv3I7VTg5EZ5rZ7D4Fs=; b=eXZ7PTD6V2fWt4xwCKfZ9aTAe301oBm5dCJkmA41na8e7u5EkjxKn5U96IcSTmt9KM mA8opAwf5K/28wEdLR0Rwgyh8JE9JNegtWTS78aPOtSsf9pM8BdTBvLCjLuQ+l28rWvj AOWkg+JR2tVGoApL9QNLMZaq93mcEz15KckqACDdvm7oZUIuH/F/9OhLbZ2jX7UwU21r vch0WAbYFlPxL0JUxm26KoV4rWqBjfQYLJz5LjdIL1iqWTKHfCH/a0DB3F2odaWzAlbt z2uchjHm/8+ysjxIyykjktj3ThRZ/024LH49wb5G0vzUusaU/aC36bwf/PSM3TG7tsUj FQIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730823504; x=1731428304; 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=KmtWlz91TJSK4h5e5cNQt2Ayuv3I7VTg5EZ5rZ7D4Fs=; b=UDzeWMqKzMQWYQl9AhdzS+uayUCL7TfsgivWBa+kgSlEuXKUd8TUFlmYLNcr2a7YqQ Ckpk+M01efbBolVN8jSiQWae+X+c7iPboRgVi7wRlwNl8Hbl5sblH7ahGxIGM+qpgDlY US8HwBapZHmottCjuIt2hlxaG0kfYmvNiCn3eWlL0U9xX7pI2i+el6zemRduK6mVDA0P Z6QhoYvSYyXAbb//tpyUpGjOhsflOHLNNH3SOo0L2eFYOS7ohSO9VkkwmDJ0Bnt56i01 TGvdbjkAlalToVAR7Eq1ZkL9B+dy6/ScWhfTZLgscIYN0wOuxAHDlBbk+0AC5qHP9Ue3 OXcQ== X-Forwarded-Encrypted: i=1; AJvYcCVoV7qrnua9E+WOEeGVWI18yK1F0psokkv2YWlcdPDDkdWuPiEuiHCdPOk72JG1Ze0KOuYBYAGs9Mc=@vger.kernel.org, AJvYcCXlfYT1YC0tdXcUiWK4RR2KmJntao63/zJy8egILXfdz0u8cqDd2FGvxLM2pWjxzJV9h8w5a+6W7z8iNbWM@vger.kernel.org X-Gm-Message-State: AOJu0YyJjazJw7hcNc7E4XNrJ1u10Gzp8hjeBZPB4fV5cl0MoPr7Wnum 4S0BTb2EFOKi4WHRVfFsHFk4kof1vHIHQ4MEskPA5cH6vMXXY148 X-Google-Smtp-Source: AGHT+IFeexANrtepr8tFxuvgULw0OpAvbMZOzidMyaWEF29zaJWbq8+xGIA3j9ZNrjvW8hCKk2crvg== X-Received: by 2002:a05:620a:4608:b0:7b1:4d3b:d618 with SMTP id af79cd13be357-7b2f25529e5mr2568975885a.57.1730823504072; Tue, 05 Nov 2024 08:18:24 -0800 (PST) Received: from newman.cs.purdue.edu ([128.10.127.250]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b2f39eb14fsm538010885a.7.2024.11.05.08.18.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2024 08:18:23 -0800 (PST) From: Jiasheng Jiang To: andi.shyti@kernel.org Cc: 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, 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 v2 1/3] i2c: lpc2k: Add check for clk_enable() Date: Tue, 5 Nov 2024 16:18:18 +0000 Message-Id: <20241105161820.32512-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. Signed-off-by: Jiasheng Jiang --- Changelog: v1 -> v2: 1. Remove the Fixes tag. 2. Use dev_err_probe to simplify error handling. --- drivers/i2c/busses/i2c-lpc2k.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/busses/i2c-lpc2k.c b/drivers/i2c/busses/i2c-lpc2k.c index 9fb33cbf7419..0fe7d4421a31 100644 --- a/drivers/i2c/busses/i2c-lpc2k.c +++ b/drivers/i2c/busses/i2c-lpc2k.c @@ -442,8 +442,12 @@ 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) + return dev_err_probe(dev, ret, "failed to enable clock: %d\n", ret); - clk_enable(i2c->clk); i2c_lpc2k_reset(i2c); return 0; From patchwork Tue Nov 5 16:18:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiasheng Jiang X-Patchwork-Id: 841192 Received: from mail-qk1-f175.google.com (mail-qk1-f175.google.com [209.85.222.175]) (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 31F6717C22B; Tue, 5 Nov 2024 16:18:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730823509; cv=none; b=KvOShNlJ1Uo2kicyx9s7YlQDi08/gUgco650btcDgqT2giLGmuLjo9Jf+M0n3Oy39RbZb8AJHG6DtpGcxBrYScEIKUxZEpn5zlS6WGJyKeieh7YCamEdj0ku2yErYFhMvDMEV6/VRVA4YjJS87Xey1f1v/u6bmcZRdjWsdDDrgE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730823509; c=relaxed/simple; bh=WZtVn59iDVkO73iASai27i+jcw5hLgkhpFYsg1i5DJ8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Jv0kGGY5H+e4vqFPvqOKpufTnpwuYRtcWrl3ejHYdVY+k1vcxVTZz6T8gFtRpF3CtKFf31Zn01vjwM8kuH8vXJ9jBkbURDhhm/b3Dd+Ey9Dk+6C1jGx7krpNTclLET85JrRyVi5zPxN9oM5m+Jy8M45NbtZN/LtuQg8WGsJCZ3I= 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=gkhHCAWy; arc=none smtp.client-ip=209.85.222.175 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="gkhHCAWy" Received: by mail-qk1-f175.google.com with SMTP id af79cd13be357-7b15416303aso411596785a.1; Tue, 05 Nov 2024 08:18:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730823506; x=1731428306; 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=eXGcEW/yKJ2kT/lKQoK+ikV2KsFoei/F8kGwDlFWQO8=; b=gkhHCAWyw3e7Cwg117zMwh4toYmFs221xfAm+fE3LfvSOVdnZqd3JwSPKJCA+KBVxZ kReUiGj23oMxUXrRSqpeyyufj7kXP+9bsqVakBaEH8QGt+CPNd2i1KNNrPrWsGiVb7Ql 7vHAQ8/vRSdNRx9cEIwu1eVLmx9mcw2jF/xDojS6YPmQXMHZE+Zicv+TTYlQ8IYaMrhW e+AoSY5kynH+4UniRPB1xK8ncTw6e7t6wiP6Lgb0XZW18a4JO+2rcdljB8FZhp4Qujtk SGBG9S+f9VfwmYiuh5H3Fo1KyKFmoSWEWR3eucyHcRtkxCW0159n+QxZx5CnLAzz7INa SEmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730823506; x=1731428306; 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=eXGcEW/yKJ2kT/lKQoK+ikV2KsFoei/F8kGwDlFWQO8=; b=Mf3iCOqSE3uTvwXGUTHN8iOB4KiHnZGBdPJnHSwZZxh50l5dtb93t2C9ZgHcnea6+M rWBjjtXOQt3iXNCgcP0gcRTE0bNeIezXDr9IvmvGZ/D7+iPqSa+vl+5jod3CF08k2VmM A68ZIDomDIjAMR3bgKEhxU+ja0kgD/RM+nsv71FFn1/oPU6k3Q/i8621+slpCY+nMOXB tmWfe++Kn4FQdYjtN/4HEIHxDEeiWviDM6JnNg8Ou+FtT/kVmG9C42ciS+4DPBRq91VR 327t25IvC4reHWY1UaKrh5nbg0Xok0RetiRQSo0e+a59sJX5ylJRl3UwYE3ekGlCZVFQ yKnw== X-Forwarded-Encrypted: i=1; AJvYcCWEDGXIjTHaL8iMxLL1TAgJXbHDU1anCYKlXsp+WwohPtYBoertqcgHZvqGSut7biex9YS1z2K873I=@vger.kernel.org, AJvYcCXhA59Ccb0N04taRBlNs/mTyciqv0BRHfwb2VGsu3msJYWVy7OdeFzGaijlxMbsOxtanXeoTkz2ugn1G9LO@vger.kernel.org X-Gm-Message-State: AOJu0Ywn65igVIsvbCaS+/T2phQi85Q6oP1PraHm1n2VQ1Wlnc6jmq6k hlLOnzr8s/aWc+oSrbpNJU3BKSOfeZfyL9Gfg1H8yyJfYeUFQ0Ph X-Google-Smtp-Source: AGHT+IH/TVTagDdBicU9q7qr8NhSf15bW+aAQAdd0pCb97OHGnCjFbeCAMwnLUwjAeS4tg6AWJHmHQ== X-Received: by 2002:a05:620a:4492:b0:7b1:52a9:ae15 with SMTP id af79cd13be357-7b2fb948de3mr2387592485a.9.1730823506107; Tue, 05 Nov 2024 08:18:26 -0800 (PST) Received: from newman.cs.purdue.edu ([128.10.127.250]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b2f39eb14fsm538010885a.7.2024.11.05.08.18.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2024 08:18:25 -0800 (PST) From: Jiasheng Jiang To: andi.shyti@kernel.org Cc: 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, 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 v2 2/3] i2c: pxa: Add check for clk_enable() and clk_prepare_enable() Date: Tue, 5 Nov 2024 16:18:19 +0000 Message-Id: <20241105161820.32512-2-jiashengjiangcool@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241105161820.32512-1-jiashengjiangcool@gmail.com> References: <20241105161820.32512-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. Signed-off-by: Jiasheng Jiang --- Changelog: v1 -> v2: 1. Remove the Fixes tag. 2. Use dev_err_probe to simplify error handling. --- drivers/i2c/busses/i2c-pxa.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c index 4d76e71cdd4b..0ee6fe83de40 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: %d\n", ret); if (i2c->use_pio) { i2c->adap.algo = &i2c_pxa_pio_algorithm; @@ -1560,8 +1562,12 @@ 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) + return dev_err_probe(dev, ret, "failed to enable clock: %d\n", ret); - clk_enable(i2c->clk); i2c_pxa_reset(i2c); return 0; From patchwork Tue Nov 5 16:18:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiasheng Jiang X-Patchwork-Id: 840924 Received: from mail-qk1-f175.google.com (mail-qk1-f175.google.com [209.85.222.175]) (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 0182D17DFE8; Tue, 5 Nov 2024 16:18:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730823510; cv=none; b=iMrnml4xQxfUNnMb3SAQeLm+bzlepUNiQv05nsKKo2SuHI8PFf9xH/91zFRyAHAQ3hrO07UD71iPhOAjufE8hOmj10MikhdNftE8837JDUCwkHOhrNySisKa4vR/1NroVac2A7M2dTn6yDbRjZUQmuNMnmFQVZeHet9LpLxnwi8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730823510; c=relaxed/simple; bh=CNx5+P8L3AbdA637G48DT+8HgcBVx2RQ5y1gvQK3YGo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WDuLNEvhWc9lZo52Ac/o6XH9/6o7n22Of3l+scT8Tuoe2iQqWz8+udYrsLidcUzCdhBKB0tbp9+i/ajlci+GfvMOtPsB4aLwv4djSuRYAx+RJyd1bdQsGkRHl/HPjjXAXXC3fVGnPjgvFTL3PDRTfA3OlY+2BNmZhmaLfmPWK0Y= 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=OG45trwz; arc=none smtp.client-ip=209.85.222.175 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="OG45trwz" Received: by mail-qk1-f175.google.com with SMTP id af79cd13be357-7b155cca097so446460685a.1; Tue, 05 Nov 2024 08:18:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730823508; x=1731428308; 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=rZsBpzkk5eIxxCoFTUQlG8fOz3VfVWVw0fc2odhFnds=; b=OG45trwzN+h+SCWuKJD+yeWXl2uBxtlkawJi8dQJIHhRStRwZNmxCvwxBcOyeNirJq KCY9iTEOtmYAow9gXylSpsAPZfcn1UryBIoX0TVEM16RNqb/D+3P9wEvt7Tq3yzLIwoD I8LatHSRVeh415r6qTJUzM2+PToDqpX9edY+ROR9Z2SPYVQ32rEyVuoTv6y7VrMJV6+I ApCZjLsyPdqV02DO86BNMp2t4w/OOED9AxtrEDlR78Pg3TSxyy9OlYUxYdrtoY7iA2RH 5+8hfyCltxhAtbY1i6MvbT77HsyxoiD0U7nbMyuvsc+sm5P/cjh1Nn1ofx/aQY4ruVlS QK+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730823508; x=1731428308; 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=rZsBpzkk5eIxxCoFTUQlG8fOz3VfVWVw0fc2odhFnds=; b=W9EixnIyLfGjahwEUzbaflhwpa6I6dwCOrL21yH/UHwSPN9/QRXcvlv7W8+PwHzvn7 m3vfBcNa+s7R02rUQn4xLX2945PCxspOCypqQRknyo9cy4DArqUSqbGkFlG0mWMX1PEi 4Rft8BrD874TOTW4W+6cDuJz+5uA95TCji664s3XWo3453DQizAWNtArUroZNgd460gs zeXfWPBVHytmHFftVsjVCHnGgXDqTqGhRmdpYuerVVVcc9IT1YX2WjZn3NUxUUuvOQHh psoDGiEWyW93Hx3Zguu1zJDRtGNoV70p/tBjU+W2BEOcoIiS/e6HEZU4J34iXA14aLs8 B3IA== X-Forwarded-Encrypted: i=1; AJvYcCWB3NeuhZIfIoibwGZuZ/HKBrE59Dj7rjbxG7G1LQ9R8WgMOeZt/seAM+4P1feOPWn9ZXcYXo55n/w=@vger.kernel.org, AJvYcCWiPczRWOIfZ7kfCFQpJErk7efncDNlm9B45uc+oamjyRjmGyzc2hnSo8glNPpRkr77ybaAc44LS2M4jaDS@vger.kernel.org X-Gm-Message-State: AOJu0YywqsoJ5a+fjGUPM5bbH71cDsZzx/W414tDsEycfFvbl93gmvHC gNtXF0bmxJMbnAtxkIGEzGDr0dts63TAkXQa6aLdbYIAWJ0HQeoa X-Google-Smtp-Source: AGHT+IGQEeuVCyhghtqvJgTQQUezecC0Efl6QzEbppiW669eVn4FBMz1WOBfVXc/9kFFbFVBKkX7wg== X-Received: by 2002:a05:620a:284b:b0:7a9:c129:504f with SMTP id af79cd13be357-7b2f3d3999emr2948846985a.23.1730823507790; Tue, 05 Nov 2024 08:18:27 -0800 (PST) Received: from newman.cs.purdue.edu ([128.10.127.250]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7b2f39eb14fsm538010885a.7.2024.11.05.08.18.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2024 08:18:27 -0800 (PST) From: Jiasheng Jiang To: andi.shyti@kernel.org Cc: 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, 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 v2 3/3] i2c: rk3x: Add check for clk_enable() Date: Tue, 5 Nov 2024 16:18:20 +0000 Message-Id: <20241105161820.32512-3-jiashengjiangcool@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241105161820.32512-1-jiashengjiangcool@gmail.com> References: <20241105161820.32512-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. Signed-off-by: Jiasheng Jiang --- Changelog: v1 -> v2: 1. Remove the Fixes tag. 2. Use dev_err_probe to simplify error handling. --- drivers/i2c/busses/i2c-rk3x.c | 51 +++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/drivers/i2c/busses/i2c-rk3x.c b/drivers/i2c/busses/i2c-rk3x.c index 4ef9bad77b85..57c2d37fc7c3 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,9 @@ 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) + return dev_err_probe(i2c->dev, ret, "Can't enable bus clk for rk3399: %d\n", ret); spin_lock_irqsave(&i2c->lock, flags); val = i2c_readl(i2c, REG_CON); @@ -904,6 +906,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 +946,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 +1080,18 @@ 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); + return dev_err_probe(i2c->dev, ret, "Can't enable bus clk: %d\n", ret); + } + + ret = clk_enable(i2c->pclk); + if (ret) { + clk_disable(i2c->clk); + spin_unlock_irqrestore(&i2c->lock, flags); + return dev_err_probe(i2c->dev, ret, "Can't enable bus clk for rk3399: %d\n", ret); + } i2c->is_last_msg = false; @@ -1149,9 +1171,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 +1385,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;