[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20220326074454.13813-1-xiam0nd.tong@gmail.com>
Date: Sat, 26 Mar 2022 15:44:54 +0800
From: Xiaomeng Tong <xiam0nd.tong@...il.com>
To: mchehab@...nel.org
Cc: hverkuil-cisco@...all.nl, yangyingliang@...wei.com,
v4l@...queira.org, akpm@...l.org, linux-media@...r.kernel.org,
linux-kernel@...r.kernel.org,
Xiaomeng Tong <xiam0nd.tong@...il.com>
Subject: [PATCH v3] saa7134: fix incorrect check to determine if list is empty
The bug is here: "if (dev == NULL)".
The list iterator value will *always* be set and non-NULL by
list_for_each_entry(), so it is incorrect to assume that the iterator
value will be NULL if the list is empty. Instead, check with list_empty()
to fix this bug, and move the 'if' ahead to make the logic clearer.
Fixes: 4aabf6331f89c ("[PATCH] v4l: (951) Make saa7134-oss as a stand-alone module")
Signed-off-by: Xiaomeng Tong <xiam0nd.tong@...il.com>
---
changes since v2:
- add return (Xiaomeng Tong)
changes since v1:
- check with list_empty() (Jakob Koschel)
- and move the 'if' ahead (Xiaomeng Tong)
v1:https://lore.kernel.org/all/20220320025718.10053-1-xiam0nd.tong@gmail.com/
v2:https://lore.kernel.org/all/20220326073301.12949-1-xiam0nd.tong@gmail.com/
---
drivers/media/pci/saa7134/saa7134-alsa.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/drivers/media/pci/saa7134/saa7134-alsa.c b/drivers/media/pci/saa7134/saa7134-alsa.c
index fb24d2ed3621..1eb2e8da8950 100644
--- a/drivers/media/pci/saa7134/saa7134-alsa.c
+++ b/drivers/media/pci/saa7134/saa7134-alsa.c
@@ -1214,13 +1214,18 @@ static int alsa_device_exit(struct saa7134_dev *dev)
static int saa7134_alsa_init(void)
{
- struct saa7134_dev *dev = NULL;
+ struct saa7134_dev *dev;
saa7134_dmasound_init = alsa_device_init;
saa7134_dmasound_exit = alsa_device_exit;
pr_info("saa7134 ALSA driver for DMA sound loaded\n");
+ if (list_empty(&saa7134_devlist)) {
+ pr_info("saa7134 ALSA: no saa7134 cards found\n");
+ return 0;
+ }
+
list_for_each_entry(dev, &saa7134_devlist, devlist) {
if (dev->pci->device == PCI_DEVICE_ID_PHILIPS_SAA7130)
pr_info("%s/alsa: %s doesn't support digital audio\n",
@@ -1229,9 +1234,6 @@ static int saa7134_alsa_init(void)
alsa_device_init(dev);
}
- if (dev == NULL)
- pr_info("saa7134 ALSA: no saa7134 cards found\n");
-
return 0;
}
--
2.17.1
Powered by blists - more mailing lists