Skip to contentSkip to conversation

staging: media: atomisp: Drop unnecessary else block after return/break

PATCH Superseded Dileep Sankhla 2 participants 2 messages Jul 6 – Jul 12

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: media: atomisp: Drop unnecessary else block after return/break

Remove redundant else blocks following return or break statements. As control flow exits in these cases, the else branch is unnecessary. Dropping it improves code readability.

No functional change.

---
 .../staging/media/atomisp/pci/atomisp_fops.c  |  22 ++--
 .../staging/media/atomisp/pci/atomisp_v4l2.c  |  30 ++---
 .../hive_isp_css_common/host/input_system.c   | 103 ++++++++-------
 drivers/staging/media/atomisp/pci/hmm/hmm.c   |   3 +-
 .../kernels/ctc/ctc1_5/ia_css_ctc1_5.host.c   |   6 +-
 drivers/staging/media/atomisp/pci/sh_css.c    |  16 +--
 .../media/atomisp/pci/sh_css_firmware.c       |   4 +-
 .../staging/media/atomisp/pci/sh_css_params.c | 118 +++++++++---------
 8 files changed, 149 insertions(+), 153 deletions(-)
drivers/staging/media/atomisp/pci/atomisp_fops.c +11 -11
index c7aef066f209..8f885f72e195 100644
@@ -125,10 +125,9 @@ static int atomisp_q_one_metadata_buffer(struct atomisp_sub_device *asd,
 					     stream_id, css_pipe_id)) {
 		list_add(&metadata_buf->list, metadata_list);
 		return -EINVAL;
-	} else {
-		list_add_tail(&metadata_buf->list,
-			      &asd->metadata_in_css[md_type]);
 	}
+
+	list_add_tail(&metadata_buf->list, &asd->metadata_in_css[md_type]);
 	asd->metadata_bufs_in_css[stream_id][css_pipe_id]++;
 
 	return 0;
@@ -165,12 +164,13 @@ static int atomisp_q_one_s3a_buffer(struct atomisp_sub_device *asd,
 		/* got from head, so return back to the head */
 		list_add(&s3a_buf->list, s3a_list);
 		return -EINVAL;
-	} else {
-		list_add_tail(&s3a_buf->list, &asd->s3a_stats_in_css);
-		if (s3a_list == &asd->s3a_stats_ready)
-			dev_dbg(asd->isp->dev, "drop one s3a stat with exp_id %d\n", exp_id);
 	}
 
+	list_add_tail(&s3a_buf->list, &asd->s3a_stats_in_css);
+	if (s3a_list == &asd->s3a_stats_ready)
+		dev_dbg(asd->isp->dev, "drop one s3a stat with exp_id %d\n",
+			exp_id);
+
 	asd->s3a_bufs_in_css[css_pipe_id]++;
 	return 0;
 }
@@ -206,12 +206,12 @@ static int atomisp_q_one_dis_buffer(struct atomisp_sub_device *asd,
 		list_add_tail(&dis_buf->list, &asd->dis_stats);
 		spin_unlock_irqrestore(&asd->dis_stats_lock, irqflags);
 		return -EINVAL;
-	} else {
-		spin_lock_irqsave(&asd->dis_stats_lock, irqflags);
-		list_add_tail(&dis_buf->list, &asd->dis_stats_in_css);
-		spin_unlock_irqrestore(&asd->dis_stats_lock, irqflags);
 	}
 
+	spin_lock_irqsave(&asd->dis_stats_lock, irqflags);
+	list_add_tail(&dis_buf->list, &asd->dis_stats_in_css);
+	spin_unlock_irqrestore(&asd->dis_stats_lock, irqflags);
+
 	asd->dis_bufs_in_css++;
 
 	return 0;
drivers/staging/media/atomisp/pci/atomisp_v4l2.c +15 -15
index 812230397409..2059b3afc858 100644
@@ -468,22 +468,22 @@ static int atomisp_mrfld_pre_power_down(struct atomisp_device *isp)
 			__func__, irq);
 		spin_unlock_irqrestore(&isp->lock, flags);
 		return -EAGAIN;
-	} else {
-		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;
-		}
-		dev_err(isp->dev,
-			"%s: error in iunit interrupt. status reg=0x%x\n",
-			__func__, irq);
-		spin_unlock_irqrestore(&isp->lock, flags);
-		return -EAGAIN;
 	}
+
+	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;
+	}
+	dev_err(isp->dev,
+		"%s: error in iunit interrupt. status reg=0x%x\n", __func__,
+		irq);
+	spin_unlock_irqrestore(&isp->lock, flags);
+	return -EAGAIN;
 done:
 	/*
 	 * MRFLD WORKAROUND:
drivers/staging/media/atomisp/pci/hive_isp_css_common/host/input_system.c +50 -53

133 lines not on this page · raw message

drivers/staging/media/atomisp/pci/hmm/hmm.c +1 -2
index f998b57f90c4..6ff77e053d5d 100644
@@ -235,9 +235,8 @@ static int load_and_flush(ia_css_ptr virt, void *data, unsigned int bytes)
 		vptr = hmm_bo_vmap(bo, true);
 		if (!vptr)
 			return load_and_flush_by_kmap(virt, data, bytes);
-		else
-			vptr = vptr + (virt - bo->start);
 
+		vptr = vptr + (virt - bo->start);
 		memcpy(data, vptr, bytes);
 		clflush_cache_range(vptr, bytes);
 		hmm_bo_vunmap(bo);
drivers/staging/media/atomisp/pci/isp/kernels/ctc/ctc1_5/ia_css_ctc1_5.host.c +3 -3
index 0089402bc12d..4b2b7667f075 100644
@@ -29,11 +29,11 @@ static void ctc_gradient(
 		ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE_PRIVATE,
 				    "ctc_gradient() error, illegal division operation\n");
 		return;
-	} else {
-		dydx_int = dy / dx;
-		dydx_frc = ((dy - dydx_int * dx) << frc_bits) / dx;
 	}
 
+	dydx_int = dy / dx;
+	dydx_frc = ((dy - dydx_int * dx) << frc_bits) / dx;
+
 	assert(y0 >= 0 && y0 <= max_dydx);
 	assert(y1 >= 0 && y1 <= max_dydx);
 	assert(x0 < x1);
drivers/staging/media/atomisp/pci/sh_css.c +8 -8
index 00082276f1db..8e7c99b88c39 100644
@@ -7719,14 +7719,14 @@ ia_css_pipe_override_frame_format(struct ia_css_pipe *pipe,
 		err = -EINVAL;
 		IA_CSS_LEAVE_ERR_PRIVATE(err);
 		return err;
-	} else {
-		err = ia_css_pipe_check_format(pipe, new_format);
-		if (!err) {
-			if (pin_index == 0)
-				pipe->output_info[0].format = new_format;
-			else
-				pipe->vf_output_info[0].format = new_format;
-		}
+	}
+
+	err = ia_css_pipe_check_format(pipe, new_format);
+	if (!err) {
+		if (pin_index == 0)
+			pipe->output_info[0].format = new_format;
+		else
+			pipe->vf_output_info[0].format = new_format;
 	}
 	IA_CSS_LEAVE_ERR_PRIVATE(err);
 	return err;
drivers/staging/media/atomisp/pci/sh_css_firmware.c +2 -2
index af12df2f9b09..965445609eaa 100644
@@ -246,10 +246,10 @@ sh_css_load_firmware(struct device *dev, const char *fw_data,
 		IA_CSS_ERROR("CSS code version (%s) and firmware version (%s) mismatch!",
 			     file_header->version, release_version);
 		return -EINVAL;
-	} else {
-		IA_CSS_LOG("successfully load firmware version %s", release_version);
 	}
 
+	IA_CSS_LOG("Successfully loaded firmware version %s", release_version);
+
 	sh_css_num_binaries = file_header->binary_nr;
 	/* Only allocate memory for ISP blob info */
 	if (sh_css_num_binaries > NUM_OF_SPS) {
drivers/staging/media/atomisp/pci/sh_css_params.c +59 -59

144 lines not on this page · raw message

Signature · 1 line
2.43.0
#1 lore raw
Quoted 5 lines · Dileep Sankhla

Remove redundant else blocks following return or break statements. As control flow exits in these cases, the else branch is unnecessary. Dropping it improves code readability.

No functional change.

...

Quoted 26 lines

+++ b/drivers/staging/media/atomisp/pci/atomisp_v4l2.c static int atomisp_mrfld_pre_power_down(struct atomisp_device *isp)

drivers/staging/media/atomisp/pci/atomisp_v4l2.c +5 -15
 		spin_unlock_irqrestore(&isp->lock, flags);
 		return -EAGAIN;
-	} else {
-		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;
-		}
-		dev_err(isp->dev,
-			"%s: error in iunit interrupt. status reg=0x%x\n",
-			__func__, irq);
-		spin_unlock_irqrestore(&isp->lock, flags);
-		return -EAGAIN;
 	}
+
+	pci_read_config_dword(pdev, PCI_INTERRUPT_CTRL, &irq);
+	irq &= BIT(INTR_IIR);
+	pci_write_config_dword(pdev, PCI_INTERRUPT_CTRL, irq);
+

drivers/staging/media/atomisp/pci/atomisp_v4l2.c static int atomisp_mrfld_pre_power_down(struct atomisp_device *isp) · line 486

Quoted 10 lines
drivers/staging/media/atomisp/pci/atomisp_v4l2.c +10 -0
+	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;
+	}
+	dev_err(isp->dev,
+		"%s: error in iunit interrupt. status reg=0x%x\n", __func__,
+		irq);
+	spin_unlock_irqrestore(&isp->lock, flags);
+	return -EAGAIN;

I would really avoid touching this for now. This is non-straight workaround for some platforms and it needs real care on what's going on and how to make it look better. Since your patch does not targeting that, it's doubtful that this change is helpful.

...

drivers/staging/media/atomisp/pci/hive_isp_css_common/host/input_system.c static input_system_err_t set_source_type( · line 1174

Quoted 4 lines
drivers/staging/media/atomisp/pci/hive_isp_css_common/host/input_system.c +1 -1
 	if ((*flags) & INPUT_SYSTEM_CFG_FLAG_SET) {
 		// Check for consistency with already set value.
-		if ((*lhs) == (rhs)) {
+		if ((*lhs) == (rhs))

Unneeded parentheses, also see below.

drivers/staging/media/atomisp/pci/hive_isp_css_common/host/input_system.c static input_system_err_t set_source_type( · line 1179

Quoted 9 lines
drivers/staging/media/atomisp/pci/hive_isp_css_common/host/input_system.c +3 -4
 			return INPUT_SYSTEM_ERR_NO_ERROR;
-		} else {
-			*flags |= INPUT_SYSTEM_CFG_FLAG_CONFLICT;
-			return INPUT_SYSTEM_ERR_CONFLICT_ON_RESOURCE;
-		}
+
+		*flags |= INPUT_SYSTEM_CFG_FLAG_CONFLICT;
+		return INPUT_SYSTEM_ERR_CONFLICT_ON_RESOURCE;
 	}

In this case it's better to toggle the conditional to follow the pattern to check for errors first.

		if (*lhs != rhs) {
			*flags |= INPUT_SYSTEM_CFG_FLAG_CONFLICT;
			return INPUT_SYSTEM_ERR_CONFLICT_ON_RESOURCE;
		}

		return INPUT_SYSTEM_ERR_NO_ERROR;

And yeah, looking at the below, you might want to have a common helper for this. So, perhaps don't touch these three cases for now. Or we can leave them as in your patch, it's up to Sakari and you.

...

drivers/staging/media/atomisp/pci/sh_css_params.c sh_css_param_update_isp_params(struct ia_css_pipe *curr_pipe, · line 3202

Quoted 3 lines
drivers/staging/media/atomisp/pci/sh_css_params.c +3 -0
+		/* TMP: check discrepancy between nr of enqueued
+		 * parameter sets and dequeued sets
+		 */

When moving comments with a wrong style, fix the style at the same time.

		/*
		 * TMP: check discrepancy between nr of enqueued parameter sets
		 * and dequeued sets.
		 */

...

drivers/staging/media/atomisp/pci/sh_css_params.c sh_css_param_update_isp_params(struct ia_css_pipe *curr_pipe, · line 3204

Quoted 1 line
drivers/staging/media/atomisp/pci/sh_css_params.c +1 -0
+		assert(g_param_buffer_enqueue_count < g_param_buffer_dequeue_count + 50);

What will this do in the kernel environment? Perhaps first you need to check that and most likely change the assert():s to something else?

...

drivers/staging/media/atomisp/pci/sh_css_params.c sh_css_param_update_isp_params(struct ia_css_pipe *curr_pipe, · line 3217

Quoted 3 lines
drivers/staging/media/atomisp/pci/sh_css_params.c +3 -0
+		ia_css_bufq_enqueue_psys_event(
+				IA_CSS_PSYS_SW_EVENT_BUFFER_ENQUEUED,
+				(uint8_t)thread_id, (uint8_t)queue_id, 0);

Why do we need the castings?

...

Half of the patch is good to go, and the other needs more work and real work on the driver.

Signature · 2 lines
With Best Regards,
Andy Shevchenko