[01/78] media: atmel: properly get pm_runtime
diff mbox series

Message ID cd5ded1d2ea82a0fb0e983d014ffcebfadffae31.1619191723.git.mchehab+huawei@kernel.org
State New, archived
Headers show
Series
  • media: use pm_runtime_resume_and_get() instead of pm_runtime_get_sync()
Related show

Commit Message

Mauro Carvalho Chehab April 24, 2021, 6:44 a.m. UTC
There are several issues in the way the atmel driver handles
pm_runtime_get_sync():

- it doesn't check return codes;
- it doesn't properly decrement the usage_count on all places;
- it starts streaming even if pm_runtime_get_sync() fails.
- while it tries to get pm_runtime at the clock enable logic,
  it doesn't check if the operation was suceeded.

Replace all occurrences of it to use the new kAPI:
pm_runtime_resume_and_get(), which ensures that, if the
return code is not negative, the usage_count was incremented.

With that, add additional checks when this is called, in order
to ensure that errors will be properly addressed.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/platform/atmel/atmel-isc-base.c | 26 ++++++++++++++-----
 drivers/media/platform/atmel/atmel-isi.c      | 19 +++++++++++---
 2 files changed, 34 insertions(+), 11 deletions(-)

Comments

kernel test robot April 24, 2021, 9:36 a.m. UTC | #1
Hi Mauro,

I love your patch! Yet something to improve:

[auto build test ERROR on linuxtv-media/master]
[also build test ERROR on rockchip/for-next tegra/for-next v5.12-rc8 next-20210423]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Mauro-Carvalho-Chehab/media-use-pm_runtime_resume_and_get-instead-of-pm_runtime_get_sync/20210424-145029
base:   git://linuxtv.org/media_tree.git master
config: nios2-randconfig-s031-20210424 (attached as .config)
compiler: nios2-linux-gcc (GCC) 9.3.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # apt-get install sparse
        # sparse version: v0.6.3-341-g8af24329-dirty
        # https://github.com/0day-ci/linux/commit/40fc496edfa42498090c5a0d8230ec732b82bdc9
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Mauro-Carvalho-Chehab/media-use-pm_runtime_resume_and_get-instead-of-pm_runtime_get_sync/20210424-145029
        git checkout 40fc496edfa42498090c5a0d8230ec732b82bdc9
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' W=1 ARCH=nios2 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   drivers/media/platform/atmel/atmel-isc-base.c: In function 'isc_awb_work':
>> drivers/media/platform/atmel/atmel-isc-base.c:1844:2: error: 'ret' undeclared (first use in this function); did you mean 'net'?
    1844 |  ret = pm_runtime_resume_and_get(isc->dev);
         |  ^~~
         |  net
   drivers/media/platform/atmel/atmel-isc-base.c:1844:2: note: each undeclared identifier is reported only once for each function it appears in

Kconfig warnings: (for reference only)
   WARNING: unmet direct dependencies detected for SERIAL_CORE_CONSOLE
   Depends on TTY && HAS_IOMEM
   Selected by
   - EARLY_PRINTK


vim +1844 drivers/media/platform/atmel/atmel-isc-base.c

  1811	
  1812	static void isc_awb_work(struct work_struct *w)
  1813	{
  1814		struct isc_device *isc =
  1815			container_of(w, struct isc_device, awb_work);
  1816		struct regmap *regmap = isc->regmap;
  1817		struct isc_ctrls *ctrls = &isc->ctrls;
  1818		u32 hist_id = ctrls->hist_id;
  1819		u32 baysel;
  1820		unsigned long flags;
  1821		u32 min, max;
  1822	
  1823		/* streaming is not active anymore */
  1824		if (isc->stop)
  1825			return;
  1826	
  1827		if (ctrls->hist_stat != HIST_ENABLED)
  1828			return;
  1829	
  1830		isc_hist_count(isc, &min, &max);
  1831		ctrls->hist_minmax[hist_id][HIST_MIN_INDEX] = min;
  1832		ctrls->hist_minmax[hist_id][HIST_MAX_INDEX] = max;
  1833	
  1834		if (hist_id != ISC_HIS_CFG_MODE_B) {
  1835			hist_id++;
  1836		} else {
  1837			isc_wb_update(ctrls);
  1838			hist_id = ISC_HIS_CFG_MODE_GR;
  1839		}
  1840	
  1841		ctrls->hist_id = hist_id;
  1842		baysel = isc->config.sd_format->cfa_baycfg << ISC_HIS_CFG_BAYSEL_SHIFT;
  1843	
> 1844		ret = pm_runtime_resume_and_get(isc->dev);
  1845		if (ret < 0)
  1846			return;
  1847	
  1848		/*
  1849		 * only update if we have all the required histograms and controls
  1850		 * if awb has been disabled, we need to reset registers as well.
  1851		 */
  1852		if (hist_id == ISC_HIS_CFG_MODE_GR || ctrls->awb == ISC_WB_NONE) {
  1853			/*
  1854			 * It may happen that DMA Done IRQ will trigger while we are
  1855			 * updating white balance registers here.
  1856			 * In that case, only parts of the controls have been updated.
  1857			 * We can avoid that by locking the section.
  1858			 */
  1859			spin_lock_irqsave(&isc->awb_lock, flags);
  1860			isc_update_awb_ctrls(isc);
  1861			spin_unlock_irqrestore(&isc->awb_lock, flags);
  1862	
  1863			/*
  1864			 * if we are doing just the one time white balance adjustment,
  1865			 * we are basically done.
  1866			 */
  1867			if (ctrls->awb == ISC_WB_ONETIME) {
  1868				v4l2_info(&isc->v4l2_dev,
  1869					  "Completed one time white-balance adjustment.\n");
  1870				/* update the v4l2 controls values */
  1871				isc_update_v4l2_ctrls(isc);
  1872				ctrls->awb = ISC_WB_NONE;
  1873			}
  1874		}
  1875		regmap_write(regmap, ISC_HIS_CFG, hist_id | baysel | ISC_HIS_CFG_RAR);
  1876		isc_update_profile(isc);
  1877		/* if awb has been disabled, we don't need to start another histogram */
  1878		if (ctrls->awb)
  1879			regmap_write(regmap, ISC_CTRLEN, ISC_CTRL_HISREQ);
  1880	
  1881		pm_runtime_put_sync(isc->dev);
  1882	}
  1883	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

Patch
diff mbox series

diff --git a/drivers/media/platform/atmel/atmel-isc-base.c b/drivers/media/platform/atmel/atmel-isc-base.c
index fe3ec8d0eaee..db1be719192a 100644
--- a/drivers/media/platform/atmel/atmel-isc-base.c
+++ b/drivers/media/platform/atmel/atmel-isc-base.c
@@ -294,9 +294,13 @@  static int isc_wait_clk_stable(struct clk_hw *hw)
 static int isc_clk_prepare(struct clk_hw *hw)
 {
 	struct isc_clk *isc_clk = to_isc_clk(hw);
+	int ret;
 
-	if (isc_clk->id == ISC_ISPCK)
-		pm_runtime_get_sync(isc_clk->dev);
+	if (isc_clk->id == ISC_ISPCK) {
+		ret = pm_runtime_resume_and_get(isc_clk->dev);
+		if (ret < 0)
+			return 0;
+	}
 
 	return isc_wait_clk_stable(hw);
 }
@@ -353,9 +357,13 @@  static int isc_clk_is_enabled(struct clk_hw *hw)
 {
 	struct isc_clk *isc_clk = to_isc_clk(hw);
 	u32 status;
+	int ret;
 
-	if (isc_clk->id == ISC_ISPCK)
-		pm_runtime_get_sync(isc_clk->dev);
+	if (isc_clk->id == ISC_ISPCK) {
+		ret = pm_runtime_resume_and_get(isc_clk->dev);
+		if (ret < 0)
+			return 0;
+	}
 
 	regmap_read(isc_clk->regmap, ISC_CLKSR, &status);
 
@@ -807,7 +815,9 @@  static int isc_start_streaming(struct vb2_queue *vq, unsigned int count)
 		goto err_start_stream;
 	}
 
-	pm_runtime_get_sync(isc->dev);
+	ret = pm_runtime_resume_and_get(isc->dev);
+	if (ret < 0)
+		goto err_pm_get;
 
 	ret = isc_configure(isc);
 	if (unlikely(ret))
@@ -838,7 +848,7 @@  static int isc_start_streaming(struct vb2_queue *vq, unsigned int count)
 
 err_configure:
 	pm_runtime_put_sync(isc->dev);
-
+err_pm_get:
 	v4l2_subdev_call(isc->current_subdev->sd, video, s_stream, 0);
 
 err_start_stream:
@@ -1831,7 +1841,9 @@  static void isc_awb_work(struct work_struct *w)
 	ctrls->hist_id = hist_id;
 	baysel = isc->config.sd_format->cfa_baycfg << ISC_HIS_CFG_BAYSEL_SHIFT;
 
-	pm_runtime_get_sync(isc->dev);
+	ret = pm_runtime_resume_and_get(isc->dev);
+	if (ret < 0)
+		return;
 
 	/*
 	 * only update if we have all the required histograms and controls
diff --git a/drivers/media/platform/atmel/atmel-isi.c b/drivers/media/platform/atmel/atmel-isi.c
index 0514be6153df..6a433926726d 100644
--- a/drivers/media/platform/atmel/atmel-isi.c
+++ b/drivers/media/platform/atmel/atmel-isi.c
@@ -422,7 +422,9 @@  static int start_streaming(struct vb2_queue *vq, unsigned int count)
 	struct frame_buffer *buf, *node;
 	int ret;
 
-	pm_runtime_get_sync(isi->dev);
+	ret = pm_runtime_resume_and_get(isi->dev);
+	if (ret < 0)
+		return ret;
 
 	/* Enable stream on the sub device */
 	ret = v4l2_subdev_call(isi->entity.subdev, video, s_stream, 1);
@@ -782,9 +784,10 @@  static int isi_enum_frameintervals(struct file *file, void *fh,
 	return 0;
 }
 
-static void isi_camera_set_bus_param(struct atmel_isi *isi)
+static int isi_camera_set_bus_param(struct atmel_isi *isi)
 {
 	u32 cfg1 = 0;
+	int ret;
 
 	/* set bus param for ISI */
 	if (isi->pdata.hsync_act_low)
@@ -801,12 +804,16 @@  static void isi_camera_set_bus_param(struct atmel_isi *isi)
 	cfg1 |= ISI_CFG1_THMASK_BEATS_16;
 
 	/* Enable PM and peripheral clock before operate isi registers */
-	pm_runtime_get_sync(isi->dev);
+	ret = pm_runtime_resume_and_get(isi->dev);
+	if (ret < 0)
+		return ret;
 
 	isi_writel(isi, ISI_CTRL, ISI_CTRL_DIS);
 	isi_writel(isi, ISI_CFG1, cfg1);
 
 	pm_runtime_put(isi->dev);
+
+	return 0;
 }
 
 /* -----------------------------------------------------------------------*/
@@ -1085,7 +1092,11 @@  static int isi_graph_notify_complete(struct v4l2_async_notifier *notifier)
 		dev_err(isi->dev, "No supported mediabus format found\n");
 		return ret;
 	}
-	isi_camera_set_bus_param(isi);
+	ret = isi_camera_set_bus_param(isi);
+	if (ret) {
+		dev_err(isi->dev, "Can't wake up device\n");
+		return ret;
+	}
 
 	ret = isi_set_default_fmt(isi);
 	if (ret) {