From patchwork Fri Dec 27 22:32:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Shyti X-Patchwork-Id: 853845 Received: from 13.mo583.mail-out.ovh.net (13.mo583.mail-out.ovh.net [87.98.182.191]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EAE6D11CA9 for ; Fri, 27 Dec 2024 23:51:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=87.98.182.191 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735343489; cv=none; b=U8R4a6UglVeQSd8Dxux+EDDVTZkcwLYfWR7dIZw1mv4UM35QDFOUGr/bZxWQ5jXQW3sARS7zOGbZT6LnLE7pgWSe2cXO8Wfi2B3IWy1EQSWCJ2DId4ROoFMu+o3Yg3l6Wjn+D6K3FSvlCJuKqn8wEkRjC1W5nY8dFW3xeIMuFyU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735343489; c=relaxed/simple; bh=/vVElhArPs2oL3H3/MGvnQtDRW7Y0jfODIZIccvQBX0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZMJJfyV/u/COItnxEobMH8HUFfXh4Omn6v/0cIKVHHW7Kw+IPcZG0Nvmppmd3JZ3giPKhVHY/S1Ove1PnQ4A0fEQPpMxIl2OMU58NsI69ybKAfDTjmXYvGF/0ZMhGIJdj2W7GgCFoME+Onl+mZQ+AX9kXIAcN30IglBx7RWyI3U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=etezian.org; arc=none smtp.client-ip=87.98.182.191 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=etezian.org Received: from director11.ghost.mail-out.ovh.net (unknown [10.108.17.219]) by mo583.mail-out.ovh.net (Postfix) with ESMTP id 4YKgHM1SLyz1RL6 for ; Fri, 27 Dec 2024 22:32:47 +0000 (UTC) Received: from ghost-submission-5b5ff79f4f-dkrcz (unknown [10.111.182.20]) by director11.ghost.mail-out.ovh.net (Postfix) with ESMTPS id 390511FD80; Fri, 27 Dec 2024 22:32:46 +0000 (UTC) Received: from etezian.org ([37.59.142.100]) by ghost-submission-5b5ff79f4f-dkrcz with ESMTPSA id gNsrNg0rb2f3dgIAoSK1aw (envelope-from ); Fri, 27 Dec 2024 22:32:46 +0000 Authentication-Results: garm.ovh; auth=pass (GARM-100R0033b37c51d-1a51-4e51-95a3-e962138ba63c, 1CF389E8DC6EE1CDBE94366E1222F406669E166D) smtp.auth=andi@etezian.org X-OVh-ClientIp: 197.26.54.218 From: Andi Shyti To: linux-arm-msm@vger.kernel.org, linux-i2c@vger.kernel.org Cc: Mukesh Kumar Savaliya , Vladimir Zapolskiy Subject: [PATCH v3 1/2] i2c: qcom-geni: Use dev_err_probe in the probe function Date: Fri, 27 Dec 2024 23:32:29 +0100 Message-ID: <20241227223230.462395-2-andi.shyti@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241227223230.462395-1-andi.shyti@kernel.org> References: <20241227223230.462395-1-andi.shyti@kernel.org> Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Ovh-Tracer-Id: 3102698669072779853 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeefuddruddvtddgudeivdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemucehtddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeetnhguihcuufhhhihtihcuoegrnhguihdrshhhhihtiheskhgvrhhnvghlrdhorhhgqeenucggtffrrghtthgvrhhnpefgudevjeetgeetlefhteeuteehgeefhefhkedtvdelheethfehveekudelueeuveenucfkphepuddvjedrtddrtddruddpudeljedrvdeirdehgedrvddukedpfeejrdehledrudegvddruddttdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduvdejrddtrddtrddupdhmrghilhhfrhhomheprghnughisegvthgviihirghnrdhorhhgpdhnsggprhgtphhtthhopedupdhrtghpthhtoheplhhinhhugidqrghrmhdqmhhsmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdpoffvtefjohhsthepmhhoheekfegmpdhmohguvgepshhmthhpohhuth Replace classical dev_err with dev_err_probe in the probe function for better error reporting. Also, use dev_err_probe in cases where the error number is clear (e.g., -EIO or -EINVAL) to maintain consistency. Additionally, remove redundant logging to simplify the code. Signed-off-by: Andi Shyti Reviewed-by: Vladimir Zapolskiy Acked-by: Mukesh Kumar Savaliya --- drivers/i2c/busses/i2c-qcom-geni.c | 33 +++++++++++++----------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/drivers/i2c/busses/i2c-qcom-geni.c b/drivers/i2c/busses/i2c-qcom-geni.c index 7a22e1f46e60..01db24188e29 100644 --- a/drivers/i2c/busses/i2c-qcom-geni.c +++ b/drivers/i2c/busses/i2c-qcom-geni.c @@ -823,11 +823,9 @@ static int geni_i2c_probe(struct platform_device *pdev) return gi2c->irq; ret = geni_i2c_clk_map_idx(gi2c); - if (ret) { - dev_err(dev, "Invalid clk frequency %d Hz: %d\n", - gi2c->clk_freq_out, ret); - return ret; - } + if (ret) + return dev_err_probe(dev, ret, "Invalid clk frequency %d Hz\n", + gi2c->clk_freq_out); gi2c->adap.algo = &geni_i2c_algo; init_completion(&gi2c->done); @@ -837,11 +835,10 @@ static int geni_i2c_probe(struct platform_device *pdev) /* Keep interrupts disabled initially to allow for low-power modes */ ret = devm_request_irq(dev, gi2c->irq, geni_i2c_irq, IRQF_NO_AUTOEN, dev_name(dev), gi2c); - if (ret) { - dev_err(dev, "Request_irq failed:%d: err:%d\n", - gi2c->irq, ret); - return ret; - } + if (ret) + return dev_err_probe(dev, ret, + "Request_irq failed: %d\n", gi2c->irq); + i2c_set_adapdata(&gi2c->adap, gi2c); gi2c->adap.dev.parent = dev; gi2c->adap.dev.of_node = dev->of_node; @@ -870,16 +867,14 @@ static int geni_i2c_probe(struct platform_device *pdev) ret = geni_se_resources_on(&gi2c->se); if (ret) { - dev_err(dev, "Error turning on resources %d\n", ret); clk_disable_unprepare(gi2c->core_clk); - return ret; + return dev_err_probe(dev, ret, "Error turning on resources\n"); } proto = geni_se_read_proto(&gi2c->se); if (proto != GENI_SE_I2C) { - dev_err(dev, "Invalid proto %d\n", proto); geni_se_resources_off(&gi2c->se); clk_disable_unprepare(gi2c->core_clk); - return -ENXIO; + return dev_err_probe(dev, -ENXIO, "Invalid proto %d\n", proto); } if (desc && desc->no_dma_support) @@ -894,7 +889,7 @@ static int geni_i2c_probe(struct platform_device *pdev) if (ret) { geni_se_resources_off(&gi2c->se); clk_disable_unprepare(gi2c->core_clk); - return dev_err_probe(dev, ret, "Failed to setup GPI DMA mode\n"); + return ret; } dev_dbg(dev, "Using GPI DMA mode for I2C\n"); @@ -907,10 +902,10 @@ static int geni_i2c_probe(struct platform_device *pdev) tx_depth = desc->tx_fifo_depth; if (!tx_depth) { - dev_err(dev, "Invalid TX FIFO depth\n"); geni_se_resources_off(&gi2c->se); clk_disable_unprepare(gi2c->core_clk); - return -EINVAL; + return dev_err_probe(dev, -EINVAL, + "Invalid TX FIFO depth\n"); } gi2c->tx_wm = tx_depth - 1; @@ -924,7 +919,7 @@ static int geni_i2c_probe(struct platform_device *pdev) clk_disable_unprepare(gi2c->core_clk); ret = geni_se_resources_off(&gi2c->se); if (ret) { - dev_err(dev, "Error turning off resources %d\n", ret); + dev_err_probe(dev, ret, "Error turning off resources\n"); goto err_dma; } @@ -940,7 +935,7 @@ static int geni_i2c_probe(struct platform_device *pdev) ret = i2c_add_adapter(&gi2c->adap); if (ret) { - dev_err(dev, "Error adding i2c adapter %d\n", ret); + dev_err_probe(dev, ret, "Error adding i2c adapter\n"); pm_runtime_disable(gi2c->se.dev); goto err_dma; } From patchwork Fri Dec 27 22:32:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Shyti X-Patchwork-Id: 854021 Received: from 6.mo560.mail-out.ovh.net (6.mo560.mail-out.ovh.net [87.98.165.38]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2E32D11CA9 for ; Fri, 27 Dec 2024 23:49:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=87.98.165.38 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735343372; cv=none; b=Q3iwdyvVSnhx0jOHxSF3fsh1fIm3Iqco75Uyi4drVoL6dcINMfZxBOUGY7F89XTy4ThTSPpvBeDsNqwHtlTXIU6uqStxsPaoPd3P4DE8TdNl61d+VQHv5TgIBlRf+v08NAWdZiPmeHOHlpapd8/qc2O6dVDzca1zvZ2WHYTbAsw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735343372; c=relaxed/simple; bh=wBn9uz/w0EiNkmFY57lHz7M0KHBUCBPGBvzCnVi6Qm0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gfnCcWE7N0ypP97jcFAOnu3vpoLl9bcbdI3ZkW1aQCcUmpwzDK86pQQlq0iDR5oOuTX6WejiRT/j7u9Qy1piKLOSpjJEP9Wr0fOBIzYMT4Qk7mgszxVu70FaZlBXT5IpBN7KJko//ATZKtn9UsWaEkSZD8hlSb32LxswVo5NQ1o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=etezian.org; arc=none smtp.client-ip=87.98.165.38 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=etezian.org Received: from director10.ghost.mail-out.ovh.net (unknown [10.109.139.40]) by mo560.mail-out.ovh.net (Postfix) with ESMTP id 4YKgHP3zyKz1Xxj for ; Fri, 27 Dec 2024 22:32:49 +0000 (UTC) Received: from ghost-submission-5b5ff79f4f-rcdtk (unknown [10.110.101.246]) by director10.ghost.mail-out.ovh.net (Postfix) with ESMTPS id B99091FD42; Fri, 27 Dec 2024 22:32:48 +0000 (UTC) Received: from etezian.org ([37.59.142.110]) by ghost-submission-5b5ff79f4f-rcdtk with ESMTPSA id 3HomGxArb2cnXRkAKJWVUA (envelope-from ); Fri, 27 Dec 2024 22:32:48 +0000 Authentication-Results: garm.ovh; auth=pass (GARM-110S00481b48f1e-0671-40b4-ba33-6822b09e1607, 1CF389E8DC6EE1CDBE94366E1222F406669E166D) smtp.auth=andi@etezian.org X-OVh-ClientIp: 197.26.54.218 From: Andi Shyti To: linux-arm-msm@vger.kernel.org, linux-i2c@vger.kernel.org Cc: Mukesh Kumar Savaliya , Vladimir Zapolskiy Subject: [PATCH v3 2/2] i2c: qcom-geni: Simplify error handling in probe function Date: Fri, 27 Dec 2024 23:32:30 +0100 Message-ID: <20241227223230.462395-3-andi.shyti@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241227223230.462395-1-andi.shyti@kernel.org> References: <20241227223230.462395-1-andi.shyti@kernel.org> Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Ovh-Tracer-Id: 3103261619345951309 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeefuddruddvtddgudeivdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemucehtddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeetnhguihcuufhhhihtihcuoegrnhguihdrshhhhihtiheskhgvrhhnvghlrdhorhhgqeenucggtffrrghtthgvrhhnpefgudevjeetgeetlefhteeuteehgeefhefhkedtvdelheethfehveekudelueeuveenucfkphepuddvjedrtddrtddruddpudeljedrvdeirdehgedrvddukedpfeejrdehledrudegvddruddutdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduvdejrddtrddtrddupdhmrghilhhfrhhomheprghnughisegvthgviihirghnrdhorhhgpdhnsggprhgtphhtthhopedupdhrtghpthhtoheplhhinhhugidqrghrmhdqmhhsmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdpoffvtefjohhsthepmhhoheeitdgmpdhmohguvgepshhmthhpohhuth Avoid repeating the error handling pattern: geni_se_resources_off(&gi2c->se); clk_disable_unprepare(gi2c->core_clk); return; Introduce a single 'goto' exit label for cleanup in case of errors. While there are currently two distinct exit points, there is no overlap in their handling, allowing both branches to coexist cleanly. Signed-off-by: Andi Shyti --- drivers/i2c/busses/i2c-qcom-geni.c | 33 ++++++++++++++++-------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/drivers/i2c/busses/i2c-qcom-geni.c b/drivers/i2c/busses/i2c-qcom-geni.c index 01db24188e29..7bbd478171e0 100644 --- a/drivers/i2c/busses/i2c-qcom-geni.c +++ b/drivers/i2c/busses/i2c-qcom-geni.c @@ -867,14 +867,13 @@ static int geni_i2c_probe(struct platform_device *pdev) ret = geni_se_resources_on(&gi2c->se); if (ret) { - clk_disable_unprepare(gi2c->core_clk); - return dev_err_probe(dev, ret, "Error turning on resources\n"); + dev_err_probe(dev, ret, "Error turning on resources\n"); + goto err_clk; } proto = geni_se_read_proto(&gi2c->se); if (proto != GENI_SE_I2C) { - geni_se_resources_off(&gi2c->se); - clk_disable_unprepare(gi2c->core_clk); - return dev_err_probe(dev, -ENXIO, "Invalid proto %d\n", proto); + ret = dev_err_probe(dev, -ENXIO, "Invalid proto %d\n", proto); + goto err_resources; } if (desc && desc->no_dma_support) @@ -886,11 +885,8 @@ static int geni_i2c_probe(struct platform_device *pdev) /* FIFO is disabled, so we can only use GPI DMA */ gi2c->gpi_mode = true; ret = setup_gpi_dma(gi2c); - if (ret) { - geni_se_resources_off(&gi2c->se); - clk_disable_unprepare(gi2c->core_clk); - return ret; - } + if (ret) + goto err_resources; dev_dbg(dev, "Using GPI DMA mode for I2C\n"); } else { @@ -902,10 +898,9 @@ static int geni_i2c_probe(struct platform_device *pdev) tx_depth = desc->tx_fifo_depth; if (!tx_depth) { - geni_se_resources_off(&gi2c->se); - clk_disable_unprepare(gi2c->core_clk); - return dev_err_probe(dev, -EINVAL, - "Invalid TX FIFO depth\n"); + ret = dev_err_probe(dev, -EINVAL, + "Invalid TX FIFO depth\n"); + goto err_resources; } gi2c->tx_wm = tx_depth - 1; @@ -942,10 +937,18 @@ static int geni_i2c_probe(struct platform_device *pdev) dev_dbg(dev, "Geni-I2C adaptor successfully added\n"); - return 0; + return ret; + +err_resources: + geni_se_resources_off(&gi2c->se); +err_clk: + clk_disable_unprepare(gi2c->core_clk); + + return ret; err_dma: release_gpi_dma(gi2c); + return ret; }