mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] saa7134: fix incorrect check to determine if list is empty
@ 2022-03-26  7:33 Xiaomeng Tong
  0 siblings, 0 replies; 2+ messages in thread
From: Xiaomeng Tong @ 2022-03-26  7:33 UTC (permalink / raw)
  To: mchehab
  Cc: hverkuil-cisco, yangyingliang, v4l, akpm, linux-media,
	linux-kernel, Xiaomeng Tong

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()
and move the 'if' ahead, to fix this bug.

Fixes: 4aabf6331f89c ("[PATCH] v4l: (951) Make saa7134-oss as a stand-alone module")
Signed-off-by: Xiaomeng Tong <xiam0nd.tong@gmail.com>
---
changes from v1:
 - check with list_empty() (Jakob Koschel)
 - move the 'if' ahead (Xiaomeng Tong)
v1:https://lore.kernel.org/all/20220320025718.10053-1-xiam0nd.tong@gmail.com/
sorry for the wrong PATCH v2:
https://lore.kernel.org/all/20220326072215.11608-1-xiam0nd.tong@gmail.com/
just skip it.
---
 drivers/media/pci/saa7134/saa7134-alsa.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/media/pci/saa7134/saa7134-alsa.c b/drivers/media/pci/saa7134/saa7134-alsa.c
index fb24d2ed3621..f0318617197c 100644
--- a/drivers/media/pci/saa7134/saa7134-alsa.c
+++ b/drivers/media/pci/saa7134/saa7134-alsa.c
@@ -1214,13 +1214,16 @@ 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");
+
 	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 +1232,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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH v2] saa7134: fix incorrect check to determine if list is empty
@ 2022-03-26  7:22 Xiaomeng Tong
  0 siblings, 0 replies; 2+ messages in thread
From: Xiaomeng Tong @ 2022-03-26  7:22 UTC (permalink / raw)
  To: mchehab
  Cc: hverkuil-cisco, yangyingliang, v4l, akpm, linux-media,
	linux-kernel, Xiaomeng Tong

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()
and move the 'if' ahead, to fix this bug.

Fixes: 4aabf6331f89c ("[PATCH] v4l: (951) Make saa7134-oss as a stand-alone module")
Signed-off-by: Xiaomeng Tong <xiam0nd.tong@gmail.com>
---
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/
---
 drivers/media/pci/saa7134/saa7134-alsa.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/media/pci/saa7134/saa7134-alsa.c b/drivers/media/pci/saa7134/saa7134-alsa.c
index fb24d2ed3621..4955f7e7c5bf 100644
--- a/drivers/media/pci/saa7134/saa7134-alsa.c
+++ b/drivers/media/pci/saa7134/saa7134-alsa.c
@@ -1215,18 +1215,21 @@ static int alsa_device_exit(struct saa7134_dev *dev)
 static int saa7134_alsa_init(void)
 {
 	struct saa7134_dev *dev = NULL;
+	struct saa7134_dev *iter;
 
 	saa7134_dmasound_init = alsa_device_init;
 	saa7134_dmasound_exit = alsa_device_exit;
 
 	pr_info("saa7134 ALSA driver for DMA sound loaded\n");
 
-	list_for_each_entry(dev, &saa7134_devlist, devlist) {
-		if (dev->pci->device == PCI_DEVICE_ID_PHILIPS_SAA7130)
+	list_for_each_entry(iter, &saa7134_devlist, devlist) {
+		dev = iter;
+
+		if (iter->pci->device == PCI_DEVICE_ID_PHILIPS_SAA7130)
 			pr_info("%s/alsa: %s doesn't support digital audio\n",
-				dev->name, saa7134_boards[dev->board].name);
+				iter->name, saa7134_boards[iter->board].name);
 		else
-			alsa_device_init(dev);
+			alsa_device_init(iter);
 	}
 
 	if (dev == NULL)
-- 
2.17.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-03-26  7:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-26  7:33 [PATCH v2] saa7134: fix incorrect check to determine if list is empty Xiaomeng Tong
  -- strict thread matches above, loose matches on Subject: below --
2022-03-26  7:22 Xiaomeng Tong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®