From patchwork Thu Dec 12 13:54:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Shyti X-Patchwork-Id: 13905231 Received: from 11.mo582.mail-out.ovh.net (11.mo582.mail-out.ovh.net [188.165.38.119]) (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 9BCD1748D for ; Thu, 12 Dec 2024 13:54:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=188.165.38.119 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734011694; cv=none; b=hoWL0uSQxxLCpyEVOym5PS10tpdqK3mFmYn9wPH5GlbQwu8N5Wt41P3pOyII1LKH1uAJOKmZFoCtPqOpyuptYu9o5yKXf0eTrBCwQ6tXf5F0x8PNVgUgrkt/gR73KDNY4pjDSC6sP7S/rgxFu9x0kymjSWpSh0Y3iiiofDwOLRk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734011694; c=relaxed/simple; bh=RSA5W+aUu9kn5TswI3lIVWqWj9MpCmpFEeVlLa671CA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tMmsjX8KKZk7NdB0BcYTYfNYPFy+KWMawJJCdQvcUjwkDvDKJQ/K6HrXPXACJkzGN5wCZGoeynJfAw9vVRVxYFj8RRVDIiNb3OueGEq6HBSdMs8qasbpkXeLvBX5Ihr2StroHLBuzGeEdIh+/MrlxoJVAITURh7R9Sy/mHke2+0= 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=188.165.38.119 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 director7.ghost.mail-out.ovh.net (unknown [10.108.17.3]) by mo582.mail-out.ovh.net (Postfix) with ESMTP id 4Y8DVW6wNlz1VLv for ; Thu, 12 Dec 2024 13:54:43 +0000 (UTC) Received: from ghost-submission-5b5ff79f4f-p4mxx (unknown [10.110.113.149]) by director7.ghost.mail-out.ovh.net (Postfix) with ESMTPS id 0C31F1FEA5; Thu, 12 Dec 2024 13:54:43 +0000 (UTC) Received: from etezian.org ([37.59.142.114]) by ghost-submission-5b5ff79f4f-p4mxx with ESMTPSA id kGxlNiLrWmdwNQAATAYGmg (envelope-from ); Thu, 12 Dec 2024 13:54:43 +0000 Authentication-Results: garm.ovh; auth=pass (GARM-114S008070d7480-a6fe-4e9e-abfb-38be5adcf06a, 7E8E14E11F102121CE247F47C6B4DBC0808239E0) smtp.auth=andi@etezian.org X-OVh-ClientIp: 178.39.90.92 From: Andi Shyti To: linux-arm-msm@vger.kernel.org, linux-i2c@vger.kernel.org Cc: Mukesh Kumar Savaliya , Andi Shyti Subject: [PATCH v2 1/2] i2c: qcom-geni: Use dev_err_probe in the probe function Date: Thu, 12 Dec 2024 14:54:15 +0100 Message-ID: <20241212135416.244504-2-andi.shyti@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241212135416.244504-1-andi.shyti@kernel.org> References: <20241212135416.244504-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: 16943386224625650247 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeefuddrkeehgdehiecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemucehtddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomheptehnughiucfuhhihthhiuceorghnughirdhshhihthhisehkvghrnhgvlhdrohhrgheqnecuggftrfgrthhtvghrnhepgfduveejteegteelhfetueetheegfeehhfektddvleehtefhheevkeduleeuueevnecukfhppeduvdejrddtrddtrddupddujeekrdefledrledtrdelvddpfeejrdehledrudegvddruddugeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduvdejrddtrddtrddupdhmrghilhhfrhhomheprghnughisegvthgviihirghnrdhorhhgpdhnsggprhgtphhtthhopedupdhrtghpthhtoheplhhinhhugidqrghrmhdqmhhsmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdpoffvtefjohhsthepmhhoheekvdgmpdhmohguvgepshhmthhpohhuth 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 Thu Dec 12 13:54:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Shyti X-Patchwork-Id: 13905232 Received: from 8.mo560.mail-out.ovh.net (8.mo560.mail-out.ovh.net [188.165.52.147]) (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 8817920ADCD for ; Thu, 12 Dec 2024 13:54:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=188.165.52.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734011695; cv=none; b=jjeVJ89O7t+uOwP/Vrqga085KiTTYibQu34NWpYFltRk04OnAtJgC2nZlO2aP8UlTBkNfIGYeYRxoWEGw7R4jR/IFKkZ0/ActLJJqcu/fe80R26PxrWEeldcliftreLUKsxIT419q9y06R7T4qDYIbCewv9STntEYxETgDLRgt8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734011695; c=relaxed/simple; bh=VPjRocNSukRbmdBc3XUtxk+vawkhCNClBfvUMhwY5J4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iZnAvV7Cw0+50r7xuL5cvOnYg+H1Nn8SEaoQsOTbbPEXdPT0PaKW7Fz2aM167pNDuaktY53uE61Mf9Xs0NnixkyjjUHJ+frrXBK8YWofabXbeoBQH5FGJalNHXYZ2xBJg+Yt00vh7zI0jaqJqOxx4+5gCqispKz9g6+hBnRl6dk= 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=188.165.52.147 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 director9.ghost.mail-out.ovh.net (unknown [10.109.148.146]) by mo560.mail-out.ovh.net (Postfix) with ESMTP id 4Y8DVX6pc3z1Rbk for ; Thu, 12 Dec 2024 13:54:44 +0000 (UTC) Received: from ghost-submission-5b5ff79f4f-dx889 (unknown [10.110.164.150]) by director9.ghost.mail-out.ovh.net (Postfix) with ESMTPS id 8B0D71FE94; Thu, 12 Dec 2024 13:54:44 +0000 (UTC) Received: from etezian.org ([37.59.142.98]) by ghost-submission-5b5ff79f4f-dx889 with ESMTPSA id IP8jGSTrWmfJBAEAV5M9HA (envelope-from ); Thu, 12 Dec 2024 13:54:44 +0000 Authentication-Results: garm.ovh; auth=pass (GARM-98R002bd5ad6a2-8b7b-4542-9082-b4b10b8058e6, 7E8E14E11F102121CE247F47C6B4DBC0808239E0) smtp.auth=andi@etezian.org X-OVh-ClientIp: 178.39.90.92 From: Andi Shyti To: linux-arm-msm@vger.kernel.org, linux-i2c@vger.kernel.org Cc: Mukesh Kumar Savaliya , Andi Shyti Subject: [PATCH v2 2/2] i2c: qcom-geni: Simplify error handling in probe function Date: Thu, 12 Dec 2024 14:54:16 +0100 Message-ID: <20241212135416.244504-3-andi.shyti@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241212135416.244504-1-andi.shyti@kernel.org> References: <20241212135416.244504-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: 16943667699760040519 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeefuddrkeehgdehiecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemucehtddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomheptehnughiucfuhhihthhiuceorghnughirdhshhihthhisehkvghrnhgvlhdrohhrgheqnecuggftrfgrthhtvghrnhepgfduveejteegteelhfetueetheegfeehhfektddvleehtefhheevkeduleeuueevnecukfhppeduvdejrddtrddtrddupddujeekrdefledrledtrdelvddpfeejrdehledrudegvddrleeknecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepuddvjedrtddrtddruddpmhgrihhlfhhrohhmpegrnhguihesvghtvgiiihgrnhdrohhrghdpnhgspghrtghpthhtohepuddprhgtphhtthhopehlihhnuhigqdgrrhhmqdhmshhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdfovfetjfhoshhtpehmohehiedtmgdpmhhouggvpehsmhhtphhouhht 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 | 32 ++++++++++++++++-------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/drivers/i2c/busses/i2c-qcom-geni.c b/drivers/i2c/busses/i2c-qcom-geni.c index 01db24188e29..88709b97f86d 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); + 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,8 @@ 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"); + dev_err_probe(dev, -EINVAL, "Invalid TX FIFO depth\n"); + goto err_resources; } gi2c->tx_wm = tx_depth - 1; @@ -942,10 +936,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; }