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: 841542 Received: from mail-qt1-f172.google.com (mail-qt1-f172.google.com [209.85.160.172]) (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 EA9111EC015; Thu, 7 Nov 2024 21:14:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731014074; cv=none; b=iyDnUIj7OyOtD+kQ+tI4b7FvK/OZSmg6vD620beq6T5Hprwu7VQy5JExWAmnRAgyCcSplgk++Gpj975iv/PByLRFTpFwg9WAW3Pgnx+MKxZl8Q+EFb0kGbri6LUE46Co2l1ZZrk5LDtDSHVRHDGIKOreBjy1I2zMeg+gg0bqa+I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731014074; c=relaxed/simple; bh=pqjgTpcgdJf0vXPdIAuto0LnqO8V02lIDQngJ9eq3fE=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=cp4dkBcEpiOT2ffqaFLUxGlBWjKi/aunnLl7pMizzosJqFqZvGaH30A9n0Sg4S+U7eh+cw27YHViMu/70nO1093ha6EthkHy4jLTrrC5MRHZfRHMJYqUIcj76PesexjBH7f1hotzB+mbXzCu8oDeWF0uTGrLLrIhjzuBgXOM1wM= 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=ddgLfsBk; arc=none smtp.client-ip=209.85.160.172 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="ddgLfsBk" Received: by mail-qt1-f172.google.com with SMTP id d75a77b69052e-460ace055d8so9033361cf.1; Thu, 07 Nov 2024 13:14:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731014072; x=1731618872; 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=7uKO2TXaFtTXkQxrGMFy3dzEippfijU9bG+tCuCJOR0=; b=ddgLfsBkYYM9udRleiXoSEuqem6I4Y0bleO/M36efKUuJwC1Y5T95MkJgjouUCLY1W 2SlEVi6Nr3wuAoS5rfSl57kWhvJT9yzJU+4u2Fo3ChEqlqFdYbtOEf39o7yORKX7kcfb p5XudMx2vtiBeKdWQOoDApFWr5JNG89iNgRjomhN+iSvSVfv3mFOKw1U7Aj5CheaCkgR eBni2Zu4w5tBxfBJTXckfbgNT6smyrlwHQ3nqH9w7udSMb3dfiNnZ8m2fOzuaSXoTqrn trheqT8ss95vMZHA7feC2d23KncOFVbsF/CPCG1FNfhlZn46o0ui7lRhY3X33aRtVbjY 12kg== 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=f3bUi/EN4aK9XE2m3GYYyoTpDTzLR5+xalMZzuVkJnI6KL5Jh3IZdZOC5f7Gn4YR/S rItN7yG6N+7+IfEHT0eG3yGoHUtLbD74P1kU9OHPypmKl301PxEcOq+4HrdEri6Py/JK dzEoBcubrMK0JVCWcMIumF3RQZAjqwWKG3TNpmnKx43hzgAA6Ceu9UhHnZ4bQjzLBTrY V88+pENjma7hX47vnkJWWAqb/8d5nlM3IfV97XVHFDHFXpM5Dh4G4JWnD3E8DL0fNYly nYbLvzPWjQTJJMlSGeyz2Hhpyk6lwAV/VXgrrHKjhy/zdvwHiPQIe+NEfniFnpE1sQp0 uQKQ== X-Forwarded-Encrypted: i=1; AJvYcCUv2TWRM7Y9vXeG8rkPRAMecothiLeVQWaaT9siF9+bsOpyz5vSLUTg3be6IXm90ScDULKv6I6iL1A=@vger.kernel.org, AJvYcCVvIv4Ncm2J5pzroafUYF/BhwknxofWcVX2zdAEq0ZjQ8qnTVLxecQjjC+D5P2kSL47WAwkYWoHJOmkfJx0@vger.kernel.org X-Gm-Message-State: AOJu0Yy4R6YSCZB4ehNCHXzkWbJeg8N3CqlNJUtdvrfq3QJsdX08IfJU jvGkdntpJtjtvuj8wxP/fNZvZq4u7pOx7woTtol4kTI9VYbmH/EF 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 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: 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: 841836 Received: from mail-oi1-f179.google.com (mail-oi1-f179.google.com [209.85.167.179]) (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 AD6FD2185A7; Thu, 7 Nov 2024 21:14:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731014077; cv=none; b=QLX8XpkuyciX/bB8GvLI6K+XeWIsmTC0ZxXI+y3o+eHAG0ioS4VPB7r5XtBDmytAHjPWtQozzaqmUebttexwxQ5A6yxCj3E6MHpmiofItmQiBWB8NSpOnU0Z46dFvyLuKnSZuM5W4Q+KdQVKlTg8JtWbd9FIRIA4i04dKWpCo1M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731014077; c=relaxed/simple; bh=wQAwMy3r7FzJUUodxCO8uG97AJCUypmzZEHRhsQQMkE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=S44g6Tn91LiDApTxZfIH55WuV3qRxFLEfflmtmwEeUvVPIhvKx1giaQD/A8TWBclDh5CUAk8Zg6Jb3D10qqE7mFPiDz6XYjhOyK8PYR6Z1zeQFewDgbm++zzErHT93r+uyo+8jIf9Uup0cQjxMslBqqySM8PI4zHtp4ad1cm2a8= 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=hvN7N2h7; arc=none smtp.client-ip=209.85.167.179 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="hvN7N2h7" Received: by mail-oi1-f179.google.com with SMTP id 5614622812f47-3e786167712so1018933b6e.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=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=jOo8kzEPRGUvbYhKweLQJeBsbVaNvGh932XZf4KLPhQ=; b=hvN7N2h7iaTAgblGziaYlJ1paiTFq3GenKzfyJg85QAzOCNXRZskzzDQi3AyTlSBzi 6y+T2avafBSi12wu9F+kwPbDNwa/N7YKKMoiJvIztKh25SMUvVMDnTz3GCnmhNJw7fKS FRAawSH7ka4M3vltaqjH/EVoM4WDYcpgx9Fi7Oq/fZePsMwgb5cF+AWeGr4jrAep6Dok ixe6NkEKJ5iiTC+/YRaxeQ6L0Gnv7KF3CimcvN+Mh3I4qe8g6N2jIVnSU0NQgZCT1DJL TXCq4Qe3+enbZYpEQmMtZMbCtcs1qVyLvnvlg2DWzht9AfkQc3r0+FHp4dSRCZlwPUH/ INxg== 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=gkwQoTD/OwR+39z7b33VvbS8ZYUUWf+HDK7g7adrqXMxwYu0Sd14k/iX8T5bfp5uLb TaEqi0Y3hMJVyvZaB0qfG3pDmhEj3WkJdiesXLmOKIet2y9aNDe//Kj7iuQUV74L3blf m4cVf7NUOSGBdXfTwY9nB0BLyDjYmj0o7Wer4lJ9YK/aK+K+P0wBfvy0vS7fxX1wXd0b jMlsmWOBwKXVZHIP0ylCwVMGC1VvXKy4yaAa8SayocA4cZlfcbWNcn08ezHIJ06gO6GP Pb2A6dZkHmWA5JeGo39HdpEBTYOyMW0U5T2AK5NxIi1Pqmm7+UqY7A4cSJ5DcQnSaBDw MRwA== X-Forwarded-Encrypted: i=1; AJvYcCUi76yZQk1VN32FqPZVtLg9CCV+xJOdw4OWeHQ63loMccOBT6DTati5FMs0H6OhZhyyL0gfqXYgIcSXlrSu@vger.kernel.org, AJvYcCXjVKFa/K2dym3Rpd9xOURFS2d4rPUDfkbWULgOkA/1DPVJeHNty74eeB9Qp7DGg9+Gt/EX43ET81c=@vger.kernel.org X-Gm-Message-State: AOJu0YymRjlsDAMo95r/IZF+LTaxFme+Ttjd1cvbdRiXQf9QK+XhDtUp 57/Ly2J4QJ+tpeuvpGsvgjI7A59ZcjQ5Bz5firmKyGix9SBG+9VB 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> 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: 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: 841541 Received: from mail-oi1-f172.google.com (mail-oi1-f172.google.com [209.85.167.172]) (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 5113C2185BD; Thu, 7 Nov 2024 21:14:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731014078; cv=none; b=GS/ls7tfJ2S2K3vUMvz1DkfRSIAQKRP9FOzc7Qj4ln4LOYlzQXzqoO5GVnOtRlRZ8vuD4eoJOr9F3O5vb4IFoh1pxjM/6RwE2soEHB3/Q69iBcpvJuqk4+MXDWxraLKsWv8gqFHL4pZdC78MhcUERzbVJhN1Efffz7SOUu1aL8g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731014078; c=relaxed/simple; bh=zzzyW8v7EZ7zw7Pi/ba6/6m1PE4JwT6Zv996YFDghKs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=iTTWTAb/d9JVGCBun6CCAVWy4ONMq2Y+xAZmUIxgOmS+WXG9yyNxvOBX67qzJoI71mzsLMbKfCI11pQTtHHAQ8r7hvx9aTVW1EcfxrectPcibE1A8+kr4Mrx2QQm0BUbzyAJPLDXNImD/SQPuOMgOGANnk2kzFwX80bVaQ9lSSI= 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=MuJAqHdm; arc=none smtp.client-ip=209.85.167.172 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="MuJAqHdm" Received: by mail-oi1-f172.google.com with SMTP id 5614622812f47-3e6005781c0so931090b6e.3; 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=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=vtYJat2vwne5+4WJO2r1NKcoNFx7A4N4AD7ayp8QtCI=; b=MuJAqHdmJZHOtvRGTpSUdlGTUTWxrBby5A4ANaNVVFFdbkFZVHagZ5fzE/Nyo7f60W 2t6sZgfMkYgUngj3XvjUpbPdq1Ceoo8P+k8konXhx/5lRMWNo+TVD9jVz+Eh/BpJ0Mj5 vPET5562fjgOPccmjD3MZLSrN6dD8nbszyiXJ4QpPcbzp2Ee4ZPQugD7HvcGxnPoiTfw Z2EHf6kusgcoWrhM5ukqFr/prCOnq1kUGLwGGOwkYgzf0Al2PO4v2HX6nY2XOm9j/9/C ygoUc59ACpMa16623kDJu9wgifMupvwgunSnnnshFx8mhUm7wACOCfM19a699hBbCJlV lnqQ== 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=jxzqGKPymOA++U9IOnWmyVQNJygPhsW5DsMynBBVXaR8+DJ1fBGOu3d1oMX0Egsvi6 ZnxwPTJygGB8YHg8wlQhFURAHohleFtvCZRWyxZnwMSmrf3KUA+wZMrVDmTr5H9WuqCV OBiY7WY4hRj2HYKM7l2axvyvvetIyFS54ISJtkOBLtQ2fUhMw+u6SCU0uxaWyCDvjxiu B513+qYJWS8R30qNENMX5TZ65whmJZXdJyXy5eWtl/H4iWo1GKyOL3gPkKAyMhD80DKS ewxCVh+fqEmhIRFsZ4/X61DSllfhjKJNhQTW8Si9fk0ocuTBA7yNsHyhBs6UIN1yruPr VVmA== X-Forwarded-Encrypted: i=1; AJvYcCUMFO3kn+xuhMveX1raIXzaa6GYWMDROcJyaB18613PHBW3c+VLERQ4OFGTr/vW+p4peJmNm53u8To=@vger.kernel.org, AJvYcCXEbVw6vzFelisEJmB1y/rWrX4Wu/HtViTrhtSxH1OZtv6nXYcPSW1M0UdOb3dpwZ/Ls6EpzlcmKkb4yMqk@vger.kernel.org X-Gm-Message-State: AOJu0Ywzwi7dNI0vajmXWGhb02dUMN6exwhnA9oUV8V+X1SBplbVE1uD tEjJXdA4EaB66KRIYB+pmLx+U8ac25GlyouKfe76vKIImoWd9Oz1 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> 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: 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;