diff mbox series

media: video-mux: Use dev_err_probe()

Message ID 20220411135314.1012346-1-p.zabel@pengutronix.de (mailing list archive)
State New, archived
Headers show
Series media: video-mux: Use dev_err_probe() | expand

Commit Message

Philipp Zabel April 11, 2022, 1:53 p.m. UTC
Simplify the mux error path a bit by using dev_err_probe().

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/media/platform/video-mux.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

Comments

kernel test robot April 11, 2022, 7:05 p.m. UTC | #1
Hi Philipp,

I love your patch! Perhaps something to improve:

[auto build test WARNING on media-tree/master]
[also build test WARNING on v5.18-rc2 next-20220411]
[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/intel-lab-lkp/linux/commits/Philipp-Zabel/media-video-mux-Use-dev_err_probe/20220411-215408
base:   git://linuxtv.org/media_tree.git master
config: i386-randconfig-r004-20220411 (https://download.01.org/0day-ci/archive/20220412/202204120223.QxnsaBfK-lkp@intel.com/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project c6e83f560f06cdfe8aa47b248d8bdc58f947274b)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/475ef9688294985534faa74b409355acb00c6873
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Philipp-Zabel/media-video-mux-Use-dev_err_probe/20220411-215408
        git checkout 475ef9688294985534faa74b409355acb00c6873
        # save the config file to linux build tree
        mkdir build_dir
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash drivers/media/platform/

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

All warnings (new ones prefixed by >>):

>> drivers/media/platform/video-mux.c:444:29: warning: variable 'ret' is uninitialized when used here [-Wuninitialized]
                   return dev_err_probe(dev, ret, "Failed to get mux\n");
                                             ^~~
   drivers/media/platform/video-mux.c:413:9: note: initialize the variable 'ret' to silence this warning
           int ret;
                  ^
                   = 0
   1 warning generated.


vim +/ret +444 drivers/media/platform/video-mux.c

   404	
   405	static int video_mux_probe(struct platform_device *pdev)
   406	{
   407		struct device_node *np = pdev->dev.of_node;
   408		struct device *dev = &pdev->dev;
   409		struct device_node *ep;
   410		struct video_mux *vmux;
   411		unsigned int num_pads = 0;
   412		unsigned int i;
   413		int ret;
   414	
   415		vmux = devm_kzalloc(dev, sizeof(*vmux), GFP_KERNEL);
   416		if (!vmux)
   417			return -ENOMEM;
   418	
   419		platform_set_drvdata(pdev, vmux);
   420	
   421		v4l2_subdev_init(&vmux->subdev, &video_mux_subdev_ops);
   422		snprintf(vmux->subdev.name, sizeof(vmux->subdev.name), "%pOFn", np);
   423		vmux->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
   424		vmux->subdev.dev = dev;
   425	
   426		/*
   427		 * The largest numbered port is the output port. It determines
   428		 * total number of pads.
   429		 */
   430		for_each_endpoint_of_node(np, ep) {
   431			struct of_endpoint endpoint;
   432	
   433			of_graph_parse_endpoint(ep, &endpoint);
   434			num_pads = max(num_pads, endpoint.port + 1);
   435		}
   436	
   437		if (num_pads < 2) {
   438			dev_err(dev, "Not enough ports %d\n", num_pads);
   439			return -EINVAL;
   440		}
   441	
   442		vmux->mux = devm_mux_control_get(dev, NULL);
   443		if (IS_ERR(vmux->mux))
 > 444			return dev_err_probe(dev, ret, "Failed to get mux\n");
   445	
   446		mutex_init(&vmux->lock);
   447		vmux->active = -1;
   448		vmux->pads = devm_kcalloc(dev, num_pads, sizeof(*vmux->pads),
   449					  GFP_KERNEL);
   450		if (!vmux->pads)
   451			return -ENOMEM;
   452	
   453		vmux->format_mbus = devm_kcalloc(dev, num_pads,
   454						 sizeof(*vmux->format_mbus),
   455						 GFP_KERNEL);
   456		if (!vmux->format_mbus)
   457			return -ENOMEM;
   458	
   459		for (i = 0; i < num_pads; i++) {
   460			vmux->pads[i].flags = (i < num_pads - 1) ? MEDIA_PAD_FL_SINK
   461								 : MEDIA_PAD_FL_SOURCE;
   462			vmux->format_mbus[i] = video_mux_format_mbus_default;
   463		}
   464	
   465		vmux->subdev.entity.function = MEDIA_ENT_F_VID_MUX;
   466		ret = media_entity_pads_init(&vmux->subdev.entity, num_pads,
   467					     vmux->pads);
   468		if (ret < 0)
   469			return ret;
   470	
   471		vmux->subdev.entity.ops = &video_mux_ops;
   472	
   473		ret = video_mux_async_register(vmux, num_pads - 1);
   474		if (ret) {
   475			v4l2_async_nf_unregister(&vmux->notifier);
   476			v4l2_async_nf_cleanup(&vmux->notifier);
   477		}
   478	
   479		return ret;
   480	}
   481
Dan Carpenter April 12, 2022, 5:31 a.m. UTC | #2
Hi Philipp,

url:    https://github.com/intel-lab-lkp/linux/commits/Philipp-Zabel/media-video-mux-Use-dev_err_probe/20220411-215408 
base:   git://linuxtv.org/media_tree.git master
config: x86_64-randconfig-m001-20220411 (https://download.01.org/0day-ci/archive/20220412/202204120703.9LLj1dO9-lkp@intel.com/config )
compiler: gcc-11 (Debian 11.2.0-19) 11.2.0

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

smatch warnings:
drivers/media/platform/video-mux.c:444 video_mux_probe() error: uninitialized symbol 'ret'.

vim +/ret +444 drivers/media/platform/video-mux.c

68803ad4522f5d Philipp Zabel    2017-06-07  405  static int video_mux_probe(struct platform_device *pdev)
68803ad4522f5d Philipp Zabel    2017-06-07  406  {
68803ad4522f5d Philipp Zabel    2017-06-07  407  	struct device_node *np = pdev->dev.of_node;
68803ad4522f5d Philipp Zabel    2017-06-07  408  	struct device *dev = &pdev->dev;
68803ad4522f5d Philipp Zabel    2017-06-07  409  	struct device_node *ep;
68803ad4522f5d Philipp Zabel    2017-06-07  410  	struct video_mux *vmux;
68803ad4522f5d Philipp Zabel    2017-06-07  411  	unsigned int num_pads = 0;
efe1958ec41bab Philipp Zabel    2018-05-24  412  	unsigned int i;
68803ad4522f5d Philipp Zabel    2017-06-07  413  	int ret;
68803ad4522f5d Philipp Zabel    2017-06-07  414  
68803ad4522f5d Philipp Zabel    2017-06-07  415  	vmux = devm_kzalloc(dev, sizeof(*vmux), GFP_KERNEL);
68803ad4522f5d Philipp Zabel    2017-06-07  416  	if (!vmux)
68803ad4522f5d Philipp Zabel    2017-06-07  417  		return -ENOMEM;
68803ad4522f5d Philipp Zabel    2017-06-07  418  
68803ad4522f5d Philipp Zabel    2017-06-07  419  	platform_set_drvdata(pdev, vmux);
68803ad4522f5d Philipp Zabel    2017-06-07  420  
68803ad4522f5d Philipp Zabel    2017-06-07  421  	v4l2_subdev_init(&vmux->subdev, &video_mux_subdev_ops);
f764e6d6803915 Rob Herring      2018-08-27  422  	snprintf(vmux->subdev.name, sizeof(vmux->subdev.name), "%pOFn", np);
68803ad4522f5d Philipp Zabel    2017-06-07  423  	vmux->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
68803ad4522f5d Philipp Zabel    2017-06-07  424  	vmux->subdev.dev = dev;
68803ad4522f5d Philipp Zabel    2017-06-07  425  
68803ad4522f5d Philipp Zabel    2017-06-07  426  	/*
68803ad4522f5d Philipp Zabel    2017-06-07  427  	 * The largest numbered port is the output port. It determines
68803ad4522f5d Philipp Zabel    2017-06-07  428  	 * total number of pads.
68803ad4522f5d Philipp Zabel    2017-06-07  429  	 */
68803ad4522f5d Philipp Zabel    2017-06-07  430  	for_each_endpoint_of_node(np, ep) {
68803ad4522f5d Philipp Zabel    2017-06-07  431  		struct of_endpoint endpoint;
68803ad4522f5d Philipp Zabel    2017-06-07  432  
68803ad4522f5d Philipp Zabel    2017-06-07  433  		of_graph_parse_endpoint(ep, &endpoint);
68803ad4522f5d Philipp Zabel    2017-06-07  434  		num_pads = max(num_pads, endpoint.port + 1);
68803ad4522f5d Philipp Zabel    2017-06-07  435  	}
68803ad4522f5d Philipp Zabel    2017-06-07  436  
68803ad4522f5d Philipp Zabel    2017-06-07  437  	if (num_pads < 2) {
68803ad4522f5d Philipp Zabel    2017-06-07  438  		dev_err(dev, "Not enough ports %d\n", num_pads);
68803ad4522f5d Philipp Zabel    2017-06-07  439  		return -EINVAL;
68803ad4522f5d Philipp Zabel    2017-06-07  440  	}
68803ad4522f5d Philipp Zabel    2017-06-07  441  
435945e08551ef Philipp Zabel    2017-07-18  442  	vmux->mux = devm_mux_control_get(dev, NULL);
475ef968829498 Philipp Zabel    2022-04-11  443  	if (IS_ERR(vmux->mux))
475ef968829498 Philipp Zabel    2022-04-11 @444  		return dev_err_probe(dev, ret, "Failed to get mux\n");
                                                                                          ^^^
This should be PTR_ERR(vmux->mux) instead of ret.

68803ad4522f5d Philipp Zabel    2017-06-07  445  
68803ad4522f5d Philipp Zabel    2017-06-07  446  	mutex_init(&vmux->lock);
68803ad4522f5d Philipp Zabel    2017-06-07  447  	vmux->active = -1;
68803ad4522f5d Philipp Zabel    2017-06-07  448  	vmux->pads = devm_kcalloc(dev, num_pads, sizeof(*vmux->pads),
68803ad4522f5d Philipp Zabel    2017-06-07  449  				  GFP_KERNEL);
aeb0d0f581e207 Kangjie Lu       2019-03-09  450  	if (!vmux->pads)
aeb0d0f581e207 Kangjie Lu       2019-03-09  451  		return -ENOMEM;
aeb0d0f581e207 Kangjie Lu       2019-03-09  452  
68803ad4522f5d Philipp Zabel    2017-06-07  453  	vmux->format_mbus = devm_kcalloc(dev, num_pads,
68803ad4522f5d Philipp Zabel    2017-06-07  454  					 sizeof(*vmux->format_mbus),
68803ad4522f5d Philipp Zabel    2017-06-07  455  					 GFP_KERNEL);
aeb0d0f581e207 Kangjie Lu       2019-03-09  456  	if (!vmux->format_mbus)
aeb0d0f581e207 Kangjie Lu       2019-03-09  457  		return -ENOMEM;
68803ad4522f5d Philipp Zabel    2017-06-07  458  
efe1958ec41bab Philipp Zabel    2018-05-24  459  	for (i = 0; i < num_pads; i++) {
efe1958ec41bab Philipp Zabel    2018-05-24  460  		vmux->pads[i].flags = (i < num_pads - 1) ? MEDIA_PAD_FL_SINK
efe1958ec41bab Philipp Zabel    2018-05-24  461  							 : MEDIA_PAD_FL_SOURCE;
efe1958ec41bab Philipp Zabel    2018-05-24  462  		vmux->format_mbus[i] = video_mux_format_mbus_default;
efe1958ec41bab Philipp Zabel    2018-05-24  463  	}
68803ad4522f5d Philipp Zabel    2017-06-07  464  
68803ad4522f5d Philipp Zabel    2017-06-07  465  	vmux->subdev.entity.function = MEDIA_ENT_F_VID_MUX;
68803ad4522f5d Philipp Zabel    2017-06-07  466  	ret = media_entity_pads_init(&vmux->subdev.entity, num_pads,
68803ad4522f5d Philipp Zabel    2017-06-07  467  				     vmux->pads);
68803ad4522f5d Philipp Zabel    2017-06-07  468  	if (ret < 0)
68803ad4522f5d Philipp Zabel    2017-06-07  469  		return ret;
68803ad4522f5d Philipp Zabel    2017-06-07  470  
68803ad4522f5d Philipp Zabel    2017-06-07  471  	vmux->subdev.entity.ops = &video_mux_ops;
68803ad4522f5d Philipp Zabel    2017-06-07  472  
f4d7a681b82665 Steve Longerbeam 2020-05-01  473  	ret = video_mux_async_register(vmux, num_pads - 1);
f4d7a681b82665 Steve Longerbeam 2020-05-01  474  	if (ret) {
3c8c153914812a Sakari Ailus     2021-03-05  475  		v4l2_async_nf_unregister(&vmux->notifier);
3c8c153914812a Sakari Ailus     2021-03-05  476  		v4l2_async_nf_cleanup(&vmux->notifier);
f4d7a681b82665 Steve Longerbeam 2020-05-01  477  	}
f4d7a681b82665 Steve Longerbeam 2020-05-01  478  
f4d7a681b82665 Steve Longerbeam 2020-05-01  479  	return ret;
68803ad4522f5d Philipp Zabel    2017-06-07  480  }
diff mbox series

Patch

diff --git a/drivers/media/platform/video-mux.c b/drivers/media/platform/video-mux.c
index fda8fc0e4814..3e217c365eaf 100644
--- a/drivers/media/platform/video-mux.c
+++ b/drivers/media/platform/video-mux.c
@@ -440,12 +440,8 @@  static int video_mux_probe(struct platform_device *pdev)
 	}
 
 	vmux->mux = devm_mux_control_get(dev, NULL);
-	if (IS_ERR(vmux->mux)) {
-		ret = PTR_ERR(vmux->mux);
-		if (ret != -EPROBE_DEFER)
-			dev_err(dev, "Failed to get mux: %d\n", ret);
-		return ret;
-	}
+	if (IS_ERR(vmux->mux))
+		return dev_err_probe(dev, ret, "Failed to get mux\n");
 
 	mutex_init(&vmux->lock);
 	vmux->active = -1;