The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Ruziev Miraly <miraly.dev@gmail.com>
To: hansg@kernel.org, mchehab@kernel.org, gregkh@linuxfoundation.org
Cc: andy@kernel.org, sakari.ailus@linux.intel.com,
	linux-media@vger.kernel.org, linux-staging@lists.linux.dev,
	linux-kernel@vger.kernel.org,
	Ruziev Miraly <miraly.dev@gmail.com>
Subject: [PATCH v2] media: atomisp: flatten pre_power_down logic and clean up staging code
Date: Sun,  5 Jul 2026 00:08:54 +0500	[thread overview]
Message-ID: <20260704190854.114172-1-miraly.dev@gmail.com> (raw)

Refactor atomisp_mrfld_pre_power_down() by removing the redundant
nested 'else' block, making the function structure linear and easier
to follow. Keep both error logging branches intact to ensure consistency
in hardware failure reporting.

In addition, fix minor checkpatch.pl style warnings in the same file
regarding code alignment and hanging open parentheses.

Signed-off-by: Ruziev Miraly <miraly.dev@gmail.com>
---
Changes in v2:
  - Fixed an issue from v1 where dev_err() was accidentally dropped.
  - Kept both error logging branches for consistency with original behavior.
  - Flattened the code structure by removing the nested 'else' block.
  - Fixed checkpatch.pl style issues (hanging parenthesis and alignment).
---
 .../staging/media/atomisp/pci/atomisp_v4l2.c  | 39 +++++++++++--------
 1 file changed, 23 insertions(+), 16 deletions(-)

diff --git a/drivers/staging/media/atomisp/pci/atomisp_v4l2.c b/drivers/staging/media/atomisp/pci/atomisp_v4l2.c
index 2d72467eb..78cf09753 100644
--- a/drivers/staging/media/atomisp/pci/atomisp_v4l2.c
+++ b/drivers/staging/media/atomisp/pci/atomisp_v4l2.c
@@ -439,14 +439,14 @@ static int atomisp_mrfld_pre_power_down(struct atomisp_device *isp)
 	struct pci_dev *pdev = to_pci_dev(isp->dev);
 	u32 irq;
 	unsigned long flags;
+	int ret = 0;
 
 	spin_lock_irqsave(&isp->lock, flags);
 
 	/*
 	 * MRFLD HAS requirement: cannot power off i-unit if
 	 * ISP has IRQ not serviced.
-	 * So, here we need to check if there is any pending
-	 * IRQ, if so, waiting for it to be served
+	 * Wait for pending IRQs to be served.
 	 */
 	pci_read_config_dword(pdev, PCI_INTERRUPT_CTRL, &irq);
 	irq &= BIT(INTR_IIR);
@@ -454,29 +454,36 @@ static int atomisp_mrfld_pre_power_down(struct atomisp_device *isp)
 
 	pci_read_config_dword(pdev, PCI_INTERRUPT_CTRL, &irq);
 	if (!(irq & BIT(INTR_IIR)))
-		goto done;
+		goto power_down;
 
+	/* Clear and check interrupt status registers */
 	atomisp_css2_hw_store_32(MRFLD_INTR_CLEAR_REG, 0xFFFFFFFF);
 	atomisp_load_uint32(MRFLD_INTR_STATUS_REG, &irq);
+
 	if (irq != 0) {
 		dev_err(isp->dev,
 			"%s: fail to clear isp interrupt status reg=0x%x\n",
 			__func__, irq);
-		spin_unlock_irqrestore(&isp->lock, flags);
-		return -EAGAIN;
+		ret = -EAGAIN;
+		goto unlock_exit;
 	}
+
 	pci_read_config_dword(pdev, PCI_INTERRUPT_CTRL, &irq);
 	irq &= BIT(INTR_IIR);
 	pci_write_config_dword(pdev, PCI_INTERRUPT_CTRL, irq);
 
 	pci_read_config_dword(pdev, PCI_INTERRUPT_CTRL, &irq);
-	if (!(irq & BIT(INTR_IIR))) {
-		atomisp_css2_hw_store_32(MRFLD_INTR_ENABLE_REG, 0x0);
-		goto done;
+	if (irq & BIT(INTR_IIR)) {
+		dev_err(isp->dev,
+			"%s: error in iunit interrupt. status reg=0x%x\n",
+			__func__, irq);
+		ret = -EAGAIN;
+		goto unlock_exit;
 	}
-	spin_unlock_irqrestore(&isp->lock, flags);
-	return -EAGAIN;
-done:
+
+	atomisp_css2_hw_store_32(MRFLD_INTR_ENABLE_REG, 0x0);
+
+power_down:
 	/*
 	 * MRFLD WORKAROUND:
 	 * before powering off IUNIT, clear the pending interrupts
@@ -490,9 +497,10 @@ static int atomisp_mrfld_pre_power_down(struct atomisp_device *isp)
 
 	atomisp_msi_irq_uninit(isp);
 	atomisp_freq_scaling(isp, ATOMISP_DFS_MODE_LOW, true);
-	spin_unlock_irqrestore(&isp->lock, flags);
 
-	return 0;
+unlock_exit:
+	spin_unlock_irqrestore(&isp->lock, flags);
+	return ret;
 }
 
 /*
@@ -839,7 +847,7 @@ static int atomisp_register_entities(struct atomisp_device *isp)
 	/* Register internal entities */
 	for (i = 0; i < ATOMISP_CAMERA_NR_PORTS; i++) {
 		ret = atomisp_mipi_csi2_register_entities(&isp->csi2_port[i],
-			&isp->v4l2_dev);
+							  &isp->v4l2_dev);
 		if (ret == 0)
 			continue;
 
@@ -847,8 +855,7 @@ static int atomisp_register_entities(struct atomisp_device *isp)
 		dev_err(isp->dev, "failed to register the CSI port: %d\n", i);
 		/* deregister all registered CSI ports */
 		while (i--)
-			atomisp_mipi_csi2_unregister_entities(
-			    &isp->csi2_port[i]);
+			atomisp_mipi_csi2_unregister_entities(&isp->csi2_port[i]);
 
 		goto csi_and_subdev_probe_failed;
 	}
-- 
2.54.0


             reply	other threads:[~2026-07-04 19:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-04 19:08 Ruziev Miraly [this message]
2026-07-05  6:46 ` [PATCH v2] media: atomisp: flatten pre_power_down logic and clean up staging code Andy Shevchenko
2026-07-05  6:49 ` Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260704190854.114172-1-miraly.dev@gmail.com \
    --to=miraly.dev@gmail.com \
    --cc=andy@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=hansg@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=mchehab@kernel.org \
    --cc=sakari.ailus@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox