LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] staging: unisys: virtpci: virtpci: Fix for possible null pointer dereference
@ 2015-01-29 18:50 Rickard Strandqvist
  2015-01-30 12:39 ` Dan Carpenter
  0 siblings, 1 reply; 4+ messages in thread
From: Rickard Strandqvist @ 2015-01-29 18:50 UTC (permalink / raw)
  To: Benjamin Romer, David Kershner
  Cc: Rickard Strandqvist, Greg Kroah-Hartman, Bryan Thompson, Ken Cox,
	Erik Arfvidson, sparmaintainer, devel, linux-kernel

Fix a possible null pointer dereference, there is
otherwise a risk of a possible null pointer dereference.

This was found using a static code analysis program called cppcheck

Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
---
 drivers/staging/unisys/virtpci/virtpci.c |   20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/unisys/virtpci/virtpci.c b/drivers/staging/unisys/virtpci/virtpci.c
index 39b828d..eea3c64 100644
--- a/drivers/staging/unisys/virtpci/virtpci.c
+++ b/drivers/staging/unisys/virtpci/virtpci.c
@@ -1340,16 +1340,16 @@ static ssize_t virtpci_driver_attr_show(struct kobject *kobj,
 	struct driver_private *dprivate = to_driver(kobj);
 	struct device_driver *driver;
 
-	if (dprivate != NULL)
+	if (dprivate != NULL) {
 		driver = dprivate->driver;
-	else
-		driver = NULL;
 
-	DBGINF("In virtpci_driver_attr_show driver->name:%s\n", driver->name);
-	if (driver) {
+		DBGINF("In virtpci_driver_attr_show driver->name:%s\n", driver->name);
+
 		if (dattr->show)
 			ret = dattr->show(driver, buf);
 	}
+	else
+		DBGINF("In virtpci_driver_attr_show driver:NULL\n");
 	return ret;
 }
 
@@ -1363,17 +1363,17 @@ static ssize_t virtpci_driver_attr_store(struct kobject *kobj,
 	struct driver_private *dprivate = to_driver(kobj);
 	struct device_driver *driver;
 
-	if (dprivate != NULL)
+	if (dprivate != NULL) {
 		driver = dprivate->driver;
-	else
-		driver = NULL;
 
-	DBGINF("In virtpci_driver_attr_store driver->name:%s\n", driver->name);
+		DBGINF("In virtpci_driver_attr_store driver->name:%s\n", driver->name);
 
-	if (driver) {
 		if (dattr->store)
 			ret = dattr->store(driver, buf, count);
 	}
+	else
+		DBGINF("In virtpci_driver_attr_store driver:NULL\n");
+
 	return ret;
 }
 
-- 
1.7.10.4


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

* Re: [PATCH] staging: unisys: virtpci: virtpci: Fix for possible null pointer dereference
  2015-01-29 18:50 [PATCH] staging: unisys: virtpci: virtpci: Fix for possible null pointer dereference Rickard Strandqvist
@ 2015-01-30 12:39 ` Dan Carpenter
  2015-01-30 12:59   ` Peter Hurley
  0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2015-01-30 12:39 UTC (permalink / raw)
  To: Rickard Strandqvist
  Cc: Benjamin Romer, David Kershner, devel, Erik Arfvidson,
	Greg Kroah-Hartman, sparmaintainer, linux-kernel

Run your patches through checkpatch.pl.

On Thu, Jan 29, 2015 at 07:50:26PM +0100, Rickard Strandqvist wrote:
> -	if (dprivate != NULL)
> +	if (dprivate != NULL) {

This is a double negative.  Just say "if (dprivate) {".  Actually just
reverse the test and remove the bogus printk.  Say:

	if (!dprivate)
		return 0;

But *actually* just remove the test entirely because it can never be
NULL.  Same for virtpci_driver_attr_store().

Btw, if you have the smatch cross function database set up then you can
figure out this sort of thing by using:

$ smdb.py virtpci_driver_attr_store

It says that:

     fs/sysfs/file.c |       sysfs_kf_write | (struct sysfs_ops)->store |  PARAM_VALUE |  0 | $ | 4096-2117777777777777777

So this is called from sysfs_kf_write() and parameter zero is a valid
pointer.

regards,
dan carpenter


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

* Re: [PATCH] staging: unisys: virtpci: virtpci: Fix for possible null pointer dereference
  2015-01-30 12:39 ` Dan Carpenter
@ 2015-01-30 12:59   ` Peter Hurley
  2015-01-30 17:02     ` Rickard Strandqvist
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Hurley @ 2015-01-30 12:59 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Rickard Strandqvist, Benjamin Romer, David Kershner, devel,
	Erik Arfvidson, Greg Kroah-Hartman, sparmaintainer, linux-kernel

On 01/30/2015 07:39 AM, Dan Carpenter wrote:
> Btw, if you have the smatch cross function database set up then you can
> figure out this sort of thing by using:
> 
> $ smdb.py virtpci_driver_attr_store
> 
> It says that:
> 
>      fs/sysfs/file.c |       sysfs_kf_write | (struct sysfs_ops)->store |  PARAM_VALUE |  0 | $ | 4096-2117777777777777777
> 
> So this is called from sysfs_kf_write() and parameter zero is a valid
> pointer.

Hi Dan,

This would be a good topic for an LWN.net article.

Regards,
Peter Hurley


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

* Re: [PATCH] staging: unisys: virtpci: virtpci: Fix for possible null pointer dereference
  2015-01-30 12:59   ` Peter Hurley
@ 2015-01-30 17:02     ` Rickard Strandqvist
  0 siblings, 0 replies; 4+ messages in thread
From: Rickard Strandqvist @ 2015-01-30 17:02 UTC (permalink / raw)
  To: Peter Hurley
  Cc: Dan Carpenter, Benjamin Romer, David Kershner, devel,
	Erik Arfvidson, Greg Kroah-Hartman, sparmaintainer,
	Linux Kernel Mailing List

2015-01-30 13:59 GMT+01:00 Peter Hurley <peter@hurleysoftware.com>:
> On 01/30/2015 07:39 AM, Dan Carpenter wrote:
>> Btw, if you have the smatch cross function database set up then you can
>> figure out this sort of thing by using:
>>
>> $ smdb.py virtpci_driver_attr_store
>>
>> It says that:
>>
>>      fs/sysfs/file.c |       sysfs_kf_write | (struct sysfs_ops)->store |  PARAM_VALUE |  0 | $ | 4096-2117777777777777777
>>
>> So this is called from sysfs_kf_write() and parameter zero is a valid
>> pointer.
>
> Hi Dan,
>
> This would be a good topic for an LWN.net article.
>
> Regards,
> Peter Hurley
>

Hi

Okay, I'll do that this weekend.

But I see with you more about Smatch by the way.

Kind regards
Rickard Strandqvist

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

end of thread, other threads:[~2015-01-30 17:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-29 18:50 [PATCH] staging: unisys: virtpci: virtpci: Fix for possible null pointer dereference Rickard Strandqvist
2015-01-30 12:39 ` Dan Carpenter
2015-01-30 12:59   ` Peter Hurley
2015-01-30 17:02     ` Rickard Strandqvist

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).