Skip to contentSkip to conversation

media: em28xx: fix function pointer check

PATCH In review [email protected] 3 participants 3 messages Sep 3, 2020 – Sep 9, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: em28xx: fix function pointer check

From: Tom Rix <[email protected]>

clang static analyzer reports this problem

em28xx-core.c:1162:4: warning: Called function pointer
is null (null dereference)

        ops->suspend(dev->dev_next);
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~

This is the problem block

	if (ops->suspend)
		ops->suspend(dev);
	if (dev->dev_next)
		ops->suspend(dev->dev_next);

The check for ops->suspend only covers one statement. So fix the check consistent with other similar in the file.

Change a similar check in em28xx_resume_extension() to use consistent logic as its siblings.

Fixes be7fd3c3a8c5 ("media: em28xx: Hauppauge DualHD second tuner functionality")
---
 drivers/media/usb/em28xx/em28xx-core.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/media/usb/em28xx/em28xx-core.c +9 -8
index e6088b5d1b80..d60f4c2a661d 100644
@@ -1156,10 +1156,11 @@ int em28xx_suspend_extension(struct em28xx *dev)
 	dev_info(&dev->intf->dev, "Suspending extensions\n");
 	mutex_lock(&em28xx_devlist_mutex);
 	list_for_each_entry(ops, &em28xx_extension_devlist, next) {
-		if (ops->suspend)
+		if (ops->suspend) {
 			ops->suspend(dev);
-		if (dev->dev_next)
-			ops->suspend(dev->dev_next);
+			if (dev->dev_next)
+				ops->suspend(dev->dev_next);
+		}
 	}
 	mutex_unlock(&em28xx_devlist_mutex);
 	return 0;
@@ -1172,11 +1173,11 @@ int em28xx_resume_extension(struct em28xx *dev)
 	dev_info(&dev->intf->dev, "Resuming extensions\n");
 	mutex_lock(&em28xx_devlist_mutex);
 	list_for_each_entry(ops, &em28xx_extension_devlist, next) {
-		if (!ops->resume)
-			continue;
-		ops->resume(dev);
-		if (dev->dev_next)
-			ops->resume(dev->dev_next);
+		if (ops->resume) {
+			ops->resume(dev);
+			if (dev->dev_next)
+				ops->resume(dev->dev_next);
+		}
 	}
 	mutex_unlock(&em28xx_devlist_mutex);
 	return 0;
Signature · 1 line
2.18.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 20 lines · On Thu, Sep 03, 2020 at 07:50:38AM -0700, [email protected] wrote:

From: Tom Rix <[email protected]>

clang static analyzer reports this problem

em28xx-core.c:1162:4: warning: Called function pointer
is null (null dereference)

        ops->suspend(dev->dev_next);
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~

This is the problem block

	if (ops->suspend)
		ops->suspend(dev);
	if (dev->dev_next)
		ops->suspend(dev->dev_next);

The check for ops->suspend only covers one statement. So fix the check consistent with other similar in the file.

Quoted 5 lines

Change a similar check in em28xx_resume_extension() to use consistent logic as its siblings.

Fixes be7fd3c3a8c5 ("media: em28xx: Hauppauge DualHD second tuner functionality")

Seems reasonable.

Quoted 43 lines
---
 drivers/media/usb/em28xx/em28xx-core.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/media/usb/em28xx/em28xx-core.c +9 -8
index e6088b5d1b80..d60f4c2a661d 100644
@@ -1156,10 +1156,11 @@ int em28xx_suspend_extension(struct em28xx *dev)
 	dev_info(&dev->intf->dev, "Suspending extensions\n");
 	mutex_lock(&em28xx_devlist_mutex);
 	list_for_each_entry(ops, &em28xx_extension_devlist, next) {
-		if (ops->suspend)
+		if (ops->suspend) {
 			ops->suspend(dev);
-		if (dev->dev_next)
-			ops->suspend(dev->dev_next);
+			if (dev->dev_next)
+				ops->suspend(dev->dev_next);
+		}
 	}
 	mutex_unlock(&em28xx_devlist_mutex);
 	return 0;
@@ -1172,11 +1173,11 @@ int em28xx_resume_extension(struct em28xx *dev)
 	dev_info(&dev->intf->dev, "Resuming extensions\n");
 	mutex_lock(&em28xx_devlist_mutex);
 	list_for_each_entry(ops, &em28xx_extension_devlist, next) {
-		if (!ops->resume)
-			continue;
-		ops->resume(dev);
-		if (dev->dev_next)
-			ops->resume(dev->dev_next);
+		if (ops->resume) {
+			ops->resume(dev);
+			if (dev->dev_next)
+				ops->resume(dev->dev_next);
+		}
 	}
 	mutex_unlock(&em28xx_devlist_mutex);
 	return 0;
Signature · 1 line
2.18.1
#2 lore raw
In reply to [email protected]
Quoted 49 lines · On 03/09/2020 16:50, [email protected] wrote:

From: Tom Rix <[email protected]>

clang static analyzer reports this problem

em28xx-core.c:1162:4: warning: Called function pointer
is null (null dereference)

        ops->suspend(dev->dev_next);
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~

This is the problem block

	if (ops->suspend)
		ops->suspend(dev);
	if (dev->dev_next)
		ops->suspend(dev->dev_next);

The check for ops->suspend only covers one statement. So fix the check consistent with other similar in the file.

Change a similar check in em28xx_resume_extension() to use consistent logic as its siblings.

Fixes be7fd3c3a8c5 ("media: em28xx: Hauppauge DualHD second tuner functionality")
---
 drivers/media/usb/em28xx/em28xx-core.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/media/usb/em28xx/em28xx-core.c +4 -3
index e6088b5d1b80..d60f4c2a661d 100644
@@ -1156,10 +1156,11 @@ int em28xx_suspend_extension(struct em28xx *dev)
 	dev_info(&dev->intf->dev, "Suspending extensions\n");
 	mutex_lock(&em28xx_devlist_mutex);
 	list_for_each_entry(ops, &em28xx_extension_devlist, next) {
-		if (ops->suspend)
+		if (ops->suspend) {
 			ops->suspend(dev);
-		if (dev->dev_next)
-			ops->suspend(dev->dev_next);
+			if (dev->dev_next)
+				ops->suspend(dev->dev_next);
+		}
 	}
 	mutex_unlock(&em28xx_devlist_mutex);
 	return 0;

drivers/media/usb/em28xx/em28xx-core.c int em28xx_resume_extension(struct em28xx *dev) · line 1176

Quoted 5 lines
drivers/media/usb/em28xx/em28xx-core.c +0 -2
@@ -1172,11 +1173,11 @@ int em28xx_resume_extension(struct em28xx *dev)
 	dev_info(&dev->intf->dev, "Resuming extensions\n");
 	mutex_lock(&em28xx_devlist_mutex);
 	list_for_each_entry(ops, &em28xx_extension_devlist, next) {
-		if (!ops->resume)
-			continue;

Actually, this code is fine: if !ops->resume, then just continue.

So there is no need to change this resume code.

And in fact, I think it would be best if the same approach was used in em28xx_suspend_extension.

Regards,

Hans

Quoted 12 lines
drivers/media/usb/em28xx/em28xx-core.c +5 -3
-		ops->resume(dev);
-		if (dev->dev_next)
-			ops->resume(dev->dev_next);
+		if (ops->resume) {
+			ops->resume(dev);
+			if (dev->dev_next)
+				ops->resume(dev->dev_next);
+		}
 	}
 	mutex_unlock(&em28xx_devlist_mutex);
 	return 0;