diff mbox series

media: pci: cx88: Fix missing pci_disable_device() when cx88_core_get() returns null

Message ID 20221205062757.1749-1-gaochao49@huawei.com (mailing list archive)
State New, archived
Headers show
Series media: pci: cx88: Fix missing pci_disable_device() when cx88_core_get() returns null | expand

Commit Message

gaochao Dec. 5, 2022, 6:27 a.m. UTC
From: Gao Chao <gaochao49@huawei.com>

commit a8782f669c35 ("V4L/DVB (9796): drivers/media/video/cx88/cx88-alsa.c:
Adjust error-handling code") added fail path. However, when cx88_core_get()
returns null with chip->pci has not been setted, snd_cx88_dev_free() won't
call a valid pci_disable_device() due to invalid chip->pci. Move the
assignment of chip->pci forward to ensure snd_cx88_dev_free() can get
valid chip->pci.

Fixes: b7f355d23c34 ("V4L/DVB (3293): Added digital support for cx88 (cx88-alsa)")
Signed-off-by: Gao Chao <gaochao49@huawei.com>
---
 drivers/media/pci/cx88/cx88-alsa.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--
2.17.1

Comments

kernel test robot Dec. 5, 2022, 11:32 a.m. UTC | #1
Hi gaochao,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on media-tree/master]
[also build test WARNING on linus/master v6.1-rc8 next-20221202]
[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#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/gaochao/media-pci-cx88-Fix-missing-pci_disable_device-when-cx88_core_get-returns-null/20221205-142935
base:   git://linuxtv.org/media_tree.git master
patch link:    https://lore.kernel.org/r/20221205062757.1749-1-gaochao49%40huawei.com
patch subject: [PATCH] media: pci: cx88: Fix missing pci_disable_device() when cx88_core_get() returns null
config: riscv-randconfig-r042-20221204
compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project 6e4cea55f0d1104408b26ac574566a0e4de48036)
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
        # install riscv cross compiling tool for clang build
        # apt-get install binutils-riscv-linux-gnu
        # https://github.com/intel-lab-lkp/linux/commit/7e5ff2ec3fda73eef4c2b6637de981d936d13090
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review gaochao/media-pci-cx88-Fix-missing-pci_disable_device-when-cx88_core_get-returns-null/20221205-142935
        git checkout 7e5ff2ec3fda73eef4c2b6637de981d936d13090
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=riscv SHELL=/bin/bash drivers/media/pci/cx88/

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

All warnings (new ones prefixed by >>):

>> drivers/media/pci/cx88/cx88-alsa.c:861:2: warning: variable 'chip' is uninitialized when used here [-Wuninitialized]
           chip->pci = pci;
           ^~~~
   drivers/media/pci/cx88/cx88-alsa.c:850:29: note: initialize the variable 'chip' to silence this warning
           struct cx88_audio_dev   *chip;
                                        ^
                                         = NULL
   1 warning generated.


vim +/chip +861 drivers/media/pci/cx88/cx88-alsa.c

   840	
   841	/*
   842	 * Alsa Constructor - Component probe
   843	 */
   844	
   845	static int devno;
   846	static int snd_cx88_create(struct snd_card *card, struct pci_dev *pci,
   847				   struct cx88_audio_dev **rchip,
   848				   struct cx88_core **core_ptr)
   849	{
   850		struct cx88_audio_dev	*chip;
   851		struct cx88_core	*core;
   852		int			err;
   853		unsigned char		pci_lat;
   854	
   855		*rchip = NULL;
   856	
   857		err = pci_enable_device(pci);
   858		if (err < 0)
   859			return err;
   860	
 > 861		chip->pci = pci;
   862		pci_set_master(pci);
   863	
   864		chip = card->private_data;
   865	
   866		core = cx88_core_get(pci);
   867		if (!core) {
   868			err = -EINVAL;
   869			return err;
   870		}
   871	
   872		err = dma_set_mask(&pci->dev, DMA_BIT_MASK(32));
   873		if (err) {
   874			dprintk(0, "%s/1: Oops: no 32bit PCI DMA ???\n", core->name);
   875			cx88_core_put(core, pci);
   876			return err;
   877		}
   878	
   879		/* pci init */
   880		chip->card = card;
   881		chip->irq = -1;
   882		spin_lock_init(&chip->reg_lock);
   883	
   884		chip->core = core;
   885	
   886		/* get irq */
   887		err = request_irq(chip->pci->irq, cx8801_irq,
   888				  IRQF_SHARED, chip->core->name, chip);
   889		if (err < 0) {
   890			dprintk(0, "%s: can't get IRQ %d\n",
   891				chip->core->name, chip->pci->irq);
   892			return err;
   893		}
   894	
   895		/* print pci info */
   896		pci_read_config_byte(pci, PCI_LATENCY_TIMER, &pci_lat);
   897	
   898		dprintk(1,
   899			"ALSA %s/%i: found at %s, rev: %d, irq: %d, latency: %d, mmio: 0x%llx\n",
   900			core->name, devno,
   901			pci_name(pci), pci->revision, pci->irq,
   902			pci_lat, (unsigned long long)pci_resource_start(pci, 0));
   903	
   904		chip->irq = pci->irq;
   905		synchronize_irq(chip->irq);
   906	
   907		*rchip = chip;
   908		*core_ptr = core;
   909	
   910		return 0;
   911	}
   912
diff mbox series

Patch

diff --git a/drivers/media/pci/cx88/cx88-alsa.c b/drivers/media/pci/cx88/cx88-alsa.c
index 29fb1311e443..b355c168c462 100644
--- a/drivers/media/pci/cx88/cx88-alsa.c
+++ b/drivers/media/pci/cx88/cx88-alsa.c
@@ -858,6 +858,7 @@  static int snd_cx88_create(struct snd_card *card, struct pci_dev *pci,
 	if (err < 0)
 		return err;

+	chip->pci = pci;
 	pci_set_master(pci);

 	chip = card->private_data;
@@ -877,7 +878,6 @@  static int snd_cx88_create(struct snd_card *card, struct pci_dev *pci,

 	/* pci init */
 	chip->card = card;
-	chip->pci = pci;
 	chip->irq = -1;
 	spin_lock_init(&chip->reg_lock);